-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathready.js
101 lines (85 loc) · 2.24 KB
/
ready.js
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
var request = require('request');
var config = {
client_id:"4Pm0nE1Hmz9_cFKw1RhD4xMcW_nCYUK4",
app_id:"JE2DrYT_92kBN8ySHav13qYEj57lO6Yx",
server_token:"jL8RGdtvdFzvx4wXw-zkk6TmwIKNLVAQUJEjJI9W",
app_key:"RG04UNNERL7rhtdjlOeV-Jo0qo2PDHrDwvxWw42M"
};
var CONST = {
UBER_API:"https://sandbox-api.uber.com.cn",
UBER_AUTH_SERVER:"https://login.uber.com.cn/oauth/v2/authorize"
};
var readLib = require('./read-lib.js');
global.library = readLib(__dirname + "/lib");
console.log(library);
var acl = readLib(__dirname + "/ACL");
console.log(acl);
var ACL = {};
for(var _i in acl){
ACL[_i] = AV.Object.extend(_i,acl[_i]);
}
global.ACL = ACL;
var querystring = require('querystring');
global._Get = function(baseUrl,query,headers){
var options = {};
options.headers = {};
if(!headers){
headers = {};
}
for(var _i in headers){
options.headers[_i] = headers[_i];
}
var url =
baseUrl
+ "?"
+ querystring.stringify(query);
options.url = url;
return new Promise(function(resolve,reject){
request(
options
,function(e,r,body){
if(e){
return reject(e);
}else{
return resolve({
response:r,
body:body
});
}
});
});
};
_Get("https://login.uber.com.cn/oauth/v2/authorize",{
response_type:"code",
scope:"request",
client_id:config.client_id
},{
"Authorization":" Token " + config.server_token
}).then(function(all){
console.log(all.body);
console.log("done");
}).catch(function(e){
console.error(e);
});
global._Post = function(url,data,headers){
var header = {};
for(var i in headers){
header[i] = headers[i];
}
console.log(url);
return new Promise(function(resolve,reject){
request.post({
url:url,
json:data,
headers:header
},function(err, httpResponse, body) {
if (err) {
return reject(err);
}else{
return resolve(body);
}
});
});
};
global.config = config;
global.CONST = CONST;