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

swapped request with got #43

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 1 addition & 2 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,7 @@
"browser": "dist/browser/uphold-sdk-javascript.js",
"dependencies": {
"content-range": "1.1.0",
"request": "2.88.2",
"request-promise": "4.2.5",
"got": "^11.8.0",
"standard-error": "1.1.0"
},
"devDependencies": {
Expand Down
2 changes: 1 addition & 1 deletion src/core/utils/request-helper.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ export function buildBody(data) {
}

export function buildBasicAuthorizationHeader(username, password) {
const credentials = new Buffer(`${username}:${password}`).toString('base64');
const credentials = Buffer.from(`${username}:${password}`).toString('base64');

return { authorization: `Basic ${credentials}` };
}
Expand Down
12 changes: 6 additions & 6 deletions src/node/services/request-client.js
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
import { Client, createError } from '../../core';
import { RequestError } from 'request-promise/errors';
import request from 'request-promise';
import got from 'got';

export default class RequestClient extends Client {

request(url, method, body, headers = {}, options) { // eslint-disable-line max-params
return request({
return got({
...options,
body,
headers: {
...this.defaultHeaders,
...headers
},
https: {
rejectUnauthorized: false
},
method,
resolveWithFullResponse: true,
strictSSL: false,
url
})
.then(response => this._formatResponse(response))
.catch(response => Promise.reject(response instanceof RequestError ? response : createError(this._formatResponse(response.response), response)));
.catch(response => Promise.reject(response.response ? createError(this._formatResponse(response.response), response) : response));
}

_formatResponse({ body, headers, statusCode }) {
Expand Down
4 changes: 2 additions & 2 deletions test/node/services/request-client.spec.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { NotFoundError, RequestClient } from '../../../src/node';
import { RequestError } from 'request-promise/errors';
import { RequestError } from 'got';
import nock from 'nock';

describe('RequestClient', () => {
describe('request()', () => {
const url = 'http://foo.bar';
const url = 'https://api.uphold.com/';

it('should return formatted response if status is 200', () => {
nock(url)
Expand Down
Loading