-
Notifications
You must be signed in to change notification settings - Fork 16
/
Copy pathGoogle_APIs.saas.txt
69 lines (62 loc) · 3.89 KB
/
Google_APIs.saas.txt
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
┏━━━━━━━━━━━━━━━━━┓
┃ GOOGLE_APIS ┃
┗━━━━━━━━━━━━━━━━━┛
GAPI #Client-side JavaScript bindings for Google APIs, found at
# https://apis.google.com/js/client[:SERVICE].js
#The following must be done in order.
#Need to redo everything for every call???
GAPI.client.setApiKey(API_KEY)#Sets API_KEY, and next action must be async
GAPI.auth.init(FUNC()) #Only to be done if TOKEN_REQUEST.immediate is false
GAPI.auth.authorize #Initiates user consent (popup).
(TOKEN_REQUEST, #TOKEN_REQUEST has no redirect_uri nor response_type
FUNC(ACCESS_TOKEN)) #If ( ! ACCESSTOKEN || ACCESSTOKEN.error ) -> ERROR
GAPI.client.load
(SERVICE, VERSION, FUNC()) #Populates GAIP.client.SERVICE.*. Must be in GAPI.auth.authorize FUNC()
GAPI.client.SERVICE.*() #Google API REST call. Must be in GAPI.client.load FUNC(). Return HTTPREQUEST???
GAPI.client.request(OBJ) # - OBJ has members path STR, method STR (déf: "GET"), params OBJ, headers OBJ, body STR|OBJ.
# - returns a HTTPREQUEST, which can be executed with HTTPREQUEST.execute(FUNC(VAL, STR)):
# - VAL: JSON response
# - STR: raw response (to parse as JSON with members body, headers, status, statusText).
GOOGLEAPIS #Node.js bindings for Google APIs.
#All returns GOOGLEAPIS, so can queue.
new GOOGLEAPIS.OAuth2Client #Returns OAUTHCLIENT
(CLIENT_ID, CLIENT_SECRET, #OBJ (all optional):
REDIRECT_URI[, OBJ]) # - authBaseUrl AUTH_URL
# - tokenUrl TOKEN_URL
# - response_type STR (def: "code")
OAUTHCLIENT.generateAuthUrl
(TOKEN_REQUEST) #Returns AUTH_URL?TOKEN_REQUEST (should redirect user to there)
OAUTHCLIENT.getToken(CODE,
FUNC(ERROR, ACCESS_TOKEN)) #
OAUTHCLIENT.setCredentials
(ACCESS_TOKEN) #
OAUTHCLIENT.request #Send authenticated call (set Authorization header) with REQUEST(OBJ) headers.
(OBJ, FUNC(ERROR, BODY, RES) #Should prefer using HTTPREQUEST.execute()
[, BOOL]) #Will automatically call refreshAccessToken() after, unless BOOL is true.
OAUTHCLIENT.refreshAccessToken
(FUNC(ERROR, ACCESS_TOKEN)) #Auto. reset ACCESS_TOKEN to new one.
OAUTHCLIENT.revokeToken
(TOKEN, FUNC(ERROR)) #
OAUTHCLIENT.verifyToken #If TOKEN valid and not expired returns OBJ:
(TOKEN,FUNC(ERROR, OBJ)) # - getEnvelope(): returns JWT ENVLOP
# - getPayload(): returns JWT PAYLOAD
GOOGLEAPIS.discover
(SERVICE, VERSION_STR) #Load CLIENT.SERVICE.*()
GOOGLEAPIS.execute
(FUNC(ERROR, CLIENT)) #
CLIENT.SERVICE.*() #Returns HTTPREQUEST
HTTPREQUEST.withAuthClient
(OAUTHCLIENT) #Returns HTTPREQUEST
HTTPREQUEST.withApiKey(APIKEY)#Returns HTTPREQUEST (for methods that require it)
HTTPREQUEST.withMedia
(MIME_TYPE, VAL) #Write the request body
HTTPREQUEST.execute
(FUNC(ERROR,VAL)) #
REST API ==> #Usually at https://www.googleapis.com/SERVICE/vVERSION/RESOURCE
#Often require scope https://www.googleapis.com/auth/SERVICE[.SUB]
#RESOURCE is a OBJ.
#In JavaScript:
# - GAPI.client.SERVICE.FUNC(OBJ):
# - URL params (RESOURCE ID) -> OBJ member RESOURCEId
# - query params -> FUNC() ARG
# - request body (RESOURCE) -> OBJ member resource