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

switch to axios #4

Open
wants to merge 8 commits 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: 3 additions & 0 deletions .idea/.gitignore

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

6 changes: 6 additions & 0 deletions .idea/vcs.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

8 changes: 5 additions & 3 deletions README.md
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
# Usage example
npm install node-real-debrid --save
npm install real-debrid-api --save
```javascript
const RealDebridClient = require('node-real-debrid')
const RealDebridClient = require('real-debrid-api')
const RD = new RealDebridClient('Your API Token')

;(async () => {
Expand All @@ -13,8 +13,10 @@ const RD = new RealDebridClient('Your API Token')
console.log(await RD.traffic.get())
console.log(await RD.unrestrict.link('https://openload.co/f/faqKmuLs7ro/Scappa_-_Get_Out_%5BHD%5D_%282017%29_MD_Bluray_1080p.mp4'))
console.log(await RD.torrents.addTorrent(__dirname + '\\file.torrent'))
console.log(await RD.torrents.addMagnet('magnet_link'))
console.log(await RD.streaming.mediaInfos('id'))
} catch (e) {
console.log(e)
}
})()
```
```
Empty file modified index.js
100644 → 100755
Empty file.
Empty file modified lib/ErrorCodes.js
100644 → 100755
Empty file.
55 changes: 24 additions & 31 deletions lib/RealDebridClient.js
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
'use strict'

const fs = require('fs')
const request = require('request')
const axios = require('axios')
const errors = require('./ErrorCodes')

class RealDebridClient {
Expand All @@ -14,12 +13,6 @@ class RealDebridClient {

}

_readFile (path) {

return fs.createReadStream(path)

}

_request (endpoint, o = {}) {

const url = this.base_url + endpoint
Expand All @@ -37,28 +30,28 @@ class RealDebridClient {
}

return new Promise((resolve, reject) => {

request(options, (error, response, body) => {
if (error) {
reject(error)
} else {
if (typeof body !== 'undefined') {
if (options.binary) body = JSON.parse(body)
if (body.error) {
reject({
code: body.error_code,
message: errors[body.error_code]
})
} else {
resolve(body)
}
} else if (response.statusCode === 204) {
resolve()
} else {
reject()
}
}
})
axios(options.url, options).then(resolve).catch(reject)
// request(options, (error, response, body) => {
// if (error) {
// reject(error)
// } else {
// if (typeof body !== 'undefined') {
// if (options.binary) body = JSON.parse(body)
// if (body.error) {
// reject({
// code: body.error_code,
// message: errors[body.error_code]
// })
// } else {
// resolve(body)
// }
// } else if (response.statusCode === 204) {
// resolve()
// } else {
// reject()
// }
// }
// })

})

Expand Down Expand Up @@ -187,7 +180,7 @@ class RealDebridClient {
}

this.torrents = {
get: (offset = null, page = null, limit = 50, filter = 'active') => {
get: (offset = null, page = null, limit = 50, filter = '') => {
return this._get('torrents', {
qs: {
offset,
Expand Down
16 changes: 8 additions & 8 deletions package.json
100644 → 100755
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "node-real-debrid",
"version": "1.0.6",
"description": "Real debrid API library",
"name": "real-debrid-api",
"version": "1.0.1",
"description": "Real-debrid API library",
"main": "index.js",
"directories": {
"lib": "lib"
Expand All @@ -11,20 +11,20 @@
},
"repository": {
"type": "git",
"url": "git+https://github.com/razorxan/node-real-debrid.git"
"url": "git+https://github.com/atombarel/node-real-debrid.git"
},
"keywords": [
"realdebrid",
"real",
"debrid"
],
"author": "razorxan",
"author": "Andrea Tombarel",
"license": "MIT",
"bugs": {
"url": "https://github.com/razorxan/node-real-debrid/issues"
"url": "https://github.com/atombarel/node-real-debrid/issues"
},
"homepage": "https://github.com/razorxan/node-real-debrid#readme",
"homepage": "https://github.com/atombarel/node-real-debrid#readme",
"dependencies": {
"request": "^2.83.0"
"axios": "^0.19.2"
}
}