Skip to content

Commit

Permalink
Merge pull request #56 from sosna/develop
Browse files Browse the repository at this point in the history
Develop
  • Loading branch information
sosna committed Aug 18, 2018
2 parents 1889eb0 + e6ce734 commit 0a9dda5
Show file tree
Hide file tree
Showing 8 changed files with 60 additions and 36 deletions.
6 changes: 1 addition & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,6 @@ before_install:
before_script:
- npm prune
script:
- npm run test:single
- npm run check-coverage
- npm run test
- npm run lint
- npm run build
after_success:
- npm run report-coverage
- npm run semantic-release
3 changes: 1 addition & 2 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
# sdmx-rest4js
[![Build Status](https://travis-ci.org/sosna/sdmx-rest4js.svg?branch=master)](https://travis-ci.org/sosna/sdmx-rest4js) [![codecov.io](https://codecov.io/github/sosna/sdmx-rest4js/coverage.svg?branch=master)](https://codecov.io/github/sosna/sdmx-rest4js?branch=master) [![bitHound Overall Score](https://www.bithound.io/github/sosna/sdmx-rest4js/badges/score.svg)](https://www.bithound.io/github/sosna/sdmx-rest4js) [![bitHound Dependencies](https://www.bithound.io/github/sosna/sdmx-rest4js/badges/dependencies.svg)](https://www.bithound.io/github/sosna/sdmx-rest4js/master/dependencies/npm) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![current version](https://img.shields.io/npm/v/sdmx-rest.svg)](https://www.npmjs.com/package/sdmx-rest)
# sdmx-rest4js [![Build Status](https://travis-ci.org/sosna/sdmx-rest4js.svg?branch=master)](https://travis-ci.org/sosna/sdmx-rest4js) [![codecov.io](https://codecov.io/github/sosna/sdmx-rest4js/coverage.svg?branch=master)](https://codecov.io/github/sosna/sdmx-rest4js?branch=master) [![Codacy Grade](https://api.codacy.com/project/badge/Grade/7adaf82b611d478882ad1471f02b4314)](https://www.codacy.com/project/sosna/sdmx-rest4js/dashboard?utm_source=github.com&utm_medium=referral&utm_content=sosna/sdmx-rest4js&utm_campaign=Badge_Grade_Dashboard) [![Known Vulnerabilities](https://snyk.io/test/github/sosna/sdmx-rest4js/badge.svg?targetFile=package.json)](https://snyk.io/test/github/sosna/sdmx-rest4js?targetFile=package.json) [![semantic-release](https://img.shields.io/badge/%20%20%F0%9F%93%A6%F0%9F%9A%80-semantic--release-e10079.svg)](https://github.com/semantic-release/semantic-release) [![current version](https://img.shields.io/npm/v/sdmx-rest.svg)](https://www.npmjs.com/package/sdmx-rest)

This library allows to easily work with the [SDMX RESTful API](https://github.com/sdmx-twg/sdmx-rest) from a JavaScript application.

Expand Down
28 changes: 14 additions & 14 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -4,17 +4,17 @@
"node": ">=6"
},
"description": "The SDMX RESTful API for JavaScript",
"version": "2.7.0",
"version": "2.8.0",
"main": "./lib/index.js",
"scripts": {
"prebuild": "rm -rf lib && mkdir lib",
"build": "./node_modules/.bin/coffee -co lib src/",
"build": "coffee -co lib src/",
"commit": "git-cz",
"check-coverage": "istanbul check-coverage --statements 100 --branches 100 --functions 100 --lines 100",
"report-coverage": "cat ./coverage/lcov.info | codecov",
"test": "mocha -t 500 --recursive --compilers coffee:coffee-script/register",
"test:watch": "mocha -t 500 -w --recursive --compilers coffee:coffee-script/register",
"test:single": "istanbul cover _mocha -- --recursive --compilers coffee:coffee-script/register --require coffee-coverage/register-istanbul",
"test": "mocha -t 500 --recursive --compilers coffee:coffeescript/register",
"test:watch": "mocha -t 500 -w --recursive --compilers coffee:coffeescript/register",
"test:single": "istanbul cover _mocha -- --recursive --compilers coffee:coffeescript/register --require coffee-coverage/register-istanbul",
"prepublish": "npm build",
"semantic-release": "semantic-release pre && npm publish && semantic-release post",
"lint": "coffeelint src"
Expand All @@ -37,17 +37,17 @@
"chai": "4.1.2",
"chai-as-promised": "7.1.1",
"codecov.io": "0.1.6",
"coffee-coverage": "2.0.1",
"coffee-script": "1.12.7",
"coffeeify": "3.0.0",
"coffeelint": "2.0.7",
"commitizen": "2.9.6",
"coffee-coverage": "3.0.0",
"coffeeify": "3.0.1",
"coffeelint": "2.1.0",
"coffeescript": "2.1.1",
"commitizen": "2.10.1",
"cz-conventional-changelog": "2.1.0",
"husky": "0.14.3",
"istanbul": "0.4.5",
"mocha": "4.0.1",
"nock": "9.0.27",
"semantic-release": "8.2.0"
"mocha": "5.2.0",
"nock": "9.6.1",
"semantic-release": "15.9.8"
},
"config": {
"commitizen": {
Expand All @@ -56,7 +56,7 @@
"pre-commit": "npm run test:single && npm run check-coverage && npm run lint"
},
"dependencies": {
"es6-promise": "4.1.1",
"es6-promise": "4.2.4",
"isomorphic-fetch": "2.2.1"
}
}
2 changes: 2 additions & 0 deletions src/index.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
{MetadataReferences} = require './metadata/metadata-references'
{MetadataType} = require './metadata/metadata-type'
{Service} = require './service/service'
{services} = require './service/service'
{UrlGenerator} = require './utils/url-generator'
{ApiVersion} = require './utils/api-version'
SdmxPatterns = require './utils/sdmx-patterns'
Expand Down Expand Up @@ -252,6 +253,7 @@ request = (params...) ->

module.exports =
getService: getService
services: services
getDataQuery: getDataQuery
getMetadataQuery: getMetadataQuery
getUrl: getUrl
Expand Down
9 changes: 9 additions & 0 deletions src/service/service.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -70,4 +70,13 @@ service = class Service
throw Error createErrorMessage(input.errors, 'service') unless input.isValid
service

services = [
service.ECB_S
service.SDMXGR_S
service.EUROSTAT
service.OECD_S
service.WB
]

exports.Service = service
exports.services = services
28 changes: 13 additions & 15 deletions src/utils/url-generator.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -73,29 +73,27 @@ createMetadataQuery = (query, service) ->
url = url + "?detail=#{query.detail}&references=#{query.references}"
url

handleQueryStringParams = (q, u, hd, hr) ->
if hd or hr then u = u + "?"
if hd then u = u + "detail=#{q.detail}"
if hd and hr then u = u + "&"
if hr then u = u + "references=#{q.references}"
u

createShortMetadataQuery = (q, s) ->
u = createEntryPoint s
u = u + "#{q.resource}"
if (q.agency isnt "all" or q.id isnt "all" or q.version isnt "latest" or
itemNeeded(q.item, q.resource, s.api))
itn = itemNeeded(q.item, q.resource, s.api)
if (q.agency isnt "all" or q.id isnt "all" or q.version isnt "latest" or itn)
u = u + "/#{q.agency}"
if q.id isnt "all" or q.version isnt "latest" or
itemNeeded(q.item, q.resource, s.api)
if q.id isnt "all" or q.version isnt "latest" or itn
u = u + "/#{q.id}"
if q.version isnt "latest" or itemNeeded(q.item, q.resource, s.api)
if q.version isnt "latest" or itn
u = u + "/#{q.version}"
if itemAllowed(q.resource, s.api) and q.item isnt "all"
u = u + "/#{q.item}"
if (q.detail isnt MetadataDetail.FULL or
q.references isnt MetadataReferences.NONE)
u = u + "?"
if q.detail isnt MetadataDetail.FULL
u = u + "detail=#{q.detail}"
if (q.detail isnt MetadataDetail.FULL and
q.references isnt MetadataReferences.NONE)
u = u + "&"
if q.references isnt MetadataReferences.NONE
u = u + "references=#{q.references}"
u = handleQueryStringParams(q, u, q.detail isnt MetadataDetail.FULL,
q.references isnt MetadataReferences.NONE)
u

generator = class Generator
Expand Down
10 changes: 10 additions & 0 deletions test/index.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ describe 'API', ->

it 'offers the expected functions and objects', ->
sdmxrest.should.have.property 'getService'
sdmxrest.should.have.property('services').that.is.an 'array'
sdmxrest.should.have.property 'getDataQuery'
sdmxrest.should.have.property 'getMetadataQuery'
sdmxrest.should.have.property 'getUrl'
Expand Down Expand Up @@ -69,6 +70,15 @@ describe 'API', ->
test = -> sdmxrest.getService []
should.Throw(test, TypeError, 'Invalid type of ')

describe 'when using services', ->

it 'list some services', ->
sdmxrest.services.should.be.an 'array'
sdmxrest.services.should.have.property('length').that.is.gte 5

it 'should contain known services', ->
sdmxrest.services.should.include.members([sdmxrest.getService 'ECB_S'])

describe 'when using getDataQuery()', ->

it 'offers to create a data query from properties', ->
Expand Down
10 changes: 10 additions & 0 deletions test/service/service.test.coffee
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ should = require('chai').should()
{ApiVersion} = require '../../src/utils/api-version'
{Service} = require '../../src/service/service'
{DataFormat} = require '../../src/data/data-format'
{services} = require '../../src/service/service'

describe 'Service', ->

Expand Down Expand Up @@ -83,3 +84,12 @@ describe 'Service', ->
s1.should.have.property('api').that.equals s2.api
s1.should.have.property('url').that.contains 'http://'
s2.should.have.property('url').that.contains 'https://'

describe 'Services', ->

it 'list some services', ->
services.should.be.an 'array'
services.should.have.property('length').that.is.gte 5

it 'should contain a few known services', ->
services.should.include.members([Service.ECB_S, Service.SDMXGR_S])

0 comments on commit 0a9dda5

Please sign in to comment.