-
Notifications
You must be signed in to change notification settings - Fork 72
/
class_Github.ahk
523 lines (438 loc) · 17.9 KB
/
class_Github.ahk
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
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
; ===============================================================================================================================
; Title .........: github
; AHK Version ...: 1.1.22.06 x32 Unicode
; Win Version ...: Windows 7 Professional x64 SP1
; Description ...: Implementation of the Github Rest-API v3(https://developer.github.com/v3/)
; Version .......: v 0.0.1;
; Modified ......: 2015.09.18
; Author(s) .....: [email protected]
; ===============================================================================================================================
; Enable/Disable debugging output via OutputDebug
gDebug := 1
class github{
; ******************************************************************************************************************************************
/*
Class: github
Implementation of the Github Rest-API v3 (https://developer.github.com/v3/)
Author(s):
<hoppfrosch at [email protected]>
About: License
This program is free software. It comes without any warranty, to the extent permitted by applicable law. You can redistribute
it and/or modify it under the terms of the Do What The Fuck You Want To Public License, Version 2, as published by Sam Hocevar.
See <WTFPL at http://www.wtfpl.net/> for more details.
*/
_debug := gDebug
_version := "0.0.4"
static http:=[]
__New( name = "", email = "", token = "", baseurl = "https://api.github.com"){
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(name=(" name "), email=(" email "), token=(" token "), baseurl=(" baseurl "))] (version: " this._version ")" ; _DBG_
this.userdata := new this.userdata(name, email)
this.access := new this.access(token, baseurl)
this.orgs := new this.orgs(this.access)
this.orgs.members := new this.orgs.members(this.access)
this.repos := new this.repos(this.access)
this.users := new this.users(this.access)
this.misc := new this.misc(this.access)
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(name=(" name "), email=(" email "), token=(" token "), baseurl=(" baseurl "))]" ; _DBG_
return this
}
version[] {
/* ---------------------------------------------------------------------------------------
Property: version [get]
Get the version of the class (including versions of the subclasses as an object
*/
get {
ret := Object()
ret["github"] := this._version
ret["github.access"] := this.access._version
ret["github.misc"] := this.repos._version
ret["github.userdata"] := this.userdata._version
ret["github.orgs"] := this.orgs._version
ret["github.orgs.members"] := this.orgs.members._version
ret["github.repos"] := this.repos._version
ret["github.users"] := this.users._version
ret["github.misc"] := this.misc._version
return ret
}
}
class access {
; ********************************************************************************************************************************
/*
Class: access
Internal Helper class of github. Communication with https://api.github.com using WinHttpRequest COM Object
Authentication on http://api.github.com is done via github acces token (https://help.github.com/articles/creating-an-access-token-for-command-line-use/)
*/
_debug := gDebug
_version := "0.1.0"
/* ---------------------------------------------------------------------------------------
Method: __New
Constructor (*INTERNAL*)
Parameters:
token - github access token (https://help.github.com/articles/creating-an-access-token-for-command-line-use/)
baseurl - baseurl to github api (Optional - Default: "https://api.github.com")
Returns:
true or false, depending on current value
*/
__New(token = "", baseurl = "https://api.github.com") {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(token=(" token "), baseurl=(" baseurl "))] (version: " this._version ")" ; _DBG_
this._token := token
this._baseURL := baseurl
this._http := ComObjCreate("WinHttp.WinHttpRequest.5.1")
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(token=(" token "), baseurl=(" baseurl "))]" ; _DBG_
return this
}
baseurl[] {
/* ---------------------------------------------------------------------------------------
Property: baseurl [get]
Get baseUrl to access Github-API
Value:
baseUrl - baseUrl to access Github-API
*/
get {
return this._baseUrl
}
}
http[] {
/* ---------------------------------------------------------------------------------------
Property: baseurl [get]
Get HTTP-ComObj
Value:
http - HTTP-ComObj
*/
get {
return this._http
}
}
token[] {
/* ---------------------------------------------------------------------------------------
Property: token [get]
Get accesstoken of the application
Value:
token - accesstoken of the application
*/
get {
return this._token
}
}
url[] {
/* ---------------------------------------------------------------------------------------
Property: url [get/set]
Get/set url of the current query
Value:
url - url of the current query
*/
get {
return this._url
}
set {
this._url:=this.baseurl value "?access_token=" this._token
return value
}
}
send(verb,url,data="",content_type="application/json"){
this.http.Open(verb,url)
if !(data == "") {
this.http.SetRequestHeader("Content-Typ",content_type)
}
this.http.send(data)
return this.http.ResponseText
}
get() {
OutputDebug % "GET " this,_url
json :=this.Send("GET",this._url)
return json
}
patch(data, content_type="application/json") {
json :=this.Send("PATCH",this._url, data, content_type)
return json
}
post(data, content_type="application/json") {
json :=this.Send("POST",this._url, data, content_type)
return json
}
}
class userdata {
; ********************************************************************************************************************************
/*
Class: access
Internal Helper class of github. Storage of user relevant information
*/
_debug := gDebug
_version := "0.1.0"
__New(email = "", name = "", token = "") {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(email=(" email "), name=(" name "),, token=(" token "))] (version: " this._version ")" ; _DBG_
this.name := name
this.email := email
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(email=(" email "), name=(" name "),, token=(" token "))] " ; _DBG_
return this
}
email[] {
/* ---------------------------------------------------------------------------------------
Property: email [get/set]
Set/Get email of the user
Value:
email - email of the user
*/
get {
return this._email
}
set {
this._email := value
return value
}
}
name[] {
/* ---------------------------------------------------------------------------------------
Property: name [get/set]
Set/Get name of the user
Value:
name - name of the user
*/
get {
return this._name
}
set {
this._name := value
return value
}
}
}
class orgs {
; ********************************************************************************************************************************
/*
Class: github.orgs
Subclass of github. Implementation of API-functionality from https://developer.github.com/v3/orgs/
*/
/* Implementation state (https://developer.github.com/v3/orgs/)
VERB | URL | Method
---------+------------------------------------------------------+------------------------------------
GET | /user/orgs | obj.orgs.user_orgs()
GET | /organizations | obj.orgs.organizations()
GET | /users/:username/orgs | _NOT_YET_IMPLEMENTED_
GET | /orgs/:org | _NOT_YET_IMPLEMENTED_
PATCH | /orgs/:org | _NOT_YET_IMPLEMENTED_
*/
_debug := gDebug
_version := "0.1.0"
__New(access) {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(access=(" access "))] (version: " this._version ")" ; _DBG_
this.access := access
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(access=(" access "))]" ; _DBG_
return this
}
user_orgs() {
/* ---------------------------------------------------------------------------------------
Method: List organizations for the authenticated user.
*/
this.access.url := "/user/orgs"
json := this.access.get()
return json
}
organizations() {
/* ---------------------------------------------------------------------------------------
Method: Lists all organizations, in the order that they were created on GitHub.
*/
this.access.url := "/organizations"
json := this.access.get()
return json
}
class members {
; ********************************************************************************************************************************
/*
Class: github.orgs
Subclass of github. Implementation of API-functionality from https://developer.github.com/v3/orgs/members
*/
/* Implementation state (https://developer.github.com/v3/orgs/members)
VERB | URL | Method
---------+------------------------------------------------------+------------------------------------
GET | /orgs/:org/members | obj.orgs.members.org_members(org)
GET | /orgs/:org/members/:username | _NOT_YET_IMPLEMENTED_
DELETE | /orgs/:org/members/:username | _NOT_YET_IMPLEMENTED_
GET | /orgs/:org/public_members | _NOT_YET_IMPLEMENTED_
GET | /orgs/:org/public_members/:username | _NOT_YET_IMPLEMENTED_
PUT | /orgs/:org/public_members/:username | _NOT_YET_IMPLEMENTED_
DELETE | /orgs/:org/public_members/:username | _NOT_YET_IMPLEMENTED_
GET | /orgs/:org/memberships/:username | _NOT_YET_IMPLEMENTED_
PUT | /orgs/:org/memberships/:username | _NOT_YET_IMPLEMENTED_
DELETE | /orgs/:org/memberships/:username | _NOT_YET_IMPLEMENTED_
GET | /user/memberships/orgs | _NOT_YET_IMPLEMENTED_
GET | /user/memberships/orgs/:org | _NOT_YET_IMPLEMENTED_
PATCH | /user/memberships/orgs/:org | _NOT_YET_IMPLEMENTED_
*/
_debug := gDebug
_version := "0.1.0"
__New(access) {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(access=(" access "))] (version: " this._version ")" ; _DBG_
this.access := access
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(access=(" access "))]" ; _DBG_
return this
}
org_members(org) {
/* ---------------------------------------------------------------------------------------
Method: List all users who are members of an organization.
*/
this.access.url := "/orgs/" org "/members"
json := this.access.get()
return json
}
}
}
class repos {
; ********************************************************************************************************************************
/*
Class: github.repos
Subclass of github. Implementation of API-functionality from https://developer.github.com/v3/repos/
*/
/* Implementation state (https://developer.github.com/v3/repos/)
VERB | URL | Method
---------+------------------------------------------------------+------------------------------------
GET | /user/repos | obj.repos.user_repos()
GET | /users/:username/repos | _NOT_YET_IMPLEMENTED_
GET | /orgs/:org/repos | _NOT_YET_IMPLEMENTED_
GET | /repositories | _NOT_YET_IMPLEMENTED_
POST | /user/repos | _NOT_YET_IMPLEMENTED_
POST | /orgs/:org/repos | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo | _NOT_YET_IMPLEMENTED_
PATCH | /repos/:owner/:repo | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/contributors | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/languages | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/tags | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/branches | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/branches/:branch | _NOT_YET_IMPLEMENTED_
DELETE | /repos/:owner/:repo | _NOT_YET_IMPLEMENTED_
*/
_debug := gDebug
_version := "0.1.0"
__New(access) {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(access=(" access "))] (version: " this._version ")" ; _DBG_
this.access := access
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(access=(" access "))]" ; _DBG_
return this
}
user_repos() {
/* ---------------------------------------------------------------------------------------
Method: List repositories that are accessible to the authenticated user.
*/
this.access.url := "/user/repos"
json := this.access.get()
return json
}
}
class users {
; ********************************************************************************************************************************
/*
Class: users
Subclass of github. Implementation of API-functionality from https://developer.github.com/v3/users/
*/
/* Implementation state (https://developer.github.com/v3/users/)
VERB | URL | Method
---------+------------------------------------------------------+------------------------------------
GET | /users/:username | obj.users.getSingleUser(username)
GET | /user | obj.users.getAuthenticatedUser()
PATCH | /user | _NOT_YET_IMPLEMENTED_
GET | /users | obj.users.all()
*/
_debug := gDebug
_version := "0.1.0"
__New(access) {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(access=(" access "))] (version: " this._version ")" ; _DBG_
this.access := access
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(access=(" access "))]" ; _DBG_
return this
}
all() {
/* ---------------------------------------------------------------------------------------
Method: get all Users
*/
this.access.url := "/users"
json := this.access.get()
return json
}
getSingleUser(username) {
/* ---------------------------------------------------------------------------------------
Method: get a single user given by name
*/
this.access.url := "/users/" username
json := this.access.get()
return json
}
getAuthenticatedUser() {
/* ---------------------------------------------------------------------------------------
Method: get a single user given by name
*/
this.access.url := "/user"
json := this.access.get()
return json
}
updateAuthenticatedUser() {
/* ---------------------------------------------------------------------------------------
Method: get a single user given by name
*/
MsgBox, 16, Not Yet Implemented, %A_ThisFunc% is not yet implemented, 2
return
this.access.url := "/user"
json := this.access.path()
return json
}
}
class misc {
; ********************************************************************************************************************************
/*
Class: misc
Subclass of github. Implementation of API-functionality from https://developer.github.com/v3/misc/
*/
/* Implementation state (https://developer.github.com/v3/misc/)
VERB | URL | Method
---------+------------------------------------------------------+------------------------------------
GET | /emojis | _NOT_YET_IMPLEMENTED_
GET | /gitignore/templates | _NOT_YET_IMPLEMENTED_
GET | /gitignore/templates/:language | _NOT_YET_IMPLEMENTED_
GET | /licenses | _NOT_YET_IMPLEMENTED_
GET | /licenses/:license | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo | _NOT_YET_IMPLEMENTED_
GET | /repos/:owner/:repo/license | _NOT_YET_IMPLEMENTED_
POST | /markdown | _NOT_YET_IMPLEMENTED_
POST | /markdown/raw | obj.misc.markdown_raw(md)
GET | /meta | _NOT_YET_IMPLEMENTED_
GET | /rate_limit | obj.misc.rate_limit()
*/
_debug := gDebug
_version := "0.1.0"
__New(access) {
if (this._debug) ; _DBG_
OutputDebug % ">[" A_ThisFunc "(access=(" access "))] (version: " this._version ")" ; _DBG_
this.access := access
if (this._debug) ; _DBG_
OutputDebug % "<[" A_ThisFunc "(access=(" access "))]" ; _DBG_
return this
}
rate_limit() {
/* ---------------------------------------------------------------------------------------
Method: get the rate_limit (https://developer.github.com/v3/rate_limit/)
*/
this.access.url := "/rate_limit"
json := this.access.get()
return json
}
markdown_raw(md)
{
this.access.url := "/markdown/raw"
json := this.access.post(md,"text/x-markdown" )
return json
}
}
}