-
Notifications
You must be signed in to change notification settings - Fork 2
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
9 changed files
with
51 additions
and
96 deletions.
There are no files selected for viewing
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,2 +1,5 @@ | ||
node_modules | ||
src | ||
test | ||
coverage | ||
.* | ||
LICENSE |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1 @@ | ||
v5 | ||
v6 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,9 @@ | ||
language: node_js | ||
node_js: | ||
- "0.12" | ||
- "4" | ||
- "5" | ||
- "6" | ||
notifications: | ||
email: false | ||
after_success: | ||
- npm run coveralls |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,35 +1,31 @@ | ||
'use strict'; | ||
|
||
import Q from 'q'; | ||
import cheerio from 'cheerio'; | ||
import rp from 'request-promise'; | ||
const cheerio = require('cheerio'); | ||
const rp = require('request-promise'); | ||
|
||
const getZip = (data, cb) => { | ||
const deferred = Q.defer(); | ||
const getZip = data => { | ||
const options = { | ||
url: 'http://www.correos.cl/SitePages/codigo_postal/codigo_postal.aspx', | ||
qs: { | ||
calle: data.address, | ||
numero: data.number, | ||
comuna: data.commune | ||
}, | ||
transform: (body) => cheerio.load(body) | ||
transform: cheerio.load | ||
}; | ||
rp(options).then(($) => { | ||
return rp(options).then($ => { | ||
const zip = $('span[id$="CodigoPostal"]').text(); | ||
const address = $('span[id$="Calle"]').text(); | ||
const number = $('span[id$="Numero"]').text(); | ||
const commune = $('span[id$="Comuna"]').text(); | ||
if (!zip) deferred.reject(new Error('Not found')); | ||
deferred.resolve({ | ||
if (!zip) throw new Error('Not found'); | ||
return { | ||
zip: parseInt(zip, 10), | ||
address: address, | ||
number: number, | ||
commune: commune | ||
}); | ||
}).catch((err) => deferred.reject(err)); | ||
deferred.promise.nodeify(cb); | ||
return deferred.promise; | ||
}; | ||
}); | ||
}; | ||
|
||
module.exports = getZip; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters