Skip to content

Commit

Permalink
Merge branch 'develop'
Browse files Browse the repository at this point in the history
  • Loading branch information
sosna committed Oct 12, 2017
2 parents 07d0825 + e5ba543 commit ff63557
Show file tree
Hide file tree
Showing 9 changed files with 95 additions and 32 deletions.
13 changes: 4 additions & 9 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,16 +9,11 @@ branches:
notifications:
email: false
node_js:
- '5'
- '4'
- '4.4'
- '4.3'
- '4.2'
- '4.1'
- '4.0'
- '0.12'
- 'iojs'
- 'node'
- 'lts/*'
- '8'
- '7'
- '6'
before_install:
- npm i -g npm@^2.0.0
before_script:
Expand Down
33 changes: 17 additions & 16 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
{
"name": "sdmx-rest",
"engines": {
"node": ">=6"
},
"description": "The SDMX RESTful API for JavaScript",
"version": "1.0.0",
"main": "./lib/index.js",
Expand Down Expand Up @@ -31,31 +34,29 @@
},
"homepage": "https://github.com/sosna/sdmx-rest4js#readme",
"devDependencies": {
"chai": "3.5.0",
"chai-as-promised": "6.0.0",
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"codecov.io": "0.1.6",
"coffee-coverage": "1.0.1",
"coffee-script": "1.12.3",
"coffeeify": "2.1.0",
"coffeelint": "1.16.0",
"commitizen": "2.9.5",
"cz-conventional-changelog": "1.2.0",
"ghooks": "2.0.0",
"coffee-coverage": "2.0.1",
"coffee-script": "1.12.7",
"coffeeify": "3.0.0",
"coffeelint": "2.0.6",
"commitizen": "2.9.6",
"cz-conventional-changelog": "2.0.0",
"husky": "0.14.3",
"istanbul": "0.4.5",
"mocha": "3.2.0",
"nock": "9.0.5",
"semantic-release": "6.3.2"
"mocha": "4.0.1",
"nock": "9.0.22",
"semantic-release": "8.0.3"
},
"config": {
"commitizen": {
"path": "node_modules/cz-conventional-changelog"
},
"ghooks": {
"pre-commit": "npm run test:single && npm run check-coverage && npm run lint"
}
"pre-commit": "npm run test:single && npm run check-coverage && npm run lint"
},
"dependencies": {
"es6-promise": "4.0.5",
"es6-promise": "4.1.1",
"isomorphic-fetch": "2.2.1"
}
}
1 change: 1 addition & 0 deletions src/metadata/metadata-type.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ itemSchemes = [
'dataproviderscheme'
'dataconsumerscheme'
'organisationunitscheme'
'hierarchicalcodelist'
]

types =
Expand Down
6 changes: 5 additions & 1 deletion src/utils/api-version.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,11 @@ versions =
# query for items within item schemes.
v1_1_0: 'v1.1.0'

# The version of the SDMX RESTFul API released in May 2017. It adds supports
# for retrieving specific hierarchies in a hierarchical codelist.
v1_2_0: 'v1.2.0'

# A shortcut to the most recent version of the SDMX RESTful API
LATEST: 'v1.1.0'
LATEST: 'v1.2.0'

exports.ApiVersion = Object.freeze versions
4 changes: 3 additions & 1 deletion src/utils/url-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,9 @@ createMetadataQuery = (query, service) ->
if (service.api isnt ApiVersion.v1_0_0 and
service.api isnt ApiVersion.v1_0_1 and
service.api isnt ApiVersion.v1_0_2 and
isItemScheme(query.resource))
((query.resource isnt 'hierarchicalcodelist' and
isItemScheme(query.resource)) or (service.api isnt ApiVersion.v1_1_0 and
query.resource is 'hierarchicalcodelist')))
url = url + "/#{query.item}"
url = url + "?detail=#{query.detail}&references=#{query.references}"
url
Expand Down
6 changes: 6 additions & 0 deletions test/metadata/metadata-query.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -158,6 +158,12 @@ describe 'Metadata query', ->
test = -> MetadataQuery.from({resource: 'dataflow', item: 'A'})
should.Throw(test, Error, 'Not a valid metadata query')

it 'handles hierarchical codelists as item schemes', ->
item = 'hierarchy'
query = MetadataQuery.from(
{resource: MetadataType.HIERARCHICAL_CODELIST, item: item})
query.should.have.property('item').that.equals item

describe 'when setting the amount of details', ->

it 'a string representing the amount of details can be passed', ->
Expand Down
4 changes: 4 additions & 0 deletions test/metadata/metadata-type.test.coffee
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
should = require('chai').should()
{MetadataType} = require('../../src/metadata/metadata-type')
{isItemScheme} = require('../../src/metadata/metadata-type')

describe 'Metadata types', ->

Expand Down Expand Up @@ -36,3 +37,6 @@ describe 'Metadata types', ->

it 'is immutable', ->
MetadataType.should.be.frozen

it 'considers hierarchicalcodelist as item scheme', ->
isItemScheme('hierarchicalcodelist').should.be.true
4 changes: 4 additions & 0 deletions test/utils/api-version.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ describe 'API versions', ->
'v1.0.1'
'v1.0.2'
'v1.1.0'
'v1.2.0'
'latest'
]

Expand All @@ -21,3 +22,6 @@ describe 'API versions', ->

it 'is immutable', ->
ApiVersion.should.be.frozen

it 'considers v1.2.0 as the latest version', ->
ApiVersion.LATEST.should.equal 'v1.2.0'
56 changes: 51 additions & 5 deletions test/utils/url-generator.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ describe 'URL Generator', ->
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'supports item queries but only for API version 1.1.0 and above', ->
it 'supports item queries for API version 1.1.0 and above', ->
expected = "http://test.com/codelist/ECB/CL_FREQ/latest/A\
?detail=full&references=none"
query = MetadataQuery.from({
Expand All @@ -48,20 +48,66 @@ describe 'URL Generator', ->
})
service = Service.from({
url: 'http://test.com'
api: ApiVersion.v1_1_0
})
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'defaults to API version 1.1.0', ->
expected = "http://test.com/codelist/ECB/CL_FREQ/latest/A\
it 'does not support item queries before API version 1.1.0', ->
expected = "http://test.com/codelist/ECB/CL_FREQ/latest\
?detail=full&references=none"
query = MetadataQuery.from({
resource: 'codelist'
id: 'CL_FREQ'
agency: 'ECB'
item: 'A'
})
service = Service.from({
url: 'http://test.com'
api: ApiVersion.v1_0_2
})
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'treats hierarchical codelists as item schemes for API version 1.2.0', ->
expected = "http://test.com/hierarchicalcodelist/BIS/HCL/latest/HIERARCHY\
?detail=full&references=none"
query = MetadataQuery.from({
resource: 'hierarchicalcodelist'
id: 'HCL'
agency: 'BIS'
item: 'HIERARCHY'
})
service = Service.from({
url: 'http://test.com'
})
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'does not support hiearchy queries before API version 1.2.0', ->
expected = "http://test.com/hierarchicalcodelist/BIS/HCL/latest\
?detail=full&references=none"
query = MetadataQuery.from({
resource: 'hierarchicalcodelist'
id: 'HCL'
agency: 'BIS'
item: 'HIERARCHY'
})
service = Service.from({
url: 'http://test.com'
api: ApiVersion.v1_1_0
})
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'defaults to latest API version', ->
expected = "http://test.com/hierarchicalcodelist/ECB/HCL/latest/HIERARCHY\
?detail=full&references=none"
query = MetadataQuery.from({
resource: 'hierarchicalcodelist'
id: 'HCL'
agency: 'ECB'
item: 'HIERARCHY'
})
service = Service.from({
url: 'http://test.com/'
})
Expand Down Expand Up @@ -131,7 +177,7 @@ describe 'URL Generator', ->
url = new UrlGenerator().getUrl(query, service)
url.should.equal expected

it 'defaults to API version 1.1.0', ->
it 'defaults to latest API', ->
expected = "http://test.com/data/EXR/A..EUR.SP00.A/ECB?\
dimensionAtObservation=CURRENCY&detail=nodata&includeHistory=true\
&startPeriod=2010&endPeriod=2015&updatedAfter=2016-03-01T00:00:00Z\
Expand Down

0 comments on commit ff63557

Please sign in to comment.