Skip to content

Commit

Permalink
Merge branch 'release/v0.7.4'
Browse files Browse the repository at this point in the history
  • Loading branch information
alexanderwe committed Nov 11, 2018
2 parents 23554b3 + 58858d7 commit 85864e5
Show file tree
Hide file tree
Showing 10 changed files with 4,952 additions and 7,284 deletions.
1 change: 1 addition & 0 deletions .nvmrc
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
10.8.0
1 change: 0 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
[![Build Status](https://travis-ci.org/alexanderwe/the-traveler.svg?branch=master)](https://travis-ci.org/alexanderwe/the-traveler)
[![codecov](https://codecov.io/gh/alexanderwe/the-traveler/branch/master/graph/badge.svg)](https://codecov.io/gh/alexanderwe/the-traveler)
[![dependencies Status](https://david-dm.org/alexanderwe/the-traveler/status.svg)](https://david-dm.org/alexanderwe/the-traveler)
[![Known Vulnerabilities](https://snyk.io/test/github/alexanderwe/the-traveler/badge.svg)](https://snyk.io/test/github/alexanderwe/the-traveler/badge.svg)

the-traveler is a small npm package which wraps around the Destiny 2 API. It uses Promises for a modern workflow in your application.

Expand Down
7,153 changes: 0 additions & 7,153 deletions package-lock.json

This file was deleted.

5 changes: 3 additions & 2 deletions package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "the-traveler",
"version": "0.7.2",
"version": "0.7.4",
"description": "A Node.js API wrapper for the Destiny 2 API",
"keywords": [
"destiny2",
Expand All @@ -27,7 +27,8 @@
"watch": "tsc --watch --p tsconfig.json --declaration --target es5",
"test": "jest --coverage",
"posttest": "codecov",
"doc": "typedoc --target ES5 --readme ./README.md --name 'The Traveler' --mode file --out ./docs/ --hideGenerator --exclude **/node_modules/** ./src/*.ts --ignoreCompilerErrors && touch ./docs/.nojekyll"
"doc": "typedoc --target ES5 --readme ./README.md --name 'The Traveler' --mode file --out ./docs/ --hideGenerator --exclude **/node_modules/** ./src/*.ts --ignoreCompilerErrors && touch ./docs/.nojekyll",
"package": "npm pack"
},
"dependencies": {
"@types/request-promise-native": "^1.0.6",
Expand Down
114 changes: 57 additions & 57 deletions src/HttpService.ts
Original file line number Diff line number Diff line change
@@ -1,69 +1,69 @@
import 'es6-promise';
import * as request from 'request';
import * as rp from 'request-promise-native';

/**
* Wrapper class for the request package. Used to make HTTP calls.
*/
export default class HTTPService {
private debug?: boolean;
private debug?: boolean;

constructor(debug?: boolean) {
this.debug = debug;
}
constructor(debug?: boolean) {
this.debug = debug;
}

/**
* Base function for GET requests
* @async
* @param options Options for the request package to use
* @return {Promise.any} When fulfilled returns an object containing the response from the request
*/
public get(options: rp.OptionsWithUri): Promise<object> {
options.method = 'GET';
if (this.debug) {
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri);
}
return new Promise<object>((resolve, reject) => {
rp(options)
.then((response) => {
if (response.access_token) { // this is a oauth reponse
resolve(response);
} else if (response.ErrorCode !== 1) {
reject(response);
} else {
resolve(response);
}
})
.catch((err) => {
reject(err);
});
});
/**
* Base function for GET requests
* @async
* @param options Options for the request package to use
* @return {Promise.any} When fulfilled returns an object containing the response from the request
*/
public get(options: rp.OptionsWithUri): Promise<object> {
options.method = 'GET';
if (this.debug) {
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri);
}

/**
* Base function for POST requests
* @async
* @param options Options for the request package to use
* @return {Promise.any} When fulfilled returns an object containing the response from the request
*/
public post(options: rp.OptionsWithUri): Promise<object> {
options.method = 'POST';
if (this.debug) {
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri);
}
return new Promise<object>((resolve, reject) => {
rp(options)
.then((response) => {
if (response.access_token) { // this is a oauth reponse
resolve(response);
} else if (response.ErrorCode !== 1) {
reject(response);
}
resolve(response);
})
.catch((err) => {
reject(err);
});
return new Promise<object>((resolve, reject) => {
rp(options)
.then(response => {
if (response.access_token) {
// this is a oauth reponse
resolve(response);
} else if (response.ErrorCode !== 1) {
reject(response);
} else {
resolve(response);
}
})
.catch(err => {
reject(err);
});
});
}

/**
* Base function for POST requests
* @async
* @param options Options for the request package to use
* @return {Promise.any} When fulfilled returns an object containing the response from the request
*/
public post(options: rp.OptionsWithUri): Promise<object> {
options.method = 'POST';
if (this.debug) {
console.log('\x1b[33m%s\x1b[0m', 'Debug url:' + options.uri);
}
return new Promise<object>((resolve, reject) => {
rp(options)
.then(response => {
if (response.access_token) {
// this is a oauth reponse
resolve(response);
} else if (response.ErrorCode !== 1) {
reject(response);
}
resolve(response);
})
.catch(err => {
reject(err);
});
});
}
}
Loading

0 comments on commit 85864e5

Please sign in to comment.