nordnet-next-api
Advanced tools
Comparing version 3.1.1 to 3.2.0
import React from 'react'; | ||
import { get } from 'nordnet-next-api'; | ||
import { get, setConfig } from 'nordnet-next-api'; | ||
@@ -4,0 +4,0 @@ class Status extends React.Component { |
@@ -64,3 +64,5 @@ 'use strict'; | ||
return conditions.forEach(function (condition) { | ||
return Object.keys(_index2.default).forEach(testMethodRejected(condition)); | ||
return Object.keys(_index2.default).filter(function (method) { | ||
return method !== 'setConfig'; | ||
}).forEach(testMethodRejected(condition)); | ||
}); | ||
@@ -67,0 +69,0 @@ }; |
@@ -9,2 +9,3 @@ 'use strict'; | ||
exports.setConfig = setConfig; | ||
exports.get = get; | ||
@@ -45,2 +46,17 @@ exports.post = post; | ||
var config = {}; | ||
var configKeys = ['root']; | ||
function setConfig() { | ||
var options = arguments.length <= 0 || arguments[0] === undefined ? {} : arguments[0]; | ||
configKeys.forEach(function (key) { | ||
return config[key] = options[key]; | ||
}); | ||
if (options.nTag) { | ||
state.nTag = options.nTag; | ||
} | ||
} | ||
function get(url) { | ||
@@ -117,3 +133,4 @@ var params = arguments.length <= 1 || arguments[1] === undefined ? {} : arguments[1]; | ||
put: put, | ||
del: del | ||
del: del, | ||
setConfig: setConfig | ||
}; | ||
@@ -224,3 +241,9 @@ | ||
var pathContainsQuery = path.indexOf('?') !== -1; | ||
var pathContainsProtocol = !!path.match(/^http(s)?:\/\//); | ||
var root = ''; | ||
if (!pathContainsProtocol && typeof config.root !== 'undefined') { | ||
root = config.root; | ||
} | ||
var delimiter = ''; | ||
@@ -233,3 +256,3 @@ if (pathContainsQuery && queryParams) { | ||
return '' + path + delimiter + queryParams; | ||
return '' + root + path + delimiter + queryParams; | ||
} | ||
@@ -236,0 +259,0 @@ |
{ | ||
"name": "nordnet-next-api", | ||
"version": "3.1.1", | ||
"version": "3.2.0", | ||
"description": "Nordnet nExt API Javascript client", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -111,3 +111,17 @@ # Nordnet nExt API Javascript client | ||
### Setting root URL before querying | ||
```js | ||
import api from 'nordnet-next-api'; | ||
api.setConfig({ root: 'https://api.test.nordnet.se/next/2' }); | ||
api.get('/accounts/{accno}', { accno: 123456789 }) | ||
.then(response => console.log(response)); | ||
``` | ||
The following config keys are supported: | ||
* `root` sets base root URL | ||
* `nTag` set initial nTag value | ||
### Passing path parameters | ||
@@ -156,5 +170,6 @@ | ||
First, build the project: | ||
Before proceeding, install dependencies and build the project: | ||
``` | ||
npm install | ||
npm run build | ||
@@ -181,3 +196,3 @@ ``` | ||
This open source project released by Nordnet is licenced under the MIT licence. | ||
This Open Source project released by Nordnet is licensed under the MIT license. | ||
@@ -184,0 +199,0 @@ |
@@ -37,3 +37,6 @@ import { initSandBox, respondWith, execute, expectations } from 'test-helper'; | ||
function testRejected(conditions) { | ||
return () => conditions.forEach(condition => Object.keys(api).forEach(testMethodRejected(condition))); | ||
return () => conditions.forEach( | ||
condition => Object.keys(api) | ||
.filter(method => method !== 'setConfig') | ||
.forEach(testMethodRejected(condition))); | ||
} | ||
@@ -40,0 +43,0 @@ |
@@ -26,2 +26,13 @@ import es6Promise from 'es6-promise'; | ||
const config = {}; | ||
const configKeys = ['root']; | ||
export function setConfig(options = {}) { | ||
configKeys.forEach(key => config[key] = options[key]); | ||
if (options.nTag) { | ||
state.nTag = options.nTag; | ||
} | ||
} | ||
export function get(url, params = {}, headers = {}) { | ||
@@ -82,2 +93,3 @@ const options = { | ||
del, | ||
setConfig, | ||
}; | ||
@@ -179,3 +191,9 @@ | ||
const pathContainsQuery = path.indexOf('?') !== -1; | ||
const pathContainsProtocol = !!(path.match(/^http(s)?:\/\//)); | ||
let root = ''; | ||
if (!pathContainsProtocol && typeof config.root !== 'undefined') { | ||
root = config.root; | ||
} | ||
let delimiter = ''; | ||
@@ -188,3 +206,3 @@ if (pathContainsQuery && queryParams) { | ||
return `${path}${delimiter}${queryParams}`; | ||
return `${root}${path}${delimiter}${queryParams}`; | ||
} | ||
@@ -191,0 +209,0 @@ |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
52189
1331
211