github_api 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +78 -59
- data/features/cassettes/repos/assets/delete.yml +52 -0
- data/features/cassettes/repos/assets/edit.yml +65 -0
- data/features/cassettes/repos/assets/get.yml +74 -0
- data/features/cassettes/repos/assets/list.yml +73 -0
- data/features/cassettes/repos/assets/upload.yml +66 -0
- data/features/cassettes/repos/list_org.yml +167 -0
- data/features/cassettes/repos/list_org_instance.yml +300 -0
- data/features/cassettes/repos/releases/create.yml +64 -0
- data/features/cassettes/repos/releases/delete.yml +52 -0
- data/features/cassettes/repos/releases/edit.yml +63 -0
- data/features/cassettes/repos/releases/get.yml +78 -0
- data/features/cassettes/repos/releases/list.yml +81 -0
- data/features/cassettes/search/code.yml +252 -0
- data/features/cassettes/search/code_query.yml +65 -0
- data/features/cassettes/search/issues.yml +616 -170
- data/features/cassettes/search/legacy/email.yml +72 -0
- data/features/cassettes/search/legacy/issues.yml +119 -0
- data/features/cassettes/search/legacy/repos.yml +394 -0
- data/features/cassettes/search/legacy/users.yml +72 -0
- data/features/cassettes/search/legacy/users_keyword.yml +63 -0
- data/features/cassettes/search/repos.yml +375 -364
- data/features/cassettes/search/users.yml +40 -22
- data/features/cassettes/search/users_keyword.yml +51 -56
- data/features/repos.feature +22 -0
- data/features/repos/assets.feature +59 -0
- data/features/repos/releases.feature +58 -0
- data/features/search.feature +24 -13
- data/features/search/legacy.feature +59 -0
- data/features/settings.yml +2 -5
- data/features/step_definitions/github_api_steps.rb +12 -0
- data/lib/github_api/configuration.rb +3 -1
- data/lib/github_api/error.rb +6 -17
- data/lib/github_api/error/unknown_media.rb +18 -0
- data/lib/github_api/params_hash.rb +20 -10
- data/lib/github_api/repos.rb +26 -15
- data/lib/github_api/repos/releases.rb +146 -0
- data/lib/github_api/repos/releases/assets.rb +126 -0
- data/lib/github_api/request.rb +14 -9
- data/lib/github_api/resource.rb +8 -1
- data/lib/github_api/search.rb +68 -27
- data/lib/github_api/search/legacy.rb +94 -0
- data/lib/github_api/ssl_certs/cacert.pem +41 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/version.rb +2 -2
- data/spec/fixtures/repos/asset.json +12 -0
- data/spec/fixtures/repos/assets.json +14 -0
- data/spec/fixtures/repos/release.json +15 -0
- data/spec/fixtures/repos/releases.json +17 -0
- data/spec/fixtures/search/code.json +76 -0
- data/spec/fixtures/search/issues.json +47 -16
- data/spec/fixtures/search/issues_legacy.json +23 -0
- data/spec/fixtures/search/repos.json +39 -0
- data/spec/fixtures/search/{repositories.json → repos_legacy.json} +0 -0
- data/spec/fixtures/search/users.json +15 -19
- data/spec/fixtures/search/users_legacy.json +24 -0
- data/spec/github/configuration_spec.rb +2 -0
- data/spec/github/error/unknown_media_spec.rb +21 -0
- data/spec/github/git_data/references/create_spec.rb +1 -1
- data/spec/github/git_data/references/get_spec.rb +6 -4
- data/spec/github/git_data/references/list_spec.rb +6 -16
- data/spec/github/pagination/iterator/number_spec.rb +2 -2
- data/spec/github/pagination/iterator/sha_spec.rb +2 -2
- data/spec/github/params_hash_spec.rb +6 -0
- data/spec/github/repos/assets/delete_spec.rb +40 -0
- data/spec/github/repos/assets/edit_spec.rb +40 -0
- data/spec/github/repos/assets/get_spec.rb +45 -0
- data/spec/github/repos/assets/list_spec.rb +55 -0
- data/spec/github/repos/assets/upload_spec.rb +44 -0
- data/spec/github/repos/downloads/upload_spec.rb +5 -5
- data/spec/github/repos/releases/create_spec.rb +44 -0
- data/spec/github/repos/releases/delete_spec.rb +40 -0
- data/spec/github/repos/releases/edit_spec.rb +40 -0
- data/spec/github/repos/releases/get_spec.rb +45 -0
- data/spec/github/repos/releases/list_spec.rb +54 -0
- data/spec/github/request/endpoint_spec.rb +1 -3
- data/spec/github/request/request_spec.rb +4 -8
- data/spec/github/request_spec.rb +3 -3
- data/spec/github/response_wrapper_spec.rb +3 -3
- data/spec/github/s3_uploader_spec.rb +2 -3
- data/spec/github/search/code_spec.rb +38 -0
- data/spec/github/search/issues_spec.rb +38 -0
- data/spec/github/search/legacy/email_spec.rb +34 -0
- data/spec/github/search/legacy/issues_spec.rb +39 -0
- data/spec/github/search/legacy/repos_spec.rb +36 -0
- data/spec/github/search/legacy/users_spec.rb +36 -0
- data/spec/github/search/repos_spec.rb +38 -0
- data/spec/github/search/users_spec.rb +38 -0
- data/spec/github/users/get_spec.rb +1 -1
- data/spec/github/validations/presence_spec.rb +2 -5
- data/spec/integration/repos_spec.rb +4 -0
- data/spec/integration/search_spec.rb +12 -0
- metadata +122 -62
- data/features/cassettes/search/email.yml +0 -99
- data/spec/github/search_spec.rb +0 -102
data/README.md
CHANGED
@@ -1,36 +1,41 @@
|
|
1
1
|
# GithubAPI
|
2
2
|
|
3
|
-
[![Gem Version](https://badge.fury.io/rb/github_api.png)]
|
3
|
+
[![Gem Version](https://badge.fury.io/rb/github_api.png)][gem]
|
4
|
+
[![Build Status](https://secure.travis-ci.org/peter-murach/github.png?branch=master)][travis]
|
5
|
+
[![Dependency Status](https://gemnasium.com/peter-murach/github.png?travis)][gemnasium]
|
6
|
+
[![Code Climate](https://codeclimate.com/github/peter-murach/github.png)][codeclimate]
|
7
|
+
[![Coverage Status](https://coveralls.io/repos/peter-murach/github/badge.png?branch=master)][coveralls]
|
4
8
|
|
9
|
+
[gem]: http://badge.fury.io/rb/github_api
|
5
10
|
[travis]: http://travis-ci.org/peter-murach/github
|
6
11
|
[gemnasium]: https://gemnasium.com/peter-murach/github
|
7
12
|
[codeclimate]: https://codeclimate.com/github/peter-murach/github
|
8
13
|
[coveralls]: https://coveralls.io/r/peter-murach/github
|
9
14
|
|
10
|
-
[Wiki](https://github.com/peter-murach/github/wiki) | [RDocs](http://rubydoc.info/github/peter-murach/github/master/frames)
|
15
|
+
[Website](http://peter-murach.github.io/github/) | [Wiki](https://github.com/peter-murach/github/wiki) | [RDocs](http://rubydoc.info/github/peter-murach/github/master/frames)
|
11
16
|
|
12
17
|
A Ruby wrapper for the GitHub REST API v3.
|
13
18
|
|
14
|
-
Supports all the API methods(nearly 200). It's
|
19
|
+
Supports all the API methods (nearly 200). It's built in a modular way. You can either instantiate the whole API wrapper Github.new or use parts of it i.e. Github::Repos.new if working solely with repositories is your main concern.
|
15
20
|
|
16
21
|
## Features
|
17
22
|
|
18
23
|
* Intuitive GitHub API interface navigation. [usage](#usage)
|
19
24
|
* Modular design allows for working with parts of API. [api](#api)
|
20
25
|
* Fully customizable including advanced middleware stack construction. [config](#advanced-configuration)
|
21
|
-
*
|
22
|
-
*
|
23
|
-
* Flexible
|
24
|
-
* Requests pagination with convenient DSL and automatic
|
26
|
+
* It's comprehensive. You can request all GitHub API resources.
|
27
|
+
* Supports OAuth2 authorization. [oauth](#oauth)
|
28
|
+
* Flexible argument parsing. You can write expressive and natural queries. [params](#arguments--parameters)
|
29
|
+
* Requests pagination with convenient DSL and automatic options. [pagination](#pagination)
|
25
30
|
* Easy error handling split for client and server type errors. [error](#error-handling)
|
26
31
|
* Supports multithreaded environment.
|
27
|
-
* Custom media
|
32
|
+
* Custom media type specification through the 'media' parameter. [media](#media-types)
|
28
33
|
* Request results caching (Status: TODO)
|
29
|
-
* Fully tested with test coverage above 90% with over 1,600 specs and
|
34
|
+
* Fully tested with test coverage above 90% with over 1,600 specs and 1000 features. [testing](#testing)
|
30
35
|
|
31
36
|
## Installation
|
32
37
|
|
33
|
-
Install the gem by
|
38
|
+
Install the gem by running
|
34
39
|
|
35
40
|
```ruby
|
36
41
|
gem install github_api
|
@@ -44,7 +49,7 @@ gem "github_api"
|
|
44
49
|
|
45
50
|
## Usage
|
46
51
|
|
47
|
-
To start using the gem you can either perform direct
|
52
|
+
To start using the gem, you can either perform direct calls on `Github`
|
48
53
|
|
49
54
|
```ruby
|
50
55
|
Github.repos.list user: 'wycats'
|
@@ -56,22 +61,22 @@ or create a new client instance
|
|
56
61
|
github = Github.new
|
57
62
|
```
|
58
63
|
|
59
|
-
At this stage you can also supply various configuration parameters, such as
|
64
|
+
At this stage, you can also supply various configuration parameters, such as
|
60
65
|
```
|
61
66
|
adapter # http client used for performing requests
|
62
|
-
auto_pagination # by default
|
67
|
+
auto_pagination # false by default, set to true to traverse requests page links
|
63
68
|
oauth_token # oauth authorization token
|
64
69
|
basic_auth # login:password string
|
65
70
|
client_id # oauth client id
|
66
71
|
client_secret # oauth client secret
|
67
|
-
user # global user used in
|
72
|
+
user # global user used in requests if none provided
|
68
73
|
repo # global repository used in requests in none provided
|
69
|
-
org # global organization used in
|
70
|
-
endpoint # enterprise
|
71
|
-
site # enterprise
|
72
|
-
ssl #
|
73
|
-
per_page # number of items per page
|
74
|
-
user_agent # custom user agent name,
|
74
|
+
org # global organization used in requests if none provided
|
75
|
+
endpoint # enterprise API endpoint
|
76
|
+
site # enterprise API web endpoint
|
77
|
+
ssl # SSL settings
|
78
|
+
per_page # number of items per page- max of 100
|
79
|
+
user_agent # custom user agent name, 'Github API' by default
|
75
80
|
```
|
76
81
|
which are used throughout the API. These can be passed directly as hash options:
|
77
82
|
|
@@ -79,7 +84,7 @@ which are used throughout the API. These can be passed directly as hash options:
|
|
79
84
|
github = Github.new oauth_token: 'token'
|
80
85
|
```
|
81
86
|
|
82
|
-
Alternatively, you can configure the
|
87
|
+
Alternatively, you can configure the GitHub settings by passing a block, for instance, for a custom enterprise endpoint and website like
|
83
88
|
|
84
89
|
```ruby
|
85
90
|
github = Github.new do |config|
|
@@ -91,20 +96,20 @@ github = Github.new do |config|
|
|
91
96
|
end
|
92
97
|
```
|
93
98
|
|
94
|
-
You can authenticate either using OAuth authentication convenience methods(see section
|
99
|
+
You can authenticate either using OAuth authentication convenience methods (see OAuth section) or through basic authentication by passing your login and password credentials
|
95
100
|
|
96
101
|
```ruby
|
97
102
|
github = Github.new login:'peter-murach', password:'...'
|
98
103
|
```
|
99
104
|
|
100
|
-
or
|
105
|
+
or using a convenience method:
|
101
106
|
|
102
107
|
```ruby
|
103
108
|
github = Github.new basic_auth: 'login:password'
|
104
109
|
```
|
105
110
|
|
106
|
-
This gem closely
|
107
|
-
|
111
|
+
This gem closely mirrors the GitHub API hierarchy i.e. if you want to create a download resource,
|
112
|
+
look up the GitHub API spec and issue the request as in `github.repos.downloads.create`
|
108
113
|
|
109
114
|
For example to interact with GitHub Repositories API, issue the following calls that correspond directly to the GitHub API hierarchy
|
110
115
|
|
@@ -121,7 +126,7 @@ blobs = Github::GitData::Blobs.new
|
|
121
126
|
blobs.create 'peter-murach', 'github', content: 'Blob content'
|
122
127
|
```
|
123
128
|
|
124
|
-
The response is of type [
|
129
|
+
The response is of type [Github::ResponseWrapper] which allows traversing all the json response attributes like method calls i.e.
|
125
130
|
|
126
131
|
```ruby
|
127
132
|
repos = Github::Repos.new :user => 'peter-murach', :repo => 'github'
|
@@ -132,14 +137,14 @@ end
|
|
132
137
|
|
133
138
|
## Arguments & Parameters
|
134
139
|
|
135
|
-
The library allows for flexible
|
140
|
+
The library allows for flexible argument parsing. Therefore, arguments can be passed during instance creation:
|
136
141
|
|
137
142
|
```ruby
|
138
143
|
issues = Github::Issues.new user: 'peter-murach', repo: 'github'
|
139
144
|
issues.milestones.list state: 'open'
|
140
145
|
```
|
141
146
|
|
142
|
-
Further, arguments can be passed directly inside method called but then the order of parameters matters and hence please consult the method documentation or GitHub specification. For instance:
|
147
|
+
Further, arguments can be passed directly inside the method called, but then the order of parameters matters and hence please consult the method documentation or GitHub specification. For instance:
|
143
148
|
|
144
149
|
```ruby
|
145
150
|
issues = Github::Issues.new
|
@@ -161,7 +166,7 @@ But why limit ourselves? You can mix and match arguments, for example:
|
|
161
166
|
issues.milestones(repo: 'tty').list
|
162
167
|
```
|
163
168
|
|
164
|
-
|
169
|
+
You can also use a bit of syntactic sugar common among Ruby libraries whereby "username/repository" can be passed as well:
|
165
170
|
|
166
171
|
```ruby
|
167
172
|
issues = Github::Issues.new
|
@@ -169,7 +174,7 @@ Finally, you can use a bit of syntactic sugar common among ruby libraries whereb
|
|
169
174
|
issues.milestones.list 'peter-murach/github'
|
170
175
|
```
|
171
176
|
|
172
|
-
Finally, use `with` scope to clearly denote your requests
|
177
|
+
Finally, use the `with` scope to clearly denote your requests
|
173
178
|
|
174
179
|
```ruby
|
175
180
|
issues = Github::Issues.new
|
@@ -199,7 +204,7 @@ end
|
|
199
204
|
|
200
205
|
## Advanced Configuration
|
201
206
|
|
202
|
-
The `github_api` gem will use the default middleware stack which is exposed by calling `stack` on client instance. However, this stack can be freely modified with methods such as `insert`, `insert_after`, `delete` and `swap`. For instance to add your `CustomMiddleware` do
|
207
|
+
The `github_api` gem will use the default middleware stack which is exposed by calling `stack` on a client instance. However, this stack can be freely modified with methods such as `insert`, `insert_after`, `delete` and `swap`. For instance, to add your `CustomMiddleware` do
|
203
208
|
|
204
209
|
```ruby
|
205
210
|
github = Github.new do |config|
|
@@ -220,6 +225,7 @@ github = Github.new do |config|
|
|
220
225
|
end
|
221
226
|
```
|
222
227
|
|
228
|
+
|
223
229
|
## API
|
224
230
|
|
225
231
|
Main API methods are grouped into the following classes that can be instantiated on their own
|
@@ -232,25 +238,25 @@ Github::Orgs Github::Issues Github::Authorizations
|
|
232
238
|
Github::PullRequests Github::Users Github::Activity
|
233
239
|
```
|
234
240
|
|
235
|
-
Some parts of GitHub API v3 require you to be
|
241
|
+
Some parts of GitHub API v3 require you to be authenticated, for instance the following are examples of APIs only for the authenticated user
|
236
242
|
|
237
243
|
```ruby
|
238
244
|
Github::Users::Emails
|
239
245
|
Github::Users::Keys
|
240
246
|
```
|
241
247
|
|
242
|
-
All method calls form
|
248
|
+
All method calls form Ruby like sentences and allow for intuitive API navigation, for instance
|
243
249
|
|
244
250
|
```ruby
|
245
251
|
github = Github.new :oauth_token => '...'
|
246
252
|
github.users.followers.following 'wycats' # => returns users that 'wycats' is following
|
247
|
-
github.users.followers.following 'wycats' # => returns true if following, otherwise false
|
253
|
+
github.users.followers.following? 'wycats' # => returns true if following, otherwise false
|
248
254
|
```
|
249
255
|
|
250
|
-
For
|
251
|
-
read the rdoc
|
256
|
+
For specifications on all available methods, go to http://developer.github.com/v3/ or
|
257
|
+
read the rdoc. All methods are documented there with examples of usage.
|
252
258
|
|
253
|
-
Alternatively, you can find out
|
259
|
+
Alternatively, you can find out which methods are supported by calling `actions` on a class instance in your `irb`:
|
254
260
|
|
255
261
|
```ruby
|
256
262
|
>> Github::Repos.actions >> github.issues.actions
|
@@ -298,14 +304,14 @@ Once you have your access token, configure your github instance following instru
|
|
298
304
|
|
299
305
|
### Authorizations API
|
300
306
|
|
301
|
-
Alternatively you can use OAuth Authorizations API. For instance, to create access token through GitHub API you required to pass your basic credentials as in the following:
|
307
|
+
Alternatively, you can use the OAuth Authorizations API. For instance, to create an access token through the GitHub API, you are required to pass your basic credentials as in the following:
|
302
308
|
|
303
309
|
```ruby
|
304
310
|
github = Github.new basic_auth: 'login:password'
|
305
311
|
github.oauth.create 'scopes' => ['repo']
|
306
312
|
```
|
307
313
|
|
308
|
-
You can add more than one scope from the `user`, `public_repo`, `repo`, `gist` or leave the scopes parameter out, in which case, the default read-only access will be assumed(includes public user profile info, public repo info, and gists).
|
314
|
+
You can add more than one scope from the `user`, `public_repo`, `repo`, `gist` or leave the scopes parameter out, in which case, the default read-only access will be assumed (includes public user profile info, public repo info, and gists).
|
309
315
|
|
310
316
|
### Scopes
|
311
317
|
|
@@ -316,7 +322,7 @@ You can check OAuth scopes you have by:
|
|
316
322
|
github.scopes.list # => ['repo']
|
317
323
|
```
|
318
324
|
|
319
|
-
To list the scopes that the particular
|
325
|
+
To list the scopes that the particular GitHub API action checks for do:
|
320
326
|
|
321
327
|
```ruby
|
322
328
|
repos = Github::Repos.new
|
@@ -334,7 +340,7 @@ By default requests over SSL are set to OpenSSL::SSL::VERIFY_PEER. However, you
|
|
334
340
|
Github.new ssl: { verify: false }
|
335
341
|
```
|
336
342
|
|
337
|
-
If your client fails to find CA certs you can pass other SSL options to specify exactly how the information is sourced
|
343
|
+
If your client fails to find CA certs, you can pass other SSL options to specify exactly how the information is sourced
|
338
344
|
|
339
345
|
```ruby
|
340
346
|
ssl: {
|
@@ -360,7 +366,7 @@ github.issues.get 'peter-murach', 'github', 108, media: 'text'
|
|
360
366
|
|
361
367
|
This will be expanded into `application/vnd.github.v3.text+json`
|
362
368
|
|
363
|
-
If you wish to specify the version pass `media: 'beta.text'` which will be converted to `application/vnd/github.beta.text+json`.
|
369
|
+
If you wish to specify the version, pass `media: 'beta.text'` which will be converted to `application/vnd/github.beta.text+json`.
|
364
370
|
|
365
371
|
Finally, you can always pass the whole accept header like so
|
366
372
|
|
@@ -368,6 +374,11 @@ Finally, you can always pass the whole accept header like so
|
|
368
374
|
github.issues.get 'peter-murach', 'github', 108, accept: 'application/vnd.github.raw'
|
369
375
|
```
|
370
376
|
|
377
|
+
## Hypermedia
|
378
|
+
|
379
|
+
TODO: explain how it works
|
380
|
+
Github::Resource for each *_url key
|
381
|
+
|
371
382
|
## Configuration
|
372
383
|
|
373
384
|
Certain methods require authentication. To get your GitHub OAuth v2 credentials,
|
@@ -386,10 +397,10 @@ Github.new(:oauth_token => YOUR_OAUTH_TOKEN)
|
|
386
397
|
Github.new(:basic_auth => 'login:password')
|
387
398
|
```
|
388
399
|
|
389
|
-
All parameters can be
|
400
|
+
All parameters can be overwritten each method call by passing a parameters hash.
|
390
401
|
|
391
402
|
|
392
|
-
By default no caching will be performed. In order to set the cache do... If no cache type is provided a default memoization is done.
|
403
|
+
By default, no caching will be performed. In order to set the cache do... If no cache type is provided, a default memoization is done.
|
393
404
|
|
394
405
|
## Pagination
|
395
406
|
|
@@ -400,7 +411,7 @@ repos = Github::Repos.new
|
|
400
411
|
repos.list user: 'wycats', per_page: 10, page: 5
|
401
412
|
```
|
402
413
|
|
403
|
-
Then you can query pagination information included in the link header by:
|
414
|
+
Then you can query the pagination information included in the link header by:
|
404
415
|
|
405
416
|
```ruby
|
406
417
|
res.links.first # Shows the URL of the first page of results.
|
@@ -428,21 +439,21 @@ while res.has_next_page?
|
|
428
439
|
end
|
429
440
|
```
|
430
441
|
|
431
|
-
Alternatively, you can retrieve all pages in one invocation by passing `auto_pagination` option like so:
|
442
|
+
Alternatively, you can retrieve all pages in one invocation by passing the `auto_pagination` option like so:
|
432
443
|
|
433
444
|
```ruby
|
434
445
|
github = Github.new auto_pagination: true
|
435
446
|
```
|
436
447
|
|
437
|
-
Depending at what stage you pass the `auto_pagination` it will affect all or only single request:
|
448
|
+
Depending at what stage you pass the `auto_pagination` it will affect all or only a single request:
|
438
449
|
|
439
450
|
```ruby
|
440
451
|
Github::Repos.new auto_pagination: true # affects Repos part of API
|
441
452
|
|
442
|
-
Github::Repos.new.list user: '...', auto_pagination: true # affects single request
|
453
|
+
Github::Repos.new.list user: '...', auto_pagination: true # affects a single request
|
443
454
|
```
|
444
455
|
|
445
|
-
One can also navigate straight to specific page by:
|
456
|
+
One can also navigate straight to the specific page by:
|
446
457
|
|
447
458
|
```ruby
|
448
459
|
res.count_pages # Number of pages
|
@@ -453,9 +464,17 @@ res.prev_page # Get previous page
|
|
453
464
|
res.last_page # Get last page
|
454
465
|
```
|
455
466
|
|
467
|
+
### Caching
|
468
|
+
|
469
|
+
TODO: explaing how to add faraday-cache midlleware
|
470
|
+
|
471
|
+
### Debugging requests
|
472
|
+
|
473
|
+
run with ENV['DEBUG'] flag or include middleware by passing `debug` flag
|
474
|
+
|
456
475
|
## Error Handling
|
457
476
|
|
458
|
-
The generic error class `Github::Error::GithubError` will handle both the client(`Github::Error::ClientError`) and service(`Github::Error::ServiceError`) side errors. For instance in your code you can catch
|
477
|
+
The generic error class `Github::Error::GithubError` will handle both the client (`Github::Error::ClientError`) and service (`Github::Error::ServiceError`) side errors. For instance in your code you can catch errors like
|
459
478
|
|
460
479
|
```ruby
|
461
480
|
begin
|
@@ -473,7 +492,7 @@ end
|
|
473
492
|
|
474
493
|
## Response Message
|
475
494
|
|
476
|
-
Each response comes packaged with methods allowing for inspection of HTTP start line and headers. For example to check for rate limits and status
|
495
|
+
Each response comes packaged with methods allowing for inspection of HTTP start line and headers. For example, to check for rate limits and status codes, call
|
477
496
|
|
478
497
|
```ruby
|
479
498
|
res = Github::Repos.new.branches 'peter-murach', 'github'
|
@@ -487,7 +506,7 @@ res.headers.cache_control # "public, max-age=60, s-maxage=60"
|
|
487
506
|
|
488
507
|
## Examples
|
489
508
|
|
490
|
-
Some
|
509
|
+
Some API methods require input parameters. These are simply added as a hash of properties, for instance
|
491
510
|
|
492
511
|
```ruby
|
493
512
|
issues = Github::Issues.new user:'peter-murach', repo: 'github-api'
|
@@ -501,7 +520,7 @@ users = Github::Users.new oauth_token: 'token'
|
|
501
520
|
users.emails.add 'email1', 'email2', ..., 'emailn' # => Adds emails to the authenticated user
|
502
521
|
```
|
503
522
|
|
504
|
-
If a method returns a collection, you can
|
523
|
+
If a method returns a collection, you can iterate over it by supplying a block parameter,
|
505
524
|
|
506
525
|
```ruby
|
507
526
|
events = Github::Activity::Events.new
|
@@ -510,16 +529,16 @@ events.public do |event|
|
|
510
529
|
end
|
511
530
|
```
|
512
531
|
|
513
|
-
Query requests instead of
|
532
|
+
Query requests return boolean values instead of HTTP responses
|
514
533
|
|
515
534
|
```ruby
|
516
535
|
github = Github.new
|
517
|
-
github.orgs.members.
|
536
|
+
github.orgs.members.member? 'github', 'technoweenie', public: true # => true
|
518
537
|
```
|
519
538
|
|
520
539
|
## Rails Example
|
521
540
|
|
522
|
-
A Rails controller that allows a user to authorize their GitHub account and then
|
541
|
+
A Rails controller that allows a user to authorize their GitHub account and then performs a request.
|
523
542
|
|
524
543
|
```ruby
|
525
544
|
class GithubController < ApplicationController
|
@@ -543,11 +562,11 @@ end
|
|
543
562
|
|
544
563
|
## Testing
|
545
564
|
|
546
|
-
The test suite is split into two groups `live` and `mock`.
|
565
|
+
The test suite is split into two groups, `live` and `mock`.
|
547
566
|
|
548
|
-
The `live` tests are the ones in `features` folder and they simply exercise the GitHub API by making live requests and then being cached with VCR in directory named `features\cassettes`. For details on how to get
|
567
|
+
The `live` tests are the ones in `features` folder and they simply exercise the GitHub API by making live requests and then being cached with VCR in directory named `features\cassettes`. For details on how to get set up, please navigate to the `features` folder.
|
549
568
|
|
550
|
-
The `mock` tests are in `spec` directory and their primary concern is to test the gem internals without the hindrance of external calls.
|
569
|
+
The `mock` tests are in the `spec` directory and their primary concern is to test the gem internals without the hindrance of external calls.
|
551
570
|
|
552
571
|
## Development
|
553
572
|
|
@@ -0,0 +1,52 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: delete
|
5
|
+
uri: https://<BASIC_AUTH>@api.github.com/repos/<USER>/github_api_test/releases/assets/46073?access_token=<TOKEN>
|
6
|
+
body:
|
7
|
+
encoding: US-ASCII
|
8
|
+
string: ""
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1
|
12
|
+
Accept-Charset:
|
13
|
+
- utf-8
|
14
|
+
User-Agent:
|
15
|
+
- Github Ruby Gem 0.10.2
|
16
|
+
response:
|
17
|
+
status:
|
18
|
+
code: 204
|
19
|
+
message: No Content
|
20
|
+
headers:
|
21
|
+
Server:
|
22
|
+
- GitHub.com
|
23
|
+
Date:
|
24
|
+
- Sat, 07 Dec 2013 21:27:04 GMT
|
25
|
+
Status:
|
26
|
+
- 204 No Content
|
27
|
+
X-Ratelimit-Limit:
|
28
|
+
- "5000"
|
29
|
+
X-Ratelimit-Remaining:
|
30
|
+
- "4990"
|
31
|
+
X-Ratelimit-Reset:
|
32
|
+
- "1386451969"
|
33
|
+
X-Github-Media-Type:
|
34
|
+
- github.v3; format=json
|
35
|
+
X-Content-Type-Options:
|
36
|
+
- nosniff
|
37
|
+
Access-Control-Allow-Credentials:
|
38
|
+
- "true"
|
39
|
+
Access-Control-Expose-Headers:
|
40
|
+
- ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
41
|
+
Access-Control-Allow-Origin:
|
42
|
+
- "*"
|
43
|
+
X-Github-Request-Id:
|
44
|
+
- 4D649864:2A9D:172CB9E:52A392A8
|
45
|
+
Vary:
|
46
|
+
- Accept-Encoding
|
47
|
+
body:
|
48
|
+
encoding: US-ASCII
|
49
|
+
string: ""
|
50
|
+
http_version:
|
51
|
+
recorded_at: Sat, 07 Dec 2013 21:27:04 GMT
|
52
|
+
recorded_with: VCR 2.6.0
|
@@ -0,0 +1,65 @@
|
|
1
|
+
---
|
2
|
+
http_interactions:
|
3
|
+
- request:
|
4
|
+
method: patch
|
5
|
+
uri: https://<BASIC_AUTH>@api.github.com/repos/murek/github_api_test/releases/assets/46084?access_token=<TOKEN>
|
6
|
+
body:
|
7
|
+
encoding: UTF-8
|
8
|
+
string: "{\"name\":\"Rake\",\"label\":\"Ruby code\"}"
|
9
|
+
headers:
|
10
|
+
Accept:
|
11
|
+
- application/vnd.github.v3+json,application/vnd.github.beta+json;q=0.5,application/json;q=0.1
|
12
|
+
Accept-Charset:
|
13
|
+
- utf-8
|
14
|
+
User-Agent:
|
15
|
+
- Github Ruby Gem 0.10.2
|
16
|
+
Content-Type:
|
17
|
+
- application/json
|
18
|
+
response:
|
19
|
+
status:
|
20
|
+
code: 200
|
21
|
+
message: OK
|
22
|
+
headers:
|
23
|
+
Server:
|
24
|
+
- GitHub.com
|
25
|
+
Date:
|
26
|
+
- Sat, 07 Dec 2013 21:16:20 GMT
|
27
|
+
Content-Type:
|
28
|
+
- application/json; charset=utf-8
|
29
|
+
Status:
|
30
|
+
- 200 OK
|
31
|
+
X-Ratelimit-Limit:
|
32
|
+
- "5000"
|
33
|
+
X-Ratelimit-Remaining:
|
34
|
+
- "4991"
|
35
|
+
X-Ratelimit-Reset:
|
36
|
+
- "1386451969"
|
37
|
+
Cache-Control:
|
38
|
+
- private, max-age=60, s-maxage=60
|
39
|
+
Last-Modified:
|
40
|
+
- Sat, 07 Dec 2013 21:16:20 GMT
|
41
|
+
Etag:
|
42
|
+
- "\"00bde8b488647e7a3b3ba20a812788e6\""
|
43
|
+
Vary:
|
44
|
+
- Accept, Authorization, Cookie, X-GitHub-OTP
|
45
|
+
- Accept-Encoding
|
46
|
+
X-Github-Media-Type:
|
47
|
+
- github.v3; format=json
|
48
|
+
X-Content-Type-Options:
|
49
|
+
- nosniff
|
50
|
+
Content-Length:
|
51
|
+
- "290"
|
52
|
+
Access-Control-Allow-Credentials:
|
53
|
+
- "true"
|
54
|
+
Access-Control-Expose-Headers:
|
55
|
+
- ETag, Link, X-RateLimit-Limit, X-RateLimit-Remaining, X-RateLimit-Reset, X-OAuth-Scopes, X-Accepted-OAuth-Scopes, X-Poll-Interval
|
56
|
+
Access-Control-Allow-Origin:
|
57
|
+
- "*"
|
58
|
+
X-Github-Request-Id:
|
59
|
+
- 4D649864:70CB:1D9EC01:52A39023
|
60
|
+
body:
|
61
|
+
encoding: US-ASCII
|
62
|
+
string: "{\"url\":\"https://api.github.com/repos/murek/github_api_test/releases/assets/46084\",\"id\":46084,\"name\":\"Rake\",\"label\":\"Ruby code\",\"content_type\":\"application/octet-stream\",\"state\":\"uploaded\",\"size\":333,\"download_count\":0,\"created_at\":\"2013-12-07T21:00:29Z\",\"updated_at\":\"2013-12-07T21:16:20Z\"}"
|
63
|
+
http_version:
|
64
|
+
recorded_at: Sat, 07 Dec 2013 21:16:20 GMT
|
65
|
+
recorded_with: VCR 2.6.0
|