-
Notifications
You must be signed in to change notification settings - Fork 0
/
Client.js
126 lines (113 loc) · 3.47 KB
/
Client.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
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
var request = require('request')
function Client(accessToken) {
this.accessToken = accessToken
this.request = request.defaults({
baseUrl: 'https://www.googleapis.com/admin',
auth: {
bearer: this.accessToken
},
json: true
})
this.calendarResource = new CalendarResource(this)
this.buildingResource = new BuildingResource(this)
}
function CalendarResource(client) {
this.client = client
this.resourcePath = '/directory/v1/customer/my_customer/resources/calendars'
}
function BuildingResource(client) {
this.client = client
this.resourcePath = '/directory/v1/customer/my_customer/resources/buildings'
}
function list(qs, cb) {
if (typeof qs === 'function') {
cb = qs
qs = {}
}
return this.client.request({method: 'GET', uri: this.resourcePath, qs: qs}, cb)
}
function get(resourceId, qs, cb) {
if (typeof qs === 'function') {
cb = qs
qs = {}
}
return this.client.request({method: 'GET', uri: getUrlForResource(this.resourcePath, resourceId), qs: qs}, cb)
}
// The request library does not correctly encode non-ascii characters when provided
// in the uri. See: https://github.com/request/request/pull/2210 for more info.
function getUrlForResource(path, id) {
// Prevent double encoding by calling decodeURI first
resourceId = encodeURIComponent(decodeURIComponent(id));
return path + '/' + resourceId;
}
/*
* Gets a list of calendar resources for authenticated user's account.
*
* @param [object] qs
* @option [string] qs.pageToken
* @option [number] qs.maxResults
* @callback (err, resources)
*
* API Endpoint: https://www.googleapis.com/admin/directory/v1/customer/[customer_id]/resources/calendars
* API Documentation: https://developers.google.com/admin-sdk/directory/v1/reference/resources/calendars/list
* Example Response:
* {
* "kind": "admin#directory#resources#calendars#calendarResourcesList",
* "etag": etag,
* "nextPageToken": string,
* "items": [
* resources.calendars Resource
* ]
* }
*/
CalendarResource.prototype.list = list
/*
* Gets a list of building resources for authenticated user's account.
*
* @param [object] qs
* @option [string] qs.pageToken
* @option [number] qs.maxResults
* @callback (err, resources)
*
* API Endpoint: https://www.googleapis.com/admin/directory/v1/customer/[customer_id]/resources/buildings
* API Documentation: https://developers.google.com/admin-sdk/directory/v1/reference/resources/buildings/list
* Example Response:
* {
* "kind": "admin#directory#resources#buildings#buildingsList",
* "etag": etag,
* "nextPageToken": string,
* "buildings": [
* resources.buildings Resource
* ]
* }
*/
BuildingResource.prototype.list = list
/*
* Gets a single building resource from an authenticated user's account.
*
* @param [string] resourceId The id of the resource to be retrieved
* @param [object] qs
* @option [string] qs.pageToken
* @option [number] qs.maxResults
* @callback (err, resource)
*
* API Endpoint: https://www.googleapis.com/admin/directory/v1/customer/[customer_id]/resources/buildings/[building_id]
* API Documentation: https://developers.google.com/admin-sdk/directory/v1/reference/resources/buildings/get
* Example Response:
* {
* "kind": "admin#directory#resources#buildings#Building",
* "etags": etag,
* "buildingId": string,
* "buildingName": string,
* "description": string,
* "coordinates": {
* "latitude": double,
* "longitude": double
* },
* "floorNames": [
* string
* ]
* }
*/
BuildingResource.prototype.get = get
module.exports = Client