-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathapi.js
More file actions
49 lines (49 loc) · 1.27 KB
/
api.js
File metadata and controls
49 lines (49 loc) · 1.27 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
var http = require("http"),
querystring = require("querystring");
module.exports.apiCall=function(urlpart,options,id,callback,errorCallback,method)
{
var onError = errorCallback || function() {},
baseUrl = "yify-torrents.com",
apiEndPoint = "/api/"+urlpart+"?",
params = null,
url = null,
result = "",
options = options || {},
rest = {};
if(id!=null)
{
options = id;
}
if(options!=null)
{
params = querystring.stringify(options);
}
var path = apiEndPoint+params;
rest = {
hostname: baseUrl,
port: 80,
path: path,
method : method,
headers: {
'Content-Type': 'application/json'
}
};
url = baseUrl+apiEndPoint+params;
console.log(url);
http.request(rest,function(res){
res.setEncoding('utf8');
console.log(res.statusCode);
res.on('data',function(chunk){
result += chunk;
});
res.on('end',function(){
var resultData = JSON.parse(result) ;
//console.log(resultData);
callback(resultData) ;
});
})
.on('error',function(){
console.log("There is an error in the request");
})
.end();
}