forked from RobinBobin/react-native-google-drive-api-wrapper
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGDrive.js
More file actions
43 lines (33 loc) · 1.1 KB
/
GDrive.js
File metadata and controls
43 lines (33 loc) · 1.1 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
import Files from "./Files";
import Permissions from "./Permissions";
export default class GDrive {
static _urlFiles = "https://www.googleapis.com/drive/v3/files";
static _contentTypeJson = "application/json; charset=UTF-8";
static init(params = {}) {
GDrive.files = new Files(params.files);
GDrive.permissions = new Permissions();
}
static setAccessToken(accessToken) {
GDrive.accessToken = accessToken;
}
static isInitialized() {
return !!GDrive.accessToken;
}
static _createHeaders(contentType, contentLength, ... additionalPairs) {
let pairs = [
[ "Authorization", `Bearer ${GDrive.accessToken}` ]
];
[
[ "Content-Type", contentType] ,
[ "Content-Length", contentLength ]
].forEach(data => data[1] ? pairs.push(data) : undefined);
if (additionalPairs) {
pairs = pairs.concat(additionalPairs);
}
const headers = new Headers();
for (let pair of pairs) {
headers.append(pair[0], pair[1]);
}
return headers;
}
}