-
-
Notifications
You must be signed in to change notification settings - Fork 44
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(batch): port download code to use the batch endpoint
- Loading branch information
1 parent
00fccf8
commit 4190c5c
Showing
6 changed files
with
137 additions
and
49 deletions.
There are no files selected for viewing
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,5 +1,5 @@ | ||
{ | ||
"esversion": 6, | ||
"esversion": 8, | ||
"node": true, | ||
"curly": true, | ||
"eqeqeq": true, | ||
|
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 |
---|---|---|
@@ -0,0 +1,43 @@ | ||
const _ = require('lodash'); | ||
const axios = require('axios'); | ||
const config = require('pelias-config'); | ||
const HOST = 'https://batch.openaddresses.io'; | ||
|
||
class OpenAddressesAPI { | ||
constructor() { | ||
this.config = _.get(config.generate(), 'imports.openaddresses', {}); | ||
this.token = _.get(this.config, 'token'); | ||
} | ||
|
||
// remove file extensions from 'source' | ||
normalize(source) { | ||
if (!_.isString(source)) { return source; } | ||
return source.replace(/\.[^/.]+$/, ''); | ||
} | ||
|
||
// return the http url for a specific job id | ||
url(job) { | ||
return `${HOST}/api/job/${job}/output/source.geojson.gz`; | ||
} | ||
|
||
// if the 'validated' mode is enabled (for financial supporters only) | ||
isValidatedModeEnabled() { | ||
return _.get(this.config, 'validated') === true; | ||
} | ||
|
||
async lookup(filename) { | ||
// normalize 'source' property | ||
// support the 'validated' property for financial supporters | ||
const params = { | ||
source: this.normalize(filename), | ||
layer: 'addresses', | ||
validated: this.isValidatedModeEnabled() ? 'true' : 'false' | ||
}; | ||
|
||
// request extended info and return the first result | ||
const versions = await axios.get(`${HOST}/api/data`, { params }); | ||
return _.isArray(versions.data) && !_.isEmpty(versions.data) ? _.head(versions.data) : {}; | ||
} | ||
} | ||
|
||
module.exports = OpenAddressesAPI; |
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