dsgstng-api
Advanced tools
Comparing version 0.0.3 to 0.0.4
73
app.js
@@ -11,3 +11,3 @@ const request = require('request'), | ||
constructor(token) { | ||
this.token = token || '' | ||
this.token = token || '' | ||
this.stream = { | ||
@@ -20,7 +20,16 @@ resolution: { | ||
return new Promise((res, rej) => { | ||
request.get(`${origin}/stream/resolution?token=${this.token}`, (err, response, body) => { | ||
if (err){ | ||
request.get({ | ||
url: `${origin}/stream/resolution`, | ||
qs: { | ||
token: this.token | ||
} | ||
}, (err, response, body) => { | ||
if (err) { | ||
util.log(err) | ||
return rej(err) | ||
} | ||
if (response.statusCode != 200){ | ||
util.log(body) | ||
return rej(body.data.message) | ||
} | ||
return res(JSON.parse(body).data) | ||
@@ -35,3 +44,8 @@ }) | ||
return new Promise((res, rej) => { | ||
request.post(`${origin}/stream/resolution?token=${this.token}`, { | ||
request.post({ | ||
url: `${origin}/stream/resolution` | ||
}, { | ||
qs: { | ||
token: this.token | ||
}, | ||
json: true, | ||
@@ -42,6 +56,10 @@ body: { | ||
}, (err, response, body) => { | ||
if (err){ | ||
if (err) { | ||
util.log(err) | ||
return rej(err) | ||
} | ||
if (response.statusCode != 200){ | ||
util.log(body) | ||
return rej(body.data.message) | ||
} | ||
return res(JSON.parse(body).data) | ||
@@ -58,11 +76,24 @@ }) | ||
* @param {string} [params.year] Year (default gets from Date.now()) | ||
* @param {string} params.season Anime season (example:'summer'or'spring') | ||
* @param {string} [params.season] Anime season (example:'summer'or'spring') | ||
*/ | ||
get: (params) => { | ||
return new Promise((res, rej) => { | ||
request.get(`${origin}/calendar/schedule`+ params ? `?year=${params.year ? params.year :new Date(Date.now()).getFullYear()}&season=${params.season}`:'' , (err, response, body) => { | ||
if (err){ | ||
let conf = { | ||
uri: `${origin}/calendar/schedule` | ||
} | ||
if (params.season && params.year){ | ||
conf.qs= { | ||
year: params.year, | ||
season: params.season | ||
} | ||
} | ||
request.get(conf, (err, response, body) => { | ||
if (err) { | ||
util.log(err) | ||
return rej(err) | ||
} | ||
if (response.statusCode != 200){ | ||
util.log(body) | ||
return rej(body.data.message) | ||
} | ||
return res(JSON.parse(body).data) | ||
@@ -76,2 +107,26 @@ }) | ||
} | ||
module.exports = Api | ||
module.exports = Api | ||
// function request(data) { | ||
// return new Promise(function (res, rej) { | ||
// let xmlhttp = new XMLHttpRequest() | ||
// xmlhttp.onreadystatechange = function () { | ||
// let myObj | ||
// if (this.responseText) { | ||
// try { | ||
// myObj = JSON.parse(this.responseText) | ||
// } catch (e) { | ||
// return rej('Error while parsing response') | ||
// } | ||
// res(myObj) | ||
// } | ||
// } | ||
// xmlhttp.open('GET', data.url, true) | ||
// if (data.header) { | ||
// xmlhttp.setRequestHeader(data.header.name, data.header.value) | ||
// } | ||
// xmlhttp.send() | ||
// }) | ||
// } |
{ | ||
"name": "dsgstng-api", | ||
"version": "0.0.3", | ||
"version": "0.0.4", | ||
"description": "Interface of interaction with dsgstng.com api", | ||
"main": "app.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
"build": "cross-env NODE_ENV=production webpack --config webpack/prod.config.js --progress --display-error-details --colors", | ||
"dev": "cross-env NODE_ENV=development webpack-dev-server --config webpack/dev.config.js --watch --colors" | ||
}, | ||
"private": false, | ||
"keywords":[ | ||
"dsgstng", | ||
"api", | ||
"request" | ||
"keywords": [ | ||
"dsgstng", | ||
"api", | ||
"request" | ||
], | ||
@@ -18,2 +19,3 @@ "author": "ejnshtein", | ||
"dependencies": { | ||
"promise": "^8.0.1", | ||
"request": "^2.87.0" | ||
@@ -24,3 +26,11 @@ }, | ||
"url": "https://github.com/dsgstng/api.git" | ||
}, | ||
"devDependencies": { | ||
"cross-env": "^5.2.0", | ||
"eslint": "^5.0.1", | ||
"eslint-loader": "^2.0.0", | ||
"webpack": "^4.14.0", | ||
"webpack-cli": "^3.0.8", | ||
"write-file-webpack-plugin": "^4.3.2" | ||
} | ||
} |
Interface of interaction with [dsgstng.com](https://dsgstng.com) api | ||
Docs soon | ||
``` | ||
// api usage example | ||
// backend api usage example | ||
const Api = require('dsgstng-api') | ||
const dsgstngApi = new Api() // OR if you had token, put it there. | ||
dsgstngApi.stream.resolution.get() | ||
.then(resolution => { | ||
const dsgstngApi = new Api() // OR if you had token, put it here. | ||
dsgstngApi.calendar.schedule.get() | ||
.then(calendar => { | ||
// Do something | ||
@@ -14,4 +13,27 @@ }) | ||
}) | ||
// frontend api usage example (using webpack) | ||
import Api from 'dsgstng-api/web.api' | ||
const dsgstngApi = new Api() // again token if you had | ||
dsgstngApi.calendar.schedule.get() | ||
.then(calendar => { | ||
// Do something | ||
}) | ||
.catch(err => { | ||
// Display error | ||
}) | ||
// frontend without frameworks | ||
// some.html | ||
<script src="/node_modules/dsgstng-api/dist/DsgstngApi.min.js'></script> | ||
// some.js | ||
const dsgstngApi = new DsgstngApi() | ||
dsgstngApi.calendar.schedule.get() | ||
.then(calendar => { | ||
// REEEEEEEEEEEEEEEEEEEEEEEE | ||
}) | ||
.catch(err => { | ||
// REEEEEEEEEEEEEEEEEEEEEEEE | ||
}) | ||
``` | ||
Full doc soon | ||
``` | ||
For more details contact [him](https://t.me/ejnshtein) | ||
For details contact [him](https://t.me/ejnshtein) |
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
Major refactor
Supply chain riskPackage has recently undergone a major refactor. It may be unstable or indicate significant internal changes. Use caution when updating to versions that include significant changes.
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
No tests
QualityPackage does not have any tests. This is a strong signal of a poorly maintained or low quality package.
Found 1 instance in 1 package
22051
14
352
2
38
2
6
1
+ Addedpromise@^8.0.1
+ Addedasap@2.0.6(transitive)
+ Addedpromise@8.3.0(transitive)