Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update npm request module #5

Merged
merged 4 commits into from Aug 29, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions .gitignore
@@ -1 +1,2 @@
node_modules
.npm-debug.log
9 changes: 7 additions & 2 deletions README.md
@@ -1,9 +1,9 @@
# SCSBRestClient

This is a light wrapper around SCSB's [RESTful interace](https://uat-recap.htcinc.com:9093/swagger-ui.html).
This is a light wrapper around SCSB's [RESTful interace](https://scsb.recaplib.org:9093/swagger-ui.html).

## Version
> 1.0.2
> 1.0.4

## Install

Expand Down Expand Up @@ -75,3 +75,8 @@ When you _accept_ a PR - you should:
#### Deprecated

- `.searchByParam()`

### v1.0.4

#### Updated
- Updated NPM packages to address npm request module bug [#1595](https://github.com/request/request/issues/1595)
12 changes: 6 additions & 6 deletions package.json
@@ -1,16 +1,16 @@
{
"name": "@nypl/scsb-rest-client",
"version": "1.0.2",
"version": "1.0.4",
"description": "A light wrapper around SCSB's RESTful interface",
"main": "scsb_rest_client.js",
"dependencies": {
"request": "2.53.0"
"request": "2.81.0"
},
"devDependencies": {
"chai": "4.0.2",
"chai-as-promised": "7.0.0",
"mocha": "3.2.0",
"standard": "6.0.8"
"chai": "4.1.1",
"chai-as-promised": "7.1.1",
"mocha": "3.5.0",
"standard": "10.0.3"
},
"standard": {
"env": {
Expand Down
14 changes: 7 additions & 7 deletions scsb_rest_client.js
@@ -1,8 +1,7 @@
var request = require('request')
const request = require('request')

// myClient = new SCSBRestClient({url: "foo", apiKey: "bar"})
class SCSBRestClient {

constructor ({url = null, apiKey = null}) {
this.url = url
this.apiKey = apiKey
Expand All @@ -29,7 +28,7 @@ class SCSBRestClient {
} else if (response && response.statusCode === 200) {
resolve(JSON.parse(body))
} else {
reject(`Error hitting SCSB API ${response.statusCode}: ${response.body}`)
reject(new Error(`Error hitting SCSB API ${response.statusCode}: ${response.body}`))
}
})
})
Expand All @@ -52,7 +51,7 @@ class SCSBRestClient {
} else if (response && response.statusCode === 200) {
resolve(JSON.parse(body))
} else {
reject(`Error hitting SCSB API ${response.statusCode}: ${response.body}`)
reject(new Error(`Error hitting SCSB API ${response.statusCode}: ${response.body}`))
}
})
})
Expand All @@ -74,15 +73,17 @@ class SCSBRestClient {
} else if (response && response.statusCode === 200) {
resolve(JSON.parse(body))
} else {
reject(`Error hitting SCSB API ${response.statusCode}: ${response.body}`)
reject(new Error(`Error hitting SCSB API ${response.statusCode}: ${response.body}`))
}
})
})
}

addRequestItem (data) {
if (!data || !Object.keys(data).length) {
return Promise.reject('the data parameter is empty or undefined; could not initialize POST request')
return Promise.reject(
new Error('the data parameter is empty or undefined; could not initialize POST request')
)
}

return new Promise((resolve, reject) => {
Expand Down Expand Up @@ -127,7 +128,6 @@ class SCSBRestClient {
'Content-Type': 'application/json'
}
}

}

module.exports = SCSBRestClient
2 changes: 1 addition & 1 deletion test/scsb_rest_client.test.js
@@ -1,4 +1,4 @@
/* eslint no-new:0*/
/* eslint no-new:0 */
const chai = require('chai')
const expect = chai.expect
const chaiAsPromised = require('chai-as-promised')
Expand Down