octodoggy 4.6.2

Sign up to get free protection for your applications and to get access to all the features.
Files changed (79) hide show
  1. checksums.yaml +7 -0
  2. data/.document +5 -0
  3. data/CONTRIBUTING.md +22 -0
  4. data/LICENSE.md +20 -0
  5. data/README.md +714 -0
  6. data/Rakefile +22 -0
  7. data/lib/ext/sawyer/relation.rb +10 -0
  8. data/lib/octokit.rb +59 -0
  9. data/lib/octokit/arguments.rb +14 -0
  10. data/lib/octokit/authentication.rb +82 -0
  11. data/lib/octokit/client.rb +238 -0
  12. data/lib/octokit/client/authorizations.rb +244 -0
  13. data/lib/octokit/client/commit_comments.rb +95 -0
  14. data/lib/octokit/client/commits.rb +239 -0
  15. data/lib/octokit/client/contents.rb +162 -0
  16. data/lib/octokit/client/deployments.rb +62 -0
  17. data/lib/octokit/client/downloads.rb +50 -0
  18. data/lib/octokit/client/emojis.rb +18 -0
  19. data/lib/octokit/client/events.rb +151 -0
  20. data/lib/octokit/client/feeds.rb +33 -0
  21. data/lib/octokit/client/gists.rb +233 -0
  22. data/lib/octokit/client/gitignore.rb +43 -0
  23. data/lib/octokit/client/hooks.rb +297 -0
  24. data/lib/octokit/client/integrations.rb +77 -0
  25. data/lib/octokit/client/issues.rb +321 -0
  26. data/lib/octokit/client/labels.rb +156 -0
  27. data/lib/octokit/client/legacy_search.rb +42 -0
  28. data/lib/octokit/client/licenses.rb +45 -0
  29. data/lib/octokit/client/markdown.rb +27 -0
  30. data/lib/octokit/client/meta.rb +21 -0
  31. data/lib/octokit/client/milestones.rb +87 -0
  32. data/lib/octokit/client/notifications.rb +171 -0
  33. data/lib/octokit/client/objects.rb +141 -0
  34. data/lib/octokit/client/organizations.rb +768 -0
  35. data/lib/octokit/client/pages.rb +63 -0
  36. data/lib/octokit/client/projects.rb +314 -0
  37. data/lib/octokit/client/pub_sub_hubbub.rb +111 -0
  38. data/lib/octokit/client/pull_requests.rb +301 -0
  39. data/lib/octokit/client/rate_limit.rb +54 -0
  40. data/lib/octokit/client/reactions.rb +158 -0
  41. data/lib/octokit/client/refs.rb +118 -0
  42. data/lib/octokit/client/releases.rb +163 -0
  43. data/lib/octokit/client/repositories.rb +654 -0
  44. data/lib/octokit/client/repository_invitations.rb +103 -0
  45. data/lib/octokit/client/reviews.rb +174 -0
  46. data/lib/octokit/client/say.rb +19 -0
  47. data/lib/octokit/client/search.rb +76 -0
  48. data/lib/octokit/client/service_status.rb +38 -0
  49. data/lib/octokit/client/source_import.rb +161 -0
  50. data/lib/octokit/client/stats.rb +105 -0
  51. data/lib/octokit/client/statuses.rb +47 -0
  52. data/lib/octokit/client/traffic.rb +69 -0
  53. data/lib/octokit/client/users.rb +354 -0
  54. data/lib/octokit/configurable.rb +147 -0
  55. data/lib/octokit/connection.rb +199 -0
  56. data/lib/octokit/default.rb +166 -0
  57. data/lib/octokit/enterprise_admin_client.rb +40 -0
  58. data/lib/octokit/enterprise_admin_client/admin_stats.rb +120 -0
  59. data/lib/octokit/enterprise_admin_client/license.rb +18 -0
  60. data/lib/octokit/enterprise_admin_client/orgs.rb +27 -0
  61. data/lib/octokit/enterprise_admin_client/search_indexing.rb +83 -0
  62. data/lib/octokit/enterprise_admin_client/users.rb +128 -0
  63. data/lib/octokit/enterprise_management_console_client.rb +50 -0
  64. data/lib/octokit/enterprise_management_console_client/management_console.rb +176 -0
  65. data/lib/octokit/error.rb +286 -0
  66. data/lib/octokit/gist.rb +36 -0
  67. data/lib/octokit/middleware/follow_redirects.rb +131 -0
  68. data/lib/octokit/organization.rb +17 -0
  69. data/lib/octokit/preview.rb +38 -0
  70. data/lib/octokit/rate_limit.rb +33 -0
  71. data/lib/octokit/repo_arguments.rb +19 -0
  72. data/lib/octokit/repository.rb +93 -0
  73. data/lib/octokit/response/feed_parser.rb +21 -0
  74. data/lib/octokit/response/raise_error.rb +21 -0
  75. data/lib/octokit/user.rb +19 -0
  76. data/lib/octokit/version.rb +17 -0
  77. data/lib/octokit/warnable.rb +17 -0
  78. data/octokit.gemspec +22 -0
  79. metadata +160 -0
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: bcef9f7106fa94108123753ce579f3b39fae1a88
4
+ data.tar.gz: aa7f4b953b1b8ecbc8824ae77310a5b0f1f928f5
5
+ SHA512:
6
+ metadata.gz: 03b690127a6d7d046b55f943018393a00418e705079b9d50e1951115e3d06a78808cbf6491daa028419670e2decb96e34e61ae333dd07c8fa164fbc68ebeffe7
7
+ data.tar.gz: fe06496f64bb601c45fdefbd6c2fbb9ce4286b21109e5d28ea18e5f51eff661285090b3b921ce0c9b23f1d204fbcd2c10b01d8c2f734c5ddff7033090388d28f
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ features/**/*.feature
4
+ -
5
+ LICENSE.md
@@ -0,0 +1,22 @@
1
+ ## Submitting a Pull Request
2
+
3
+ 0. Check out Hacking on Octokit in the README guide for
4
+ bootstrapping the project for local development.
5
+ 1. [Fork the repository.][fork]
6
+ 2. [Create a topic branch.][branch]
7
+ 3. Add specs for your unimplemented feature or bug fix.
8
+ 4. Run `script/test`. If your specs pass, return to step 3.
9
+ 5. Implement your feature or bug fix.
10
+ 6. Run `script/test`. If your specs fail, return to step 5.
11
+ 7. Run `open coverage/index.html`. If your changes are not completely covered
12
+ by your tests, return to step 4.
13
+ 8. Add documentation for your feature or bug fix.
14
+ 9. Run `bundle exec rake doc:yard`. If your changes are not 100% documented, go
15
+ back to step 8.
16
+ 10. Add, commit, and push your changes. For documentation-only fixes, please
17
+ add "[ci skip]" to your commit message to avoid needless CI builds.
18
+ 11. [Submit a pull request.][pr]
19
+
20
+ [fork]: https://help.github.com/articles/fork-a-repo
21
+ [branch]: https://help.github.com/articles/creating-and-deleting-branches-within-your-repository/
22
+ [pr]: https://help.github.com/articles/using-pull-requests
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009-2016 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,714 @@
1
+ # Octokit
2
+
3
+ Ruby toolkit for the GitHub API.
4
+
5
+ ![logo](http://cl.ly/image/3Y013H0A2z3z/gundam-ruby.png)
6
+
7
+ Upgrading? Check the [Upgrade Guide](#upgrading-guide) before bumping to a new
8
+ [major version][semver].
9
+
10
+ ## Table of Contents
11
+
12
+ 1. [Philosophy](#philosophy)
13
+ 2. [Quick start](#quick-start)
14
+ 3. [Making requests](#making-requests)
15
+ 4. [Consuming resources](#consuming-resources)
16
+ 5. [Accessing HTTP responses](#accessing-http-responses)
17
+ 6. [Authentication](#authentication)
18
+ 1. [Basic Authentication](#basic-authentication)
19
+ 2. [OAuth access tokens](#oauth-access-tokens)
20
+ 3. [Two-Factor Authentication](#two-factor-authentication)
21
+ 4. [Using a .netrc file](#using-a-netrc-file)
22
+ 5. [Application authentication](#application-authentication)
23
+ 7. [Pagination](#pagination)
24
+ 1. [Auto pagination](#auto-pagination)
25
+ 8. [Working with GitHub Enterprise](#working-with-github-enterprise)
26
+ 1. [Interacting with the GitHub.com APIs in GitHub Enterprise](#interacting-with-the-githubcom-apis-in-github-enterprise)
27
+ 2. [Interacting with the GitHub Enterprise Admin APIs](#interacting-with-the-github-enterprise-admin-apis)
28
+ 3. [Interacting with the GitHub Enterprise Management Console APIs](#interacting-with-the-github-enterprise-management-console-apis)
29
+ 9. [SSL Connection Errors](#ssl-connection-errors)
30
+ 10. [Configuration and defaults](#configuration-and-defaults)
31
+ 1. [Configuring module defaults](#configuring-module-defaults)
32
+ 2. [Using ENV variables](#using-env-variables)
33
+ 11. [Hypermedia agent](#hypermedia-agent)
34
+ 1. [Hypermedia in Octokit](#hypermedia-in-octokit)
35
+ 2. [URI templates](#uri-templates)
36
+ 3. [The Full Hypermedia Experience™](#the-full-hypermedia-experience)
37
+ 12. [Upgrading guide](#upgrading-guide)
38
+ 1. [Upgrading from 1.x.x](#upgrading-from-1xx)
39
+ 13. [Advanced usage](#advanced-usage)
40
+ 1. [Debugging](#debugging)
41
+ 2. [Caching](#caching)
42
+ 14. [Hacking on Octokit.rb](#hacking-on-octokitrb)
43
+ 1. [Running and writing new tests](#running-and-writing-new-tests)
44
+ 15. [Supported Ruby Versions](#supported-ruby-versions)
45
+ 16. [Versioning](#versioning)
46
+ 17. [License](#license)
47
+
48
+ ## Philosophy
49
+
50
+ API wrappers [should reflect the idioms of the language in which they were
51
+ written][wrappers]. Octokit.rb wraps the [GitHub API][github-api] in a flat API
52
+ client that follows Ruby conventions and requires little knowledge of REST.
53
+ Most methods have positional arguments for required input and an options hash
54
+ for optional parameters, headers, or other options:
55
+
56
+ ```ruby
57
+ # Fetch a README with Accept header for HTML format
58
+ Octokit.readme 'al3x/sovereign', :accept => 'application/vnd.github.html'
59
+ ```
60
+
61
+
62
+ [wrappers]: http://wynnnetherland.com/journal/what-makes-a-good-api-wrapper
63
+ [github-api]: http://developer.github.com
64
+
65
+ ## Quick start
66
+
67
+ Install via Rubygems
68
+
69
+ gem install octokit
70
+
71
+ ... or add to your Gemfile
72
+
73
+ gem "octokit", "~> 4.0"
74
+
75
+ ### Making requests
76
+
77
+ [API methods][] are available as module methods (consuming module-level
78
+ configuration) or as client instance methods.
79
+
80
+ ```ruby
81
+ # Provide authentication credentials
82
+ Octokit.configure do |c|
83
+ c.login = 'defunkt'
84
+ c.password = 'c0d3b4ssssss!'
85
+ end
86
+
87
+ # Fetch the current user
88
+ Octokit.user
89
+ ```
90
+ or
91
+
92
+ ```ruby
93
+ # Provide authentication credentials
94
+ client = Octokit::Client.new(:login => 'defunkt', :password => 'c0d3b4ssssss!')
95
+ # Fetch the current user
96
+ client.user
97
+ ```
98
+
99
+ [API methods]: http://octokit.github.io/octokit.rb/method_list.html
100
+
101
+ ### Consuming resources
102
+
103
+ Most methods return a `Resource` object which provides dot notation and `[]`
104
+ access for fields returned in the API response.
105
+
106
+ ```ruby
107
+ # Fetch a user
108
+ user = Octokit.user 'jbarnette'
109
+ puts user.name
110
+ # => "John Barnette"
111
+ puts user.fields
112
+ # => <Set: {:login, :id, :gravatar_id, :type, :name, :company, :blog, :location, :email, :hireable, :bio, :public_repos, :followers, :following, :created_at, :updated_at, :public_gists}>
113
+ puts user[:company]
114
+ # => "GitHub"
115
+ user.rels[:gists].href
116
+ # => "https://api.github.com/users/jbarnette/gists"
117
+ ```
118
+
119
+ **Note:** URL fields are culled into a separate `.rels` collection for easier
120
+ [Hypermedia](#hypermedia-agent) support.
121
+
122
+ ### Accessing HTTP responses
123
+
124
+ While most methods return a `Resource` object or a Boolean, sometimes you may
125
+ need access to the raw HTTP response headers. You can access the last HTTP
126
+ response with `Client#last_response`:
127
+
128
+ ```ruby
129
+ user = Octokit.user 'andrewpthorp'
130
+ response = Octokit.last_response
131
+ etag = response.headers[:etag]
132
+ ```
133
+
134
+ ## Authentication
135
+
136
+ Octokit supports the various [authentication methods supported by the GitHub
137
+ API][auth]:
138
+
139
+ ### Basic Authentication
140
+
141
+ Using your GitHub username and password is the easiest way to get started
142
+ making authenticated requests:
143
+
144
+ ```ruby
145
+ client = Octokit::Client.new \
146
+ :login => 'defunkt',
147
+ :password => 'c0d3b4ssssss!'
148
+
149
+ user = client.user
150
+ user.login
151
+ # => "defunkt"
152
+ ```
153
+ While Basic Authentication allows you to get started quickly, OAuth access
154
+ tokens are the preferred way to authenticate on behalf of users.
155
+
156
+ ### OAuth access tokens
157
+
158
+ [OAuth access tokens][oauth] provide two main benefits over using your username
159
+ and password:
160
+
161
+ * **Revokable access**. Access tokens can be revoked, removing access for only
162
+ that token without having to change your password everywhere.
163
+ * **Limited access**. Access tokens have [access scopes][] which allow for more
164
+ granular access to API resources. For instance, you can grant a third party
165
+ access to your gists but not your private repositories.
166
+
167
+ To use an access token with the Octokit client, pass your token in the
168
+ `:access_token` options parameter in lieu of your username and password:
169
+
170
+ ```ruby
171
+ client = Octokit::Client.new(:access_token => "<your 40 char token>")
172
+
173
+ user = client.user
174
+ user.login
175
+ # => "defunkt"
176
+ ```
177
+
178
+ You can [create access tokens through your GitHub Account Settings](https://help.github.com/articles/creating-an-access-token-for-command-line-use)
179
+ or with a basic authenticated Octokit client:
180
+
181
+ ```ruby
182
+ client = Octokit::Client.new \
183
+ :login => 'defunkt',
184
+ :password => 'c0d3b4ssssss!'
185
+
186
+ client.create_authorization(:scopes => ["user"], :note => "Name of token")
187
+ # => <your new oauth token>
188
+ ```
189
+
190
+ ### Two-Factor Authentication
191
+
192
+ [Two-Factor Authentication](https://help.github.com/articles/about-two-factor-authentication) brings added security to the account by requiring more information to login.
193
+
194
+ Using two-factor authentication for API calls is as simple as adding the [required header](http://developer.github.com/v3/auth/#working-with-two-factor-authentication) as an option:
195
+
196
+ ```ruby
197
+ client = Octokit::Client.new \
198
+ :login => 'defunkt',
199
+ :password => 'c0d3b4ssssss!'
200
+
201
+ user = client.user("defunkt", :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
202
+ ```
203
+
204
+ As you can imagine, this gets annoying quick since two-factor auth tokens are very short lived. So it is recommended to create an oauth token for the user to communicate with the API:
205
+
206
+ ```ruby
207
+ client = Octokit::Client.new \
208
+ :login => 'defunkt',
209
+ :password => 'c0d3b4ssssss!'
210
+
211
+ client.create_authorization(:scopes => ["user"], :note => "Name of token",
212
+ :headers => { "X-GitHub-OTP" => "<your 2FA token>" })
213
+ # => <your new oauth token>
214
+ ```
215
+
216
+ ### Using a .netrc file
217
+
218
+ Octokit supports reading credentials from a netrc file (defaulting to
219
+ `~/.netrc`). Given these lines in your netrc:
220
+
221
+ ```
222
+ machine api.github.com
223
+ login defunkt
224
+ password c0d3b4ssssss!
225
+ ```
226
+ You can now create a client with those credentials:
227
+
228
+ ```ruby
229
+ client = Octokit::Client.new(:netrc => true)
230
+ client.login
231
+ # => "defunkt"
232
+ ```
233
+ But _I want to use OAuth_ you say. Since the GitHub API supports using an OAuth
234
+ token as a Basic password, you totally can:
235
+
236
+ ```
237
+ machine api.github.com
238
+ login defunkt
239
+ password <your 40 char token>
240
+ ```
241
+
242
+ **Note:** Support for netrc requires adding the [netrc gem][] to your Gemfile
243
+ or `.gemspec`.
244
+
245
+ ### Application authentication
246
+
247
+ Octokit also supports application-only authentication [using OAuth application client
248
+ credentials][app-creds]. Using application credentials will result in making
249
+ anonymous API calls on behalf of an application in order to take advantage of
250
+ the higher rate limit.
251
+
252
+ ```ruby
253
+ client = Octokit::Client.new \
254
+ :client_id => "<your 20 char id>",
255
+ :client_secret => "<your 40 char secret>"
256
+
257
+ user = client.user 'defunkt'
258
+ ```
259
+
260
+ [auth]: http://developer.github.com/v3/#authentication
261
+ [oauth]: http://developer.github.com/v3/oauth/
262
+ [access scopes]: http://developer.github.com/v3/oauth/#scopes
263
+ [app-creds]: http://developer.github.com/v3/#increasing-the-unauthenticated-rate-limit-for-oauth-applications
264
+
265
+ ## Pagination
266
+
267
+ Many GitHub API resources are [paginated][]. While you may be tempted to start
268
+ adding `:page` parameters to your calls, the API returns links to the next,
269
+ previous, and last pages for you in the `Link` response header as [Hypermedia
270
+ link relations](#hypermedia-agent).
271
+
272
+ ```ruby
273
+ issues = Octokit.issues 'rails/rails', :per_page => 100
274
+ issues.concat Octokit.last_response.rels[:next].get.data
275
+ ```
276
+
277
+ ### Auto pagination
278
+
279
+ For smallish resource lists, Octokit provides auto pagination. When this is
280
+ enabled, calls for paginated resources will fetch and concatenate the results
281
+ from every page into a single array:
282
+
283
+ ```ruby
284
+ Octokit.auto_paginate = true
285
+ issues = Octokit.issues 'rails/rails'
286
+ issues.length
287
+
288
+ # => 702
289
+ ```
290
+
291
+ **Note:** While Octokit auto pagination will set the page size to the maximum
292
+ `100`, and seek to not overstep your rate limit, you probably want to use a
293
+ custom pattern for traversing large lists.
294
+
295
+ [paginated]: http://developer.github.com/v3/#pagination
296
+
297
+ ## Working with GitHub Enterprise
298
+
299
+ With a bit of setup, you can also use Octokit with your Github Enterprise instance.
300
+
301
+ ### Interacting with the GitHub.com APIs in GitHub Enterprise
302
+
303
+ To interact with the "regular" GitHub.com APIs in GitHub Enterprise, simply configure the `api_endpoint` to match your hostname. For example:
304
+
305
+ ``` ruby
306
+ Octokit.configure do |c|
307
+ c.api_endpoint = "https://<hostname>/api/v3/"
308
+ end
309
+ client = Octokit::Client.new(:access_token => "<your 40 char token>")
310
+ ```
311
+
312
+ ### Interacting with the GitHub Enterprise Admin APIs
313
+
314
+ The GitHub Enterprise Admin APIs are under a different client: `EnterpriseAdminClient`. You'll need to have an administrator account in order to use these APIs.
315
+
316
+ ``` ruby
317
+ admin_client = Octokit::EnterpriseAdminClient.new \
318
+ :access_token => "<your 40 char token>",
319
+ :api_endpoint => "https://<hostname>/api/v3/"
320
+
321
+ # or
322
+ Octokit.configure do |c|
323
+ c.api_endpoint = "https://<hostname>/api/v3/"
324
+ c.access_token = "<your 40 char token>"
325
+ end
326
+ admin_client = Octokit.enterprise_admin_client
327
+ ```
328
+
329
+ ### Interacting with the GitHub Enterprise Management Console APIs
330
+
331
+ The GitHub Enterprise Management Console APIs are also under a separate client: `EnterpriseManagementConsoleClient`. In order to use it, you'll need to provide both your management console password as well as the endpoint to your management console. This is different than the API endpoint provided above.
332
+
333
+ ``` ruby
334
+ management_console_client = Octokit::EnterpriseManagementConsoleClient.new \
335
+ :management_console_password => "secret",
336
+ :management_console_endpoint = "https://hostname:8633"
337
+ # or
338
+ Octokit.configure do |c|
339
+ c.management_console_endpoint = "https://hostname:8633"
340
+ c.management_console_password = "secret"
341
+ end
342
+ management_console_client = Octokit.enterprise_management_console_client
343
+ ```
344
+
345
+ ### SSL Connection Errors
346
+
347
+ You *may* need to disable SSL temporarily while first setting up your GitHub Enterprise install. You can do that with the following configuration:
348
+
349
+ ``` ruby
350
+ client.connection_options[:ssl] = { :verify => false }
351
+ ```
352
+
353
+ Do remember to turn `:verify` back to `true`, as it's important for secure communication.
354
+
355
+ ## Configuration and defaults
356
+
357
+ While `Octokit::Client` accepts a range of options when creating a new client
358
+ instance, Octokit's configuration API allows you to set your configuration
359
+ options at the module level. This is particularly handy if you're creating a
360
+ number of client instances based on some shared defaults. Changing options
361
+ affects new instances only and will not modify existing `Octokit::Client`
362
+ instances created with previous options.
363
+
364
+ ### Configuring module defaults
365
+
366
+ Every writable attribute in {Octokit::Configurable} can be set one at a time:
367
+
368
+ ```ruby
369
+ Octokit.api_endpoint = 'http://api.github.dev'
370
+ Octokit.web_endpoint = 'http://github.dev'
371
+ ```
372
+
373
+ or in batch:
374
+
375
+ ```ruby
376
+ Octokit.configure do |c|
377
+ c.api_endpoint = 'http://api.github.dev'
378
+ c.web_endpoint = 'http://github.dev'
379
+ end
380
+ ```
381
+
382
+ ### Using ENV variables
383
+
384
+ Default configuration values are specified in {Octokit::Default}. Many
385
+ attributes will look for a default value from the ENV before returning
386
+ Octokit's default.
387
+
388
+ ```ruby
389
+ # Given $OCTOKIT_API_ENDPOINT is "http://api.github.dev"
390
+ Octokit.api_endpoint
391
+
392
+ # => "http://api.github.dev"
393
+ ```
394
+
395
+ Deprecation warnings and API endpoints in development preview warnings are
396
+ printed to STDOUT by default, these can be disabled by setting the ENV
397
+ `OCTOKIT_SILENT=true`.
398
+
399
+ ## Hypermedia agent
400
+
401
+ Starting in version 2.0, Octokit is [hypermedia][]-enabled. Under the hood,
402
+ {Octokit::Client} uses [Sawyer][], a hypermedia client built on [Faraday][].
403
+
404
+ ### Hypermedia in Octokit
405
+
406
+ Resources returned by Octokit methods contain not only data but hypermedia
407
+ link relations:
408
+
409
+ ```ruby
410
+ user = Octokit.user 'technoweenie'
411
+
412
+ # Get the repos rel, returned from the API
413
+ # as repos_url in the resource
414
+ user.rels[:repos].href
415
+ # => "https://api.github.com/users/technoweenie/repos"
416
+
417
+ repos = user.rels[:repos].get.data
418
+ repos.last.name
419
+ # => "faraday-zeromq"
420
+ ```
421
+
422
+ When processing API responses, all `*_url` attributes are culled in to the link
423
+ relations collection. Any `url` attribute becomes `.rels[:self]`.
424
+
425
+ ### URI templates
426
+
427
+ You might notice many link relations have variable placeholders. Octokit
428
+ supports [URI Templates][uri-templates] for parameterized URI expansion:
429
+
430
+ ```ruby
431
+ repo = Octokit.repo 'pengwynn/pingwynn'
432
+ rel = repo.rels[:issues]
433
+ # => #<Sawyer::Relation: issues: get https://api.github.com/repos/pengwynn/pingwynn/issues{/number}>
434
+
435
+ # Get a page of issues
436
+ rel.get.data
437
+
438
+ # Get issue #2
439
+ rel.get(:uri => {:number => 2}).data
440
+ ```
441
+
442
+ ### The Full Hypermedia Experience™
443
+
444
+ If you want to use Octokit as a pure hypermedia API client, you can start at
445
+ the API root and follow link relations from there:
446
+
447
+ ```ruby
448
+ root = Octokit.root
449
+ root.rels[:repository].get :uri => {:owner => "octokit", :repo => "octokit.rb" }
450
+ root.rels[:user_repositories].get :uri => { :user => "octokit" },
451
+ :query => { :type => "owner" }
452
+ ```
453
+
454
+ Octokit 3.0 aims to be hypermedia-driven, removing the internal URL
455
+ construction currently used throughout the client.
456
+
457
+ [hypermedia]: http://en.wikipedia.org/wiki/Hypermedia
458
+ [Sawyer]: https://github.com/lostisland/sawyer
459
+ [Faraday]: https://github.com/lostisland/faraday
460
+ [uri-templates]: http://tools.ietf.org/html/rfc6570
461
+
462
+ ## Upgrading guide
463
+
464
+ Version 4.0
465
+
466
+ - **removes support for a [long-deprecated overload][list-pulls] for
467
+ passing state as a positional argument** when listing pull requests. Instead,
468
+ pass `state` in the method options.
469
+ - **drops support for Ruby < 2.0**.
470
+ - adds support for new [Enterprise-only APIs](#working-with-github-enterprise).
471
+ - adds support for [Repository redirects][redirects].
472
+
473
+ [list-pulls]: https://github.com/octokit/octokit.rb/commit/e48e91f736d5fce51e3bf74d7c9022aaa52f5c5c
474
+ [redirects]: https://developer.github.com/changes/2015-05-26-repository-redirects-are-coming/
475
+
476
+ Version 3.0 includes a couple breaking changes when upgrading from v2.x.x:
477
+
478
+ The [default media type][default-media-type] is now `v3` instead of `beta`. If
479
+ you need to request the older media type, you can set the default media type
480
+ for the client:
481
+
482
+ ```ruby
483
+ Octokit.default_media_type = "application/vnd.github.beta+json"
484
+ ```
485
+ or per-request
486
+
487
+ ```ruby
488
+ Octokit.emails(:accept => "application/vnd.github.beta+json")
489
+ ```
490
+
491
+ The long-deprecated `Octokit::Client#create_download` method has been removed.
492
+
493
+ [default-media-type]: https://developer.github.com/changes/2014-01-07-upcoming-change-to-default-media-type/
494
+
495
+ ### Upgrading from 1.x.x
496
+
497
+ Version 2.0 includes a completely rewritten `Client` factory that now memoizes
498
+ client instances based on unique configuration options. Breaking changes also
499
+ include:
500
+
501
+ * `:oauth_token` is now `:access_token`
502
+ * `:auto_traversal` is now `:auto_paginate`
503
+ * `Hashie::Mash` has been removed. Responses now return a `Sawyer::Resource`
504
+ object. This new type behaves mostly like a Ruby `Hash`, but does not fully
505
+ support the `Hashie::Mash` API.
506
+ * Two new client error types are raised where appropriate:
507
+ `Octokit::TooManyRequests` and `Octokit::TooManyLoginAttempts`
508
+ * The `search_*` methods from v1.x are now found at `legacy_search_*`
509
+ * Support for netrc requires including the [netrc gem][] in your Gemfile or
510
+ gemspec.
511
+ * DateTime fields are now proper `DateTime` objects. Previous versions outputted DateTime fields as 'String' objects.
512
+
513
+ [netrc gem]: https://rubygems.org/gems/netrc
514
+
515
+
516
+ ## Advanced usage
517
+
518
+ Since Octokit employs [Faraday][faraday] under the hood, some behavior can be
519
+ extended via middleware.
520
+
521
+ ### Debugging
522
+
523
+ Often, it helps to know what Octokit is doing under the hood. You can add a
524
+ logger to the middleware that enables you to peek into the underlying HTTP
525
+ traffic:
526
+
527
+ ```ruby
528
+ stack = Faraday::RackBuilder.new do |builder|
529
+ builder.response :logger
530
+ builder.use Octokit::Response::RaiseError
531
+ builder.adapter Faraday.default_adapter
532
+ end
533
+ Octokit.middleware = stack
534
+ Octokit.user 'pengwynn'
535
+ ```
536
+ ```
537
+ I, [2013-08-22T15:54:38.583300 #88227] INFO -- : get https://api.github.com/users/pengwynn
538
+ D, [2013-08-22T15:54:38.583401 #88227] DEBUG -- request: Accept: "application/vnd.github.beta+json"
539
+ User-Agent: "Octokit Ruby Gem 2.0.0.rc4"
540
+ I, [2013-08-22T15:54:38.843313 #88227] INFO -- Status: 200
541
+ D, [2013-08-22T15:54:38.843459 #88227] DEBUG -- response: server: "GitHub.com"
542
+ date: "Thu, 22 Aug 2013 20:54:40 GMT"
543
+ content-type: "application/json; charset=utf-8"
544
+ transfer-encoding: "chunked"
545
+ connection: "close"
546
+ status: "200 OK"
547
+ x-ratelimit-limit: "60"
548
+ x-ratelimit-remaining: "39"
549
+ x-ratelimit-reset: "1377205443"
550
+ ...
551
+ ```
552
+
553
+ See the [Faraday README][faraday] for more middleware magic.
554
+
555
+ ### Caching
556
+
557
+ If you want to boost performance, stretch your API rate limit, or avoid paying
558
+ the hypermedia tax, you can use [Faraday Http Cache][cache].
559
+
560
+ Add the gem to your Gemfile
561
+
562
+ gem 'faraday-http-cache'
563
+
564
+ Next, construct your own Faraday middleware:
565
+
566
+ ```ruby
567
+ stack = Faraday::RackBuilder.new do |builder|
568
+ builder.use Faraday::HttpCache, serializer: Marshal, shared_cache: false
569
+ builder.use Octokit::Response::RaiseError
570
+ builder.adapter Faraday.default_adapter
571
+ end
572
+ Octokit.middleware = stack
573
+ ```
574
+
575
+ Once configured, the middleware will store responses in cache based on ETag
576
+ fingerprint and serve those back up for future `304` responses for the same
577
+ resource. See the [project README][cache] for advanced usage.
578
+
579
+
580
+ [cache]: https://github.com/plataformatec/faraday-http-cache
581
+ [faraday]: https://github.com/lostisland/faraday
582
+
583
+ ## Hacking on Octokit.rb
584
+
585
+ If you want to hack on Octokit locally, we try to make [bootstrapping the
586
+ project][bootstrapping] as painless as possible. To start hacking, clone and run:
587
+
588
+ script/bootstrap
589
+
590
+ This will install project dependencies and get you up and running. If you want
591
+ to run a Ruby console to poke on Octokit, you can crank one up with:
592
+
593
+ script/console
594
+
595
+ Using the scripts in `./scripts` instead of `bundle exec rspec`, `bundle
596
+ console`, etc. ensures your dependencies are up-to-date.
597
+
598
+ ### Running and writing new tests
599
+
600
+ Octokit uses [VCR][] for recording and playing back API fixtures during test
601
+ runs. These cassettes (fixtures) are part of the Git project in the `spec/cassettes`
602
+ folder. If you're not recording new cassettes you can run the specs with existing
603
+ cassettes with:
604
+
605
+ script/test
606
+
607
+ Octokit uses environmental variables for storing credentials used in testing.
608
+ If you are testing an API endpoint that doesn't require authentication, you
609
+ can get away without any additional configuration. For the most part, tests
610
+ use an authenticated client, using a token stored in `ENV['OCTOKIT_TEST_GITHUB_TOKEN']`.
611
+ There are several different authenticating method's used across the api.
612
+ Here is the full list of configurable environmental variables for testing
613
+ Octokit:
614
+
615
+ ENV Variable | Description |
616
+ :-------------------|:-----------------|
617
+ `OCTOKIT_TEST_GITHUB_LOGIN`| GitHub login name (preferably one created specifically for testing against).
618
+ `OCTOKIT_TEST_GITHUB_PASSWORD`| Password for the test GitHub login.
619
+ `OCTOKIT_TEST_GITHUB_TOKEN` | [Personal Access Token](https://github.com/blog/1509-personal-api-tokens) for the test GitHub login.
620
+ `OCTOKIT_TEST_GITHUB_CLIENT_ID` | Test OAuth application client id.
621
+ `OCTOKIT_TEST_GITHUB_CLIENT_SECRET` | Test OAuth application client secret.
622
+ `OCTOKIT_TEST_GITHUB_REPOSITORY` | Test repository to perform destructive actions against, this should not be set to any repository of importance. **Automatically created by the test suite if nonexistent** Default: `api-sandbox`
623
+ `OCTOKIT_TEST_GITHUB_ORGANIZATION` | Test organization.
624
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_LOGIN` | GitHub Enterprise login name.
625
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_TOKEN` | GitHub Enterprise token.
626
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_PASSWORD` | GitHub Enterprise management console password.
627
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_ENDPOINT` | GitHub Enterprise hostname.
628
+ `OCTOKIT_TEST_GITHUB_ENTERPRISE_MANAGEMENT_CONSOLE_ENDPOINT` | GitHub Enterprise Management Console endpoint.
629
+ `OCTOKIT_TEST_GITHUB_INTEGRATION` | [GitHub Integration](https://developer.github.com/early-access/integrations/) owned by your test organization.
630
+ `OCTOKIT_TEST_GITHUB_INTEGRATION_INSTALLATION` | Installation of the GitHub Integration specified above.
631
+ `OCTOKIT_TEST_INTEGRATION_PEM_KEY` | File path to the private key generated from your integration.
632
+
633
+ Since we periodically refresh our cassettes, please keep some points in mind
634
+ when writing new specs.
635
+
636
+ * **Specs should be idempotent**. The HTTP calls made during a spec should be
637
+ able to be run over and over. This means deleting a known resource prior to
638
+ creating it if the name has to be unique.
639
+ * **Specs should be able to be run in random order.** If a spec depends on
640
+ another resource as a fixture, make sure that's created in the scope of the
641
+ spec and not depend on a previous spec to create the data needed.
642
+ * **Do not depend on authenticated user info.** Instead of asserting
643
+ actual values in resources, try to assert the existence of a key or that a
644
+ response is an Array. We're testing the client, not the API.
645
+
646
+ [bootstrapping]: http://wynnnetherland.com/linked/2013012801/bootstrapping-consistency
647
+ [VCR]: https://github.com/vcr/vcr
648
+
649
+ ## Supported Ruby Versions
650
+
651
+ This library aims to support and is [tested against][travis] the following Ruby
652
+ implementations:
653
+
654
+ * Ruby 2.0
655
+ * Ruby 2.1
656
+ * Ruby 2.2
657
+ * Ruby 2.3
658
+
659
+ If something doesn't work on one of these Ruby versions, it's a bug.
660
+
661
+ This library may inadvertently work (or seem to work) on other Ruby
662
+ implementations, but support will only be provided for the versions listed
663
+ above.
664
+
665
+ If you would like this library to support another Ruby version, you may
666
+ volunteer to be a maintainer. Being a maintainer entails making sure all tests
667
+ run and pass on that implementation. When something breaks on your
668
+ implementation, you will be responsible for providing patches in a timely
669
+ fashion. If critical issues for a particular implementation exist at the time
670
+ of a major release, support for that Ruby version may be dropped.
671
+
672
+ [travis]: https://travis-ci.org/octokit/octokit.rb
673
+
674
+ ## Versioning
675
+
676
+ This library aims to adhere to [Semantic Versioning 2.0.0][semver]. Violations
677
+ of this scheme should be reported as bugs. Specifically, if a minor or patch
678
+ version is released that breaks backward compatibility, that version should be
679
+ immediately yanked and/or a new version should be immediately released that
680
+ restores compatibility. Breaking changes to the public API will only be
681
+ introduced with new major versions. As a result of this policy, you can (and
682
+ should) specify a dependency on this gem using the [Pessimistic Version
683
+ Constraint][pvc] with two digits of precision. For example:
684
+
685
+ spec.add_dependency 'octokit', '~> 3.0'
686
+
687
+ The changes made between versions can be seen on the [project releases page][releases].
688
+
689
+ [semver]: http://semver.org/
690
+ [pvc]: http://guides.rubygems.org/patterns/#pessimistic-version-constraint
691
+ [releases]: https://github.com/octokit/octokit.rb/releases
692
+
693
+ ## License
694
+
695
+ Copyright (c) 2009-2014 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober
696
+
697
+ Permission is hereby granted, free of charge, to any person obtaining
698
+ a copy of this software and associated documentation files (the
699
+ "Software"), to deal in the Software without restriction, including
700
+ without limitation the rights to use, copy, modify, merge, publish,
701
+ distribute, sublicense, and/or sell copies of the Software, and to
702
+ permit persons to whom the Software is furnished to do so, subject to
703
+ the following conditions:
704
+
705
+ The above copyright notice and this permission notice shall be
706
+ included in all copies or substantial portions of the Software.
707
+
708
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
709
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
710
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
711
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
712
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
713
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
714
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.