Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sosna committed Dec 19, 2019
2 parents d81025b + c3b6583 commit 467a0e0
Show file tree
Hide file tree
Showing 4 changed files with 43 additions and 11 deletions.
1 change: 1 addition & 0 deletions .npmignore
Original file line number Diff line number Diff line change
Expand Up @@ -6,3 +6,4 @@ coverage/
coffeelint.json
.travis.yml
_config.yml
*.code-workspace
4 changes: 2 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
{
"name": "sdmx-rest",
"engines": {
"node": ">=6"
"node": ">=10"
},
"description": "SDMX REST API client for JavaScript",
"version": "2.15.0",
"version": "2.15.1",
"main": "./lib/index.js",
"scripts": {
"prebuild": "rm -rf lib && mkdir lib",
Expand Down
24 changes: 17 additions & 7 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -269,15 +269,25 @@ getSchemaQuery = (input) ->
# @see #getService
#
getUrl = (query, service) ->
# URL generation requires all fields to be set. The 3 next lines are just
# in case partial objects are passed to the function.
throw ReferenceError 'Service is a mandatory parameter' unless service
s = getService service
throw Error 'Not a valid query' unless query?.flow or query?.resource
q = if query.flow then getDataQuery query else getMetadataQuery query

return new UrlGenerator().getUrl q, s

if (query?.mode? \
or (query?.flow? and query?.references?) \
or (query?.flow? and query?.component?))
q = getAvailabilityQuery query
return new UrlGenerator().getUrl q, s
else if query?.flow?
q = getDataQuery query
return new UrlGenerator().getUrl q, s
else if query?.resource?
q = getMetadataQuery query
return new UrlGenerator().getUrl q, s
else if query?.context?
q = getSchemaQuery query
return new UrlGenerator().getUrl q, s
else
throw Error 'Not a valid query'

#
# Executes the supplied query against the supplied service and returns a
# Promise.
Expand Down
25 changes: 23 additions & 2 deletions test/index.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -195,7 +195,7 @@ describe 'API', ->

describe 'when using getUrl()', ->

it 'offers to create a URL from a data query and a service objects', ->
it 'creates a URL from a data query and a service objects', ->
query = sdmxrest.getDataQuery {flow: 'EXR', key: 'A.CHF.NOK.SP00.A'}
service = sdmxrest.getService 'ECB'
url = sdmxrest.getUrl query, service
Expand All @@ -204,13 +204,34 @@ describe 'API', ->
url.should.contain query.flow
url.should.contain query.key

it 'offers to create a URL from a metadata query and a service objects', ->
it 'creates a URL from a metadata query and a service objects', ->
url = sdmxrest.getUrl {resource: 'codelist', id: 'CL_FREQ'}, 'ECB'
url.should.be.a 'string'
url.should.contain 'sdw-wsrest.ecb.europa.eu'
url.should.contain 'codelist'
url.should.contain 'CL_FREQ'

it 'creates a URL from a schema query and a service objects', ->
q = {'context': 'dataflow', 'agency': 'BIS', 'id': 'CBS'}
url = sdmxrest.getUrl q, 'ECB'
url.should.be.a 'string'
url.should.contain 'sdw-wsrest.ecb.europa.eu'
url.should.contain 'schema'
url.should.contain 'dataflow/BIS/CBS'

it 'creates a URL from an availability query and a service objects', ->
input = {
flow: 'EXR'
key: 'A..EUR.SP00.A'
}
q = sdmxrest.getAvailabilityQuery input
s = sdmxrest.getService({url: 'http://ws-entry-point'});
url = sdmxrest.getUrl q, s
url.should.be.a 'string'
url.should.contain 'http://ws-entry-point'
url.should.contain 'availableconstraint'
url.should.contain 'EXR/A..EUR.SP00.A'

it 'fails if the input is not of the expected type', ->
test = -> sdmxrest.getUrl undefined, sdmxrest.getService 'ECB'
should.Throw(test, Error, 'Not a valid query')
Expand Down

0 comments on commit 467a0e0

Please sign in to comment.