質問編集履歴
3
fd
title
CHANGED
File without changes
|
body
CHANGED
@@ -43,7 +43,9 @@
|
|
43
43
|
84: cb();
|
44
44
|
85: });
|
45
45
|
86: }
|
46
|
+
|
46
47
|
・・・中略
|
48
|
+
|
47
49
|
function setAuthAndDependencies(auth) {
|
48
50
|
google_auth = auth;
|
49
51
|
if (!options.visibility) {
|
@@ -53,6 +55,157 @@
|
|
53
55
|
projection = google_auth ? "full" : "values";
|
54
56
|
}
|
55
57
|
}
|
58
|
+
|
59
|
+
・・・中略
|
60
|
+
|
61
|
+
// public API methods
|
62
|
+
this.getInfo = function(cb) {
|
63
|
+
self.makeFeedRequest(["worksheets", ss_key], "GET", null, function(
|
64
|
+
err,
|
65
|
+
data
|
66
|
+
) {
|
67
|
+
if (err) return cb(err);
|
68
|
+
if (data === true) {
|
69
|
+
return cb(new Error("No response to getInfo call"));
|
70
|
+
}
|
71
|
+
var ss_data = {
|
72
|
+
id: data.id,
|
73
|
+
title: data.title,
|
74
|
+
updated: data.updated,
|
75
|
+
author: data.author,
|
76
|
+
worksheets: []
|
77
|
+
};
|
78
|
+
var worksheets = forceArray(data.entry);
|
79
|
+
worksheets.forEach(function(ws_data) {
|
80
|
+
ss_data.worksheets.push(new SpreadsheetWorksheet(self, ws_data));
|
81
|
+
});
|
82
|
+
self.info = ss_data;
|
83
|
+
self.worksheets = ss_data.worksheets;
|
84
|
+
cb(null, ss_data);
|
85
|
+
});
|
86
|
+
};
|
87
|
+
|
88
|
+
・・・中略
|
89
|
+
|
90
|
+
// This method is used internally to make all requests
|
91
|
+
this.makeFeedRequest = function(url_params, method, query_or_data, cb) {
|
92
|
+
var url;
|
93
|
+
var headers = {};
|
94
|
+
if (!cb) cb = function() {};
|
95
|
+
if (typeof url_params == "string") {
|
96
|
+
// used for edit / delete requests
|
97
|
+
url = url_params;
|
98
|
+
} else if (Array.isArray(url_params)) {
|
99
|
+
//used for get and post requets
|
100
|
+
url_params.push(visibility, projection);
|
101
|
+
url = GOOGLE_FEED_URL + url_params.join("/");
|
102
|
+
}
|
103
|
+
|
104
|
+
async.series({
|
105
|
+
auth: function(step) {
|
106
|
+
if (auth_mode != "jwt") return step();
|
107
|
+
// check if jwt token is expired
|
108
|
+
if (google_auth && google_auth.expires > +new Date()) return step();
|
109
|
+
renewJwtAuth(step);
|
110
|
+
},
|
111
|
+
request: function(result, step) {
|
112
|
+
if (google_auth) {
|
113
|
+
if (google_auth.type === "Bearer") {
|
114
|
+
headers["Authorization"] = "Bearer " + google_auth.value;
|
115
|
+
} else {
|
116
|
+
headers["Authorization"] = "GoogleLogin auth=" + google_auth;
|
117
|
+
}
|
118
|
+
}
|
119
|
+
|
120
|
+
headers["Gdata-Version"] = "3.0";
|
121
|
+
|
122
|
+
if (method == "POST" || method == "PUT") {
|
123
|
+
headers["content-type"] = "application/atom+xml";
|
124
|
+
}
|
125
|
+
|
126
|
+
if (
|
127
|
+
method == "PUT" ||
|
128
|
+
(method == "POST" && url.indexOf("/batch") != -1)
|
129
|
+
) {
|
130
|
+
headers["If-Match"] = "*";
|
131
|
+
}
|
132
|
+
|
133
|
+
if (method == "GET" && query_or_data) {
|
134
|
+
var query = "?" + querystring.stringify(query_or_data);
|
135
|
+
// replacements are needed for using structured queries on getRows
|
136
|
+
query = query.replace(/%3E/g, ">");
|
137
|
+
query = query.replace(/%3D/g, "=");
|
138
|
+
query = query.replace(/%3C/g, "<");
|
139
|
+
url += query;
|
140
|
+
}
|
141
|
+
|
142
|
+
request(
|
143
|
+
{
|
144
|
+
url: url,
|
145
|
+
method: method,
|
146
|
+
headers: headers,
|
147
|
+
gzip: options.gzip !== undefined ? options.gzip : true,
|
148
|
+
body: method == "POST" || method == "PUT" ? query_or_data : null
|
149
|
+
},
|
150
|
+
function(err, response, body) {
|
151
|
+
if (err) {
|
152
|
+
return cb(err);
|
153
|
+
} else if (response.statusCode === 401) {
|
154
|
+
return cb(new Error("Invalid authorization key."));
|
155
|
+
} else if (response.statusCode >= 400) {
|
156
|
+
var message = _.isObject(body)
|
157
|
+
? JSON.stringify(body)
|
158
|
+
: body.replace(/"/g, '"');
|
159
|
+
return cb(
|
160
|
+
new Error(
|
161
|
+
"HTTP error " +
|
162
|
+
response.statusCode +
|
163
|
+
" (" +
|
164
|
+
http.STATUS_CODES[response.statusCode]
|
165
|
+
) +
|
166
|
+
") - " +
|
167
|
+
message
|
168
|
+
);
|
169
|
+
} else if (
|
170
|
+
response.statusCode === 200 &&
|
171
|
+
response.headers["content-type"].indexOf("text/html") >= 0
|
172
|
+
) {
|
173
|
+
return cb(
|
174
|
+
new Error(
|
175
|
+
"Sheet is private. Use authentication or make public. (see https://github.com/theoephraim/node-google-spreadsheet#a-note-on-authentication for details)"
|
176
|
+
)
|
177
|
+
);
|
178
|
+
}
|
179
|
+
|
180
|
+
if (body) {
|
181
|
+
var xml_parser = new xml2js.Parser({
|
182
|
+
// options carried over from older version of xml2js
|
183
|
+
// might want to update how the code works, but for now this is fine
|
184
|
+
explicitArray: false,
|
185
|
+
explicitRoot: false
|
186
|
+
});
|
187
|
+
xml_parser.parseString(body, function(err, result) {
|
188
|
+
if (err) {
|
189
|
+
xml_parser = null;
|
190
|
+
body = null;
|
191
|
+
return cb(err);
|
192
|
+
}
|
193
|
+
if (cb.length == 3) {
|
194
|
+
cb(null, result, body);
|
195
|
+
} else {
|
196
|
+
body = null;
|
197
|
+
cb(null, result);
|
198
|
+
}
|
199
|
+
});
|
200
|
+
} else {
|
201
|
+
if (err) cb(err);
|
202
|
+
else cb(null, true);
|
203
|
+
}
|
204
|
+
}
|
205
|
+
);
|
206
|
+
}
|
207
|
+
});
|
208
|
+
};
|
56
209
|
```
|
57
210
|
|
58
211
|
### 該当のソースコード
|
2
f
title
CHANGED
File without changes
|
body
CHANGED
@@ -24,17 +24,34 @@
|
|
24
24
|
```js
|
25
25
|
/Users/user/dev/atom-tools/node_modules/google-spreadsheet/index.js
|
26
26
|
|
27
|
+
this.setAuthToken = function(auth_id) {
|
28
|
+
if (auth_mode == "anonymous") auth_mode = "token";
|
29
|
+
setAuthAndDependencies(auth_id);
|
30
|
+
};
|
31
|
+
|
32
|
+
...中略
|
33
|
+
|
27
|
-
function renewJwtAuth(cb) {
|
34
|
+
75: function renewJwtAuth(cb) {
|
28
|
-
auth_mode = "jwt";
|
35
|
+
76: auth_mode = "jwt";
|
29
|
-
jwt_client.authorize(function(err, token) {
|
36
|
+
77: jwt_client.authorize(function(err, token) {
|
30
|
-
if (err) return cb(err);
|
37
|
+
78: if (err) return cb(err);
|
31
|
-
self.setAuthToken({
|
38
|
+
79: self.setAuthToken({
|
32
|
-
type: token.token_type,
|
39
|
+
80: type: token.token_type,
|
33
|
-
value: token.access_token,
|
40
|
+
81: value: token.access_token,
|
34
|
-
expires: token.expiry_date
|
41
|
+
82: expires: token.expiry_date
|
35
|
-
});
|
42
|
+
83: });
|
36
|
-
cb();
|
43
|
+
84: cb();
|
44
|
+
85: });
|
45
|
+
86: }
|
46
|
+
・・・中略
|
47
|
+
function setAuthAndDependencies(auth) {
|
48
|
+
google_auth = auth;
|
49
|
+
if (!options.visibility) {
|
50
|
+
visibility = google_auth ? "private" : "public";
|
37
|
-
}
|
51
|
+
}
|
52
|
+
if (!options.projection) {
|
53
|
+
projection = google_auth ? "full" : "values";
|
54
|
+
}
|
38
55
|
}
|
39
56
|
```
|
40
57
|
|
1
s
title
CHANGED
File without changes
|
body
CHANGED
@@ -21,6 +21,23 @@
|
|
21
21
|
at Object.onceWrapper (events.js:285:13)
|
22
22
|
```
|
23
23
|
|
24
|
+
```js
|
25
|
+
/Users/user/dev/atom-tools/node_modules/google-spreadsheet/index.js
|
26
|
+
|
27
|
+
function renewJwtAuth(cb) {
|
28
|
+
auth_mode = "jwt";
|
29
|
+
jwt_client.authorize(function(err, token) {
|
30
|
+
if (err) return cb(err);
|
31
|
+
self.setAuthToken({
|
32
|
+
type: token.token_type,
|
33
|
+
value: token.access_token,
|
34
|
+
expires: token.expiry_date
|
35
|
+
});
|
36
|
+
cb();
|
37
|
+
});
|
38
|
+
}
|
39
|
+
```
|
40
|
+
|
24
41
|
### 該当のソースコード
|
25
42
|
|
26
43
|
```js
|