github_api_v3 0.3.3 → 0.4.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/README.md +16 -6
- data/lib/github_api_v3/client/feeds.rb +1 -1
- data/lib/github_api_v3/client/gists.rb +10 -10
- data/lib/github_api_v3/client/issues.rb +8 -8
- data/lib/github_api_v3/client/markdown.rb +1 -1
- data/lib/github_api_v3/client/oauth.rb +101 -0
- data/lib/github_api_v3/client/orgs.rb +22 -22
- data/lib/github_api_v3/client/pull_requests.rb +14 -14
- data/lib/github_api_v3/client/repos.rb +23 -23
- data/lib/github_api_v3/client/stats.rb +5 -5
- data/lib/github_api_v3/client/users.rb +30 -20
- data/lib/github_api_v3/client.rb +73 -64
- data/lib/github_api_v3/error.rb +20 -2
- data/lib/github_api_v3/version.rb +1 -1
- data/lib/github_api_v3.rb +2 -2
- data/spec/cassettes/GitHub_Client_Gists/_create_gist/creates_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_create_gist_comment/creates_the_comment.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_create_gist_comment/returns_comment_information_after_creation.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_delete_gist/deletes_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_delete_gist_comment/deletes_the_comment.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_delete_gist_comment/returns_true_or_false.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_edit_gist/edits_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_edit_gist_comment/edits_the_comment.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_edit_gist_comment/returns_comment_information_after_editing.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_fork_gist/forks_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_fork_gist/returns_false_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist/returns_a_404_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist/returns_gist_information.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_comment/returns_a_404_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_comment/returns_a_comment.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_comments/returns_a_404_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_comments/returns_a_list_of_comments.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_starred_/returns_false_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gist_starred_/should_return_true_or_false.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gists/returns_an_array_of_gists.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gists/returns_an_array_of_gists_for_authenticated_user.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_gists/returns_public_gists_for_unauthenticated_user.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_star_gist/returns_false_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_star_gist/stars_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_unstar_gist/returns_false_when_not_found.json +1 -1
- data/spec/cassettes/GitHub_Client_Gists/_unstar_gist/unstars_a_gist.json +1 -1
- data/spec/cassettes/GitHub_Client_Issues/_issues/returns_an_array_of_issues.json +1 -1
- data/spec/cassettes/GitHub_Client_Issues/_issues/returns_the_correct_information.json +1 -1
- data/spec/cassettes/GitHub_Client_OAuth/_authorization/returns_a_404_if_using_access_token_authentication.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorization/returns_a_404_if_using_no_authentication.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorization/returns_a_404_when_not_found.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorization/returns_authorization_information.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorization/returns_the_correct_information.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorizations/returns_a_404_if_using_access_token_authentication.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorizations/returns_a_404_if_using_no_authentication.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorizations/returns_a_list_of_authorizations.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_authorizations/returns_the_correct_array.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_create_authorization/creates_the_correct_authorization.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_create_authorization/returns_authorization_information_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_delete_authorization/deletes_the_authorization.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_delete_authorization/returns_true.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_update_authorization/returns_authorization_information_hash.json +1 -0
- data/spec/cassettes/GitHub_Client_OAuth/_update_authorization/updates_the_authorization.json +1 -0
- data/spec/cassettes/GitHub_Client_Users/_follows_/returns_false_when_not_following.json +1 -1
- data/spec/cassettes/GitHub_Client_Users/_follows_/returns_true_when_following.json +1 -1
- data/spec/cassettes/GitHub_Client_Users/_rate_limit/returns_authenticated_rate_limit_information.json +1 -0
- data/spec/cassettes/GitHub_Client_Users/_rate_limit/returns_unauthenticated_rate_limit_information.json +1 -0
- data/spec/config.sample.yml +3 -1
- data/spec/github_api_v3/client/gists_spec.rb +25 -25
- data/spec/github_api_v3/client/oauth_spec.rb +87 -0
- data/spec/github_api_v3/client/users_spec.rb +16 -0
- data/spec/spec_helper.rb +21 -11
- metadata +38 -1
@@ -13,7 +13,7 @@ module GitHub
|
|
13
13
|
# @return [Array]
|
14
14
|
# @see http://developer.github.com/v3/repos/#list-all-public-repositories
|
15
15
|
def all_repos
|
16
|
-
get '/repositories'
|
16
|
+
get '/repositories'
|
17
17
|
end
|
18
18
|
|
19
19
|
# Get one repository.
|
@@ -25,7 +25,7 @@ module GitHub
|
|
25
25
|
# @example
|
26
26
|
# GitHub.repo('caseyscarborough','github')
|
27
27
|
def repo(owner, repo)
|
28
|
-
get "/repos/#{owner}/#{repo}"
|
28
|
+
get "/repos/#{owner}/#{repo}"
|
29
29
|
end
|
30
30
|
|
31
31
|
# Get all repositories for a user.
|
@@ -43,7 +43,7 @@ module GitHub
|
|
43
43
|
if username
|
44
44
|
get "/users/#{username}/repos"
|
45
45
|
else
|
46
|
-
get '/user/repos'
|
46
|
+
get '/user/repos'
|
47
47
|
end
|
48
48
|
end
|
49
49
|
|
@@ -67,7 +67,7 @@ module GitHub
|
|
67
67
|
# @example
|
68
68
|
# client.create_repo('new-repo', description: 'New repository.', private: true)
|
69
69
|
def create_repo(name, options={})
|
70
|
-
post "/user/repos",
|
70
|
+
post "/user/repos", body: options.merge(name: name)
|
71
71
|
end
|
72
72
|
|
73
73
|
# Edit a repository.
|
@@ -91,7 +91,7 @@ module GitHub
|
|
91
91
|
# client.edit_repo('caseyscarborough','github', name: 'github', description: 'An awesome repository!')
|
92
92
|
def edit_repo(owner, repo, options={})
|
93
93
|
options[:name] = repo unless options[:name]
|
94
|
-
patch "/repos/#{owner}/#{repo}",
|
94
|
+
patch "/repos/#{owner}/#{repo}", body: options
|
95
95
|
end
|
96
96
|
|
97
97
|
# Delete a repository.
|
@@ -104,7 +104,7 @@ module GitHub
|
|
104
104
|
# @example
|
105
105
|
# client.delete_repo('repo-name')
|
106
106
|
def delete_repo(owner, repo)
|
107
|
-
|
107
|
+
boolean_request :delete, "/repos/#{owner}/#{repo}"
|
108
108
|
end
|
109
109
|
|
110
110
|
# Get organization repositories.
|
@@ -115,7 +115,7 @@ module GitHub
|
|
115
115
|
# @example
|
116
116
|
# GitHub.org_repos('rails')
|
117
117
|
def org_repos(org)
|
118
|
-
get "/orgs/#{org}/repos"
|
118
|
+
get "/orgs/#{org}/repos"
|
119
119
|
end
|
120
120
|
|
121
121
|
# List contributors for a repository.
|
@@ -127,7 +127,7 @@ module GitHub
|
|
127
127
|
# @example
|
128
128
|
# GitHub.contributors('caseyscarborough','github')
|
129
129
|
def contributors(owner, repo)
|
130
|
-
get "/repos/#{owner}/#{repo}/contributors"
|
130
|
+
get "/repos/#{owner}/#{repo}/contributors"
|
131
131
|
end
|
132
132
|
|
133
133
|
# List languages for a repository.
|
@@ -139,7 +139,7 @@ module GitHub
|
|
139
139
|
# @example
|
140
140
|
# GitHub.languages('caseyscarborough','github')
|
141
141
|
def languages(owner, repo)
|
142
|
-
get "/repos/#{owner}/#{repo}/languages"
|
142
|
+
get "/repos/#{owner}/#{repo}/languages"
|
143
143
|
end
|
144
144
|
|
145
145
|
# def teams(owner, repo)
|
@@ -155,7 +155,7 @@ module GitHub
|
|
155
155
|
# @example
|
156
156
|
# GitHub.tags('caseyscarborough','github')
|
157
157
|
def tags(owner, repo)
|
158
|
-
get "/repos/#{owner}/#{repo}/tags"
|
158
|
+
get "/repos/#{owner}/#{repo}/tags"
|
159
159
|
end
|
160
160
|
|
161
161
|
# List branches for a repository.
|
@@ -167,7 +167,7 @@ module GitHub
|
|
167
167
|
# @example
|
168
168
|
# GitHub.branches('caseyscarborough','github')
|
169
169
|
def branches(owner, repo)
|
170
|
-
get "/repos/#{owner}/#{repo}/branches"
|
170
|
+
get "/repos/#{owner}/#{repo}/branches"
|
171
171
|
end
|
172
172
|
|
173
173
|
# Get information about a branch.
|
@@ -179,7 +179,7 @@ module GitHub
|
|
179
179
|
# @example
|
180
180
|
# GitHub.branch('caseyscarborough','github','master')
|
181
181
|
def branch(owner, repo, branch)
|
182
|
-
get "/repos/#{owner}/#{repo}/branches/#{branch}"
|
182
|
+
get "/repos/#{owner}/#{repo}/branches/#{branch}"
|
183
183
|
end
|
184
184
|
|
185
185
|
# Get list of collaborators for a repository.
|
@@ -191,7 +191,7 @@ module GitHub
|
|
191
191
|
# @example
|
192
192
|
# GitHub.collaborators('caseyscarborough','github')
|
193
193
|
def collaborators(owner, repo)
|
194
|
-
get "/repos/#{owner}/#{repo}/collaborators"
|
194
|
+
get "/repos/#{owner}/#{repo}/collaborators"
|
195
195
|
end
|
196
196
|
|
197
197
|
# Determine if a user is a collaborator to a repository.
|
@@ -204,7 +204,7 @@ module GitHub
|
|
204
204
|
# @example
|
205
205
|
# GitHub.collaborator?('caseyscarborough','github','caseyscarborough')
|
206
206
|
def collaborator?(owner, repo, user)
|
207
|
-
|
207
|
+
boolean_request :get, "/repos/#{owner}/#{repo}/collaborators/#{user}"
|
208
208
|
end
|
209
209
|
|
210
210
|
# Add a collaborator to a repository.
|
@@ -217,7 +217,7 @@ module GitHub
|
|
217
217
|
# @return [Boolean] True if successful, false if not.
|
218
218
|
# @see http://developer.github.com/v3/repos/collaborators/#add-collaborator
|
219
219
|
def add_collaborator(owner, repo, user)
|
220
|
-
|
220
|
+
boolean_request :put, "/repos/#{owner}/#{repo}/collaborators/#{user}"
|
221
221
|
end
|
222
222
|
|
223
223
|
# Remove a collaborator from a repository.
|
@@ -230,7 +230,7 @@ module GitHub
|
|
230
230
|
# @return [Boolean] True if successful, false if not.
|
231
231
|
# @see http://developer.github.com/v3/repos/collaborators/#remove-collaborator
|
232
232
|
def remove_collaborator(owner, repo, user)
|
233
|
-
|
233
|
+
boolean_request :delete, "/repos/#{owner}/#{repo}/collaborators/#{user}"
|
234
234
|
end
|
235
235
|
|
236
236
|
# List Stargazers for a repository.
|
@@ -242,7 +242,7 @@ module GitHub
|
|
242
242
|
# @example
|
243
243
|
# GitHub.stargazers('caseyscarborough','github')
|
244
244
|
def stargazers(owner, repo)
|
245
|
-
get "/repos/#{owner}/#{repo}/stargazers"
|
245
|
+
get "/repos/#{owner}/#{repo}/stargazers"
|
246
246
|
end
|
247
247
|
|
248
248
|
# Star a repository.
|
@@ -254,7 +254,7 @@ module GitHub
|
|
254
254
|
# @return [Boolean] True if successful, false if not.
|
255
255
|
# @see http://developer.github.com/v3/activity/starring/#star-a-repository
|
256
256
|
def star(owner, repo)
|
257
|
-
|
257
|
+
boolean_request :put, "/user/starred/#{owner}/#{repo}"
|
258
258
|
end
|
259
259
|
|
260
260
|
# Unstar a repository.
|
@@ -266,7 +266,7 @@ module GitHub
|
|
266
266
|
# @return [Boolean] True if successful, false if not.
|
267
267
|
# @see http://developer.github.com/v3/activity/starring/#unstar-a-repository
|
268
268
|
def unstar(owner, repo)
|
269
|
-
|
269
|
+
boolean_request :delete, "/user/starred/#{owner}/#{repo}"
|
270
270
|
end
|
271
271
|
|
272
272
|
# List Watchers for a repository.
|
@@ -276,7 +276,7 @@ module GitHub
|
|
276
276
|
# @return [Array] List of users.
|
277
277
|
# @see http://developer.github.com/v3/activity/watching/#list-watchers
|
278
278
|
def watchers(owner, repo)
|
279
|
-
get "/repos/#{owner}/#{repo}/subscribers"
|
279
|
+
get "/repos/#{owner}/#{repo}/subscribers"
|
280
280
|
end
|
281
281
|
|
282
282
|
# Get subscription information.
|
@@ -290,7 +290,7 @@ module GitHub
|
|
290
290
|
# @example
|
291
291
|
# client.subscription('caseyscarborough','github')
|
292
292
|
def subscription(owner, repo)
|
293
|
-
get "/repos/#{owner}/#{repo}/subscription"
|
293
|
+
get "/repos/#{owner}/#{repo}/subscription"
|
294
294
|
end
|
295
295
|
|
296
296
|
# Set a repository subscription.
|
@@ -306,7 +306,7 @@ module GitHub
|
|
306
306
|
def subscribe(owner, repo, options={})
|
307
307
|
options[:subscribed] = true unless options[:subscribed]
|
308
308
|
options[:ignored] = false unless options[:ignored]
|
309
|
-
put "/repos/#{owner}/#{repo}/subscription",
|
309
|
+
put "/repos/#{owner}/#{repo}/subscription", body: options
|
310
310
|
end
|
311
311
|
|
312
312
|
# Delete a repository subscription.
|
@@ -319,7 +319,7 @@ module GitHub
|
|
319
319
|
# @example
|
320
320
|
# client.unsubscribe('caseyscarborough','github')
|
321
321
|
def unsubscribe(owner, repo)
|
322
|
-
|
322
|
+
boolean_request :delete, "/repos/#{owner}/#{repo}/subscription"
|
323
323
|
end
|
324
324
|
|
325
325
|
end
|
@@ -25,7 +25,7 @@ module GitHub
|
|
25
25
|
# @return [Array] Contributor list.
|
26
26
|
# @see http://developer.github.com/v3/repos/statistics/#get-contributors-list-with-additions-deletions-and-commit-counts
|
27
27
|
def contributors_list(owner, repo)
|
28
|
-
get "/repos/#{owner}/#{repo}/stats/contributors"
|
28
|
+
get "/repos/#{owner}/#{repo}/stats/contributors"
|
29
29
|
end
|
30
30
|
|
31
31
|
# Get the last year of commit activity data.
|
@@ -35,7 +35,7 @@ module GitHub
|
|
35
35
|
# @return [Array] Commit activity list.
|
36
36
|
# @see http://developer.github.com/v3/repos/statistics/#get-the-last-year-of-commit-activity-data
|
37
37
|
def commit_activity(owner, repo)
|
38
|
-
get "/repos/#{owner}/#{repo}/stats/commit_activity"
|
38
|
+
get "/repos/#{owner}/#{repo}/stats/commit_activity"
|
39
39
|
end
|
40
40
|
|
41
41
|
# Get the number of additions and deletions per week.
|
@@ -45,7 +45,7 @@ module GitHub
|
|
45
45
|
# @return [Array]
|
46
46
|
# @see http://developer.github.com/v3/repos/statistics/#get-the-number-of-additions-and-deletions-per-week
|
47
47
|
def code_frequency(owner, repo)
|
48
|
-
get "/repos/#{owner}/#{repo}/stats/code_frequency"
|
48
|
+
get "/repos/#{owner}/#{repo}/stats/code_frequency"
|
49
49
|
end
|
50
50
|
|
51
51
|
# Get the weekly commit count for the repo owner and everyone else.
|
@@ -55,7 +55,7 @@ module GitHub
|
|
55
55
|
# @return [Array] Contributor list.
|
56
56
|
# @see http://developer.github.com/v3/repos/statistics/#get-the-weekly-commit-count-for-the-repo-owner-and-everyone-else
|
57
57
|
def participation(owner, repo)
|
58
|
-
get "/repos/#{owner}/#{repo}/stats/participation"
|
58
|
+
get "/repos/#{owner}/#{repo}/stats/participation"
|
59
59
|
end
|
60
60
|
|
61
61
|
# Get the number of commits per hour in each day.
|
@@ -65,7 +65,7 @@ module GitHub
|
|
65
65
|
# @return [Array]
|
66
66
|
# @see http://developer.github.com/v3/repos/statistics/#get-the-number-of-commits-per-hour-in-each-day
|
67
67
|
def punch_card(owner, repo)
|
68
|
-
get "/repos/#{owner}/#{repo}/stats/punch_card"
|
68
|
+
get "/repos/#{owner}/#{repo}/stats/punch_card"
|
69
69
|
end
|
70
70
|
|
71
71
|
end
|
@@ -21,7 +21,7 @@
|
|
21
21
|
if username
|
22
22
|
get "/users/#{username}"
|
23
23
|
else
|
24
|
-
get '/user'
|
24
|
+
get '/user'
|
25
25
|
end
|
26
26
|
end
|
27
27
|
|
@@ -41,7 +41,7 @@
|
|
41
41
|
# client = GitHub::Client.new(login: 'username', access_token: 'abcdefghijklmnopqrstuvwxyz12345')
|
42
42
|
# client.emails # => ["email@example.com", "email2@example.com"]
|
43
43
|
def emails
|
44
|
-
get '/user/emails'
|
44
|
+
get '/user/emails'
|
45
45
|
end
|
46
46
|
|
47
47
|
# Follow a user.
|
@@ -54,7 +54,7 @@
|
|
54
54
|
# @example
|
55
55
|
# client.follow('caseyscarborough')
|
56
56
|
def follow(username)
|
57
|
-
|
57
|
+
boolean_request :put, "/user/following/#{username}"
|
58
58
|
end
|
59
59
|
|
60
60
|
# Checks to see if a user is following another user.
|
@@ -66,8 +66,7 @@
|
|
66
66
|
# @example
|
67
67
|
# GitHub.follows?('caseyscarborough', 'matz')
|
68
68
|
def follows?(username, target_username)
|
69
|
-
|
70
|
-
response.code == 204
|
69
|
+
boolean_request :get, "/users/#{username}/following/#{target_username}"
|
71
70
|
end
|
72
71
|
|
73
72
|
# List a user's followers.
|
@@ -87,7 +86,7 @@
|
|
87
86
|
if username
|
88
87
|
get "/users/#{username}/followers"
|
89
88
|
else
|
90
|
-
get '/user/followers'
|
89
|
+
get '/user/followers'
|
91
90
|
end
|
92
91
|
end
|
93
92
|
|
@@ -111,8 +110,7 @@
|
|
111
110
|
# @example
|
112
111
|
# client.following?('caseyscarborough')
|
113
112
|
def following?(username)
|
114
|
-
|
115
|
-
response.code == 204
|
113
|
+
boolean_request :get, "/user/following/#{username}"
|
116
114
|
end
|
117
115
|
|
118
116
|
# Unfollow a user.
|
@@ -124,7 +122,7 @@
|
|
124
122
|
# @example
|
125
123
|
# client.unfollow('matz')
|
126
124
|
def unfollow(username)
|
127
|
-
|
125
|
+
boolean_request :delete, "/user/following/#{username}"
|
128
126
|
end
|
129
127
|
|
130
128
|
# Get a list of public keys for a user.
|
@@ -141,7 +139,7 @@
|
|
141
139
|
if username
|
142
140
|
get "/users/#{username}/keys"
|
143
141
|
else
|
144
|
-
get '/user/keys'
|
142
|
+
get '/user/keys'
|
145
143
|
end
|
146
144
|
end
|
147
145
|
|
@@ -154,7 +152,7 @@
|
|
154
152
|
# @example
|
155
153
|
# client.key(123)
|
156
154
|
def key(id)
|
157
|
-
get "/user/keys/#{id}"
|
155
|
+
get "/user/keys/#{id}"
|
158
156
|
end
|
159
157
|
|
160
158
|
# Create a public key.
|
@@ -168,7 +166,7 @@
|
|
168
166
|
# @example
|
169
167
|
# client.create_key('octocat@octomac', 'ssh-rsa AAA...')
|
170
168
|
def create_key(title, key)
|
171
|
-
post '/user/keys',
|
169
|
+
post '/user/keys', body: {title: title, key: key}
|
172
170
|
end
|
173
171
|
|
174
172
|
# Update a public key
|
@@ -183,7 +181,7 @@
|
|
183
181
|
# @example
|
184
182
|
# client.update_key(1, 'octocat@octomac', 'ssh-rsa AAA...')
|
185
183
|
def update_key(id, title, key)
|
186
|
-
patch "/user/keys/#{id}",
|
184
|
+
patch "/user/keys/#{id}", body: {title: title, key: key}
|
187
185
|
end
|
188
186
|
|
189
187
|
# Remove a public key from a user's account.
|
@@ -195,7 +193,7 @@
|
|
195
193
|
# @example
|
196
194
|
# client.delete_key(123)
|
197
195
|
def delete_key(id)
|
198
|
-
|
196
|
+
boolean_request :delete, "/user/keys/#{id}"
|
199
197
|
end
|
200
198
|
|
201
199
|
# List notifications.
|
@@ -211,7 +209,7 @@
|
|
211
209
|
# @example
|
212
210
|
# client.notifications
|
213
211
|
def notifications(options={})
|
214
|
-
get "/notifications",
|
212
|
+
get "/notifications", params: options
|
215
213
|
end
|
216
214
|
|
217
215
|
# List notifications for a repository.
|
@@ -229,7 +227,7 @@
|
|
229
227
|
# @example
|
230
228
|
# client.repo_notifications('caseyscarborough','github')
|
231
229
|
def repo_notifications(owner, repo, options={})
|
232
|
-
get "/repos/#{owner}/#{repo}/notifications"
|
230
|
+
get "/repos/#{owner}/#{repo}/notifications"
|
233
231
|
end
|
234
232
|
|
235
233
|
# List repositories a user is starring.
|
@@ -247,7 +245,7 @@
|
|
247
245
|
if username
|
248
246
|
get "/users/#{username}/starred"
|
249
247
|
else
|
250
|
-
get "/user/starred"
|
248
|
+
get "/user/starred"
|
251
249
|
end
|
252
250
|
end
|
253
251
|
|
@@ -262,7 +260,7 @@
|
|
262
260
|
# @example
|
263
261
|
# client.starring?('caseyscarborough','github')
|
264
262
|
def starring?(owner, repo)
|
265
|
-
|
263
|
+
boolean_request :get, "/user/starred/#{owner}/#{repo}"
|
266
264
|
end
|
267
265
|
|
268
266
|
# List repositories a user is watching.
|
@@ -278,7 +276,7 @@
|
|
278
276
|
if username
|
279
277
|
get "/users/#{username}/subscriptions"
|
280
278
|
else
|
281
|
-
get "/user/subscriptions"
|
279
|
+
get "/user/subscriptions"
|
282
280
|
end
|
283
281
|
end
|
284
282
|
|
@@ -295,10 +293,22 @@
|
|
295
293
|
if username
|
296
294
|
get "/users/#{username}/orgs"
|
297
295
|
else
|
298
|
-
get "/user/orgs"
|
296
|
+
get "/user/orgs"
|
299
297
|
end
|
300
298
|
end
|
301
299
|
|
300
|
+
# Get the current client's rate limit info.
|
301
|
+
#
|
302
|
+
# @return [Hash] The rate limit information.
|
303
|
+
# @see http://developer.github.com/v3/rate_limit/
|
304
|
+
# @example Unauthenticated client's rate limit.
|
305
|
+
# GitHub.rate_limit
|
306
|
+
# @example Authenticated client's rate limit.
|
307
|
+
# client.rate_limit
|
308
|
+
def rate_limit
|
309
|
+
get "/rate_limit"
|
310
|
+
end
|
311
|
+
|
302
312
|
end
|
303
313
|
|
304
314
|
end
|
data/lib/github_api_v3/client.rb
CHANGED
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'base64'
|
1
2
|
require 'json'
|
2
3
|
require 'github_api_v3/client/events'
|
3
4
|
require 'github_api_v3/client/feeds'
|
@@ -5,6 +6,7 @@ require 'github_api_v3/client/gists'
|
|
5
6
|
require 'github_api_v3/client/gitignore'
|
6
7
|
require 'github_api_v3/client/issues'
|
7
8
|
require 'github_api_v3/client/markdown'
|
9
|
+
require 'github_api_v3/client/oauth'
|
8
10
|
require 'github_api_v3/client/orgs'
|
9
11
|
require 'github_api_v3/client/pull_requests'
|
10
12
|
require 'github_api_v3/client/repos'
|
@@ -29,13 +31,14 @@ module GitHub
|
|
29
31
|
include GitHub::Client::Gists
|
30
32
|
include GitHub::Client::Issues
|
31
33
|
include GitHub::Client::Markdown
|
34
|
+
include GitHub::Client::OAuth
|
32
35
|
include GitHub::Client::Orgs
|
33
36
|
include GitHub::Client::PullRequests
|
34
37
|
include GitHub::Client::Repos
|
35
38
|
include GitHub::Client::Stats
|
36
39
|
include GitHub::Client::Users
|
37
40
|
|
38
|
-
|
41
|
+
attr_accessor :login, :access_token, :password
|
39
42
|
|
40
43
|
def initialize(options={})
|
41
44
|
@login = options[:login]
|
@@ -48,98 +51,48 @@ module GitHub
|
|
48
51
|
# Perform a get request.
|
49
52
|
#
|
50
53
|
# @return [Hash, Array, String]
|
51
|
-
def get(url,
|
52
|
-
response =
|
54
|
+
def get(url, options={})
|
55
|
+
response = request :get, url, options
|
53
56
|
handle_response(response)
|
54
57
|
response.parsed_response
|
55
58
|
end
|
56
59
|
|
57
|
-
# Perform a get request with boolean return type.
|
58
|
-
#
|
59
|
-
# @return [Boolean]
|
60
|
-
def boolean_get(url, params={})
|
61
|
-
response = self.class.get url, query: params
|
62
|
-
response.code == 204
|
63
|
-
rescue GitHub::NotFound
|
64
|
-
false
|
65
|
-
end
|
66
|
-
|
67
60
|
# Perform a put request.
|
68
61
|
#
|
69
62
|
# @return [Hash, Array, String]
|
70
|
-
def put(url,
|
71
|
-
response =
|
63
|
+
def put(url, options={})
|
64
|
+
response = request :put, url, options
|
72
65
|
handle_response(response)
|
73
66
|
response.parsed_response
|
74
67
|
end
|
75
68
|
|
76
|
-
# Perform a put request with boolean return type.
|
77
|
-
#
|
78
|
-
# @return [Boolean]
|
79
|
-
def boolean_put(url, params={}, body={})
|
80
|
-
response = self.class.put url, query: params, body: body.to_json
|
81
|
-
response.code == 204
|
82
|
-
rescue GitHub::NotFound
|
83
|
-
false
|
84
|
-
end
|
85
|
-
|
86
69
|
# Perform a post request.
|
87
70
|
#
|
88
71
|
# @return [Hash, Array, String]
|
89
|
-
def post(url,
|
90
|
-
response =
|
72
|
+
def post(url, options={})
|
73
|
+
response = request :post, url, options
|
91
74
|
handle_response(response)
|
92
75
|
response.parsed_response
|
93
76
|
end
|
94
77
|
|
95
|
-
# Perform a post request with boolean return type.
|
96
|
-
#
|
97
|
-
# @return [Boolean]
|
98
|
-
def boolean_post(url, params={}, body={})
|
99
|
-
response = self.class.post url, query: params, body: body.to_json
|
100
|
-
response.code == 204
|
101
|
-
rescue GitHub::NotFound
|
102
|
-
false
|
103
|
-
end
|
104
|
-
|
105
78
|
# Perform a patch request.
|
106
79
|
#
|
107
80
|
# @return [Hash, Array, String]
|
108
|
-
def patch(url,
|
109
|
-
response =
|
81
|
+
def patch(url, options={})
|
82
|
+
response = request :patch, url, options
|
110
83
|
handle_response(response)
|
111
84
|
response.parsed_response
|
112
85
|
end
|
113
86
|
|
114
|
-
# Perform a patch request with boolean return type.
|
115
|
-
#
|
116
|
-
# @return [Boolean]
|
117
|
-
def boolean_patch(url, params={}, body={})
|
118
|
-
response = self.class.patch url, query: params, body: body.to_json
|
119
|
-
response.code == 204
|
120
|
-
rescue GitHub::NotFound
|
121
|
-
false
|
122
|
-
end
|
123
|
-
|
124
87
|
# Perform a delete request.
|
125
88
|
#
|
126
89
|
# @return [Hash, Array, String]
|
127
|
-
def delete(url,
|
128
|
-
response =
|
90
|
+
def delete(url, options={})
|
91
|
+
response = request :delete, url, options
|
129
92
|
handle_response(response)
|
130
93
|
response.parsed_response
|
131
94
|
end
|
132
95
|
|
133
|
-
# Perform a delete request with boolean return type.
|
134
|
-
#
|
135
|
-
# @return [Boolean]
|
136
|
-
def boolean_delete(url, params={})
|
137
|
-
response = self.class.delete url, query: params
|
138
|
-
response.code == 204
|
139
|
-
rescue GitHub::NotFound
|
140
|
-
false
|
141
|
-
end
|
142
|
-
|
143
96
|
# Return a hash with client's login and password.
|
144
97
|
#
|
145
98
|
# @return [Hash]
|
@@ -154,6 +107,51 @@ module GitHub
|
|
154
107
|
@login.nil? ? {} : { login: @login, access_token: @access_token }
|
155
108
|
end
|
156
109
|
|
110
|
+
def basic_auth_headers
|
111
|
+
encoded_auth = Base64.encode64("#{@login}:#{@password}")
|
112
|
+
{ 'Authorization' => "Basic #{encoded_auth}" }
|
113
|
+
end
|
114
|
+
|
115
|
+
# Send an HTTP request.
|
116
|
+
#
|
117
|
+
# @param method [Symbol] The request type, such as :get, :put, or :post.
|
118
|
+
# @param url [String] The URL to send the request to.
|
119
|
+
# @param options [Hash] Optional parameters.
|
120
|
+
# @option options [Hash] :params URL parameters.
|
121
|
+
# @option options [Hash] :headers Headers to send with the request.
|
122
|
+
# @option options [Hash] :body Body of the request.
|
123
|
+
# @return [Array, Hash]
|
124
|
+
# @example POST request
|
125
|
+
# request :post, 'http://example.com/users', params: { name: 'Casey' }, body: { example: 'example' }
|
126
|
+
def request(method, url, options={})
|
127
|
+
params = options[:params] || {}
|
128
|
+
headers = options[:headers] || {}
|
129
|
+
body = options[:body] || {}
|
130
|
+
|
131
|
+
params.merge!(auth_params)
|
132
|
+
headers.merge!(basic_auth_headers) if @login && @password
|
133
|
+
|
134
|
+
self.class.send(method, url, query: params, body: body.to_json, headers: headers)
|
135
|
+
end
|
136
|
+
|
137
|
+
# Get a boolean response from an HTTP request.
|
138
|
+
#
|
139
|
+
# @param method [Symbol] The request type, such as :get, :put, or :post.
|
140
|
+
# @param url [String] The URL to send the request to.
|
141
|
+
# @param options [Hash] Optional parameters.
|
142
|
+
# @option options [Hash] :params URL parameters.
|
143
|
+
# @option options [Hash] :headers Headers to send with the request.
|
144
|
+
# @option options [Hash] :body Body of the request.
|
145
|
+
# @return [Boolean]
|
146
|
+
# @example DELETE Request
|
147
|
+
# boolean_request :delete, 'http://example.com/users'
|
148
|
+
def boolean_request(method, url, options={})
|
149
|
+
response = request(method, url, options)
|
150
|
+
response.code == 204
|
151
|
+
rescue GitHub::NotFound
|
152
|
+
false
|
153
|
+
end
|
154
|
+
|
157
155
|
# Handle HTTP responses.
|
158
156
|
#
|
159
157
|
# Raise proper exceptions based on the response code.
|
@@ -161,11 +159,22 @@ module GitHub
|
|
161
159
|
# @return [HTTParty::Response]
|
162
160
|
def handle_response(response)
|
163
161
|
case response.code
|
162
|
+
when 400 then raise BadRequest
|
164
163
|
when 401 then raise Unauthorized
|
165
|
-
when 403
|
164
|
+
when 403
|
165
|
+
if response.body =~ /rate limit/i
|
166
|
+
raise RateLimitExceeded
|
167
|
+
elsif response.body =~ /login attempts/i
|
168
|
+
raise LoginAttemptsExceeded
|
169
|
+
else
|
170
|
+
raise Forbidden
|
171
|
+
end
|
166
172
|
when 404 then raise NotFound
|
167
|
-
when 400
|
168
|
-
when 500
|
173
|
+
when 400...500 then raise ClientError
|
174
|
+
when 500 then raise InternalServerError
|
175
|
+
when 502 then raise BadGateway
|
176
|
+
when 503 then raise ServiceUnavailable
|
177
|
+
when 500...600 then raise ServerError, response.code
|
169
178
|
else
|
170
179
|
response
|
171
180
|
end
|
data/lib/github_api_v3/error.rb
CHANGED
@@ -3,6 +3,9 @@ module GitHub
|
|
3
3
|
# Default GitHub error.
|
4
4
|
class GitHubError < StandardError; end
|
5
5
|
|
6
|
+
# Raised when a 400 HTTP status code is received.
|
7
|
+
class BadRequest < GitHubError; end
|
8
|
+
|
6
9
|
# Raised when a 404 HTTP status code is received.
|
7
10
|
class NotFound < GitHubError; end
|
8
11
|
|
@@ -15,10 +18,25 @@ module GitHub
|
|
15
18
|
# Raised when a 403 HTTP status code is received.
|
16
19
|
class RateLimitExceeded < GitHubError; end
|
17
20
|
|
18
|
-
# Raised when a
|
21
|
+
# Raised when a 403 HTTP status code is received.
|
22
|
+
class LoginAttemptsExceeded < GitHubError; end
|
23
|
+
|
24
|
+
# Raised when a 403 HTTP status code is received.
|
25
|
+
class Forbidden < GitHubError; end
|
26
|
+
|
27
|
+
# Raised when a 500 HTTP status code is received.
|
28
|
+
class InternalServerError < GitHubError; end
|
29
|
+
|
30
|
+
# Raised when a 502 HTTP status code is received.
|
31
|
+
class BadGateway < GitHubError; end
|
32
|
+
|
33
|
+
# Raised when a 503 HTTP status code is received.
|
34
|
+
class ServiceUnavailable < GitHubError; end
|
35
|
+
|
36
|
+
# Raised when a 500...600 HTTP status code is received.
|
19
37
|
class ServerError < GitHubError; end
|
20
38
|
|
21
|
-
# Raised when a 400
|
39
|
+
# Raised when a 400...500 HTTP status code is received.
|
22
40
|
class ClientError < GitHubError; end
|
23
41
|
|
24
42
|
end
|