octokit 1.18.0 → 1.19.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (173) hide show
  1. data/.document +1 -1
  2. data/.rspec +1 -0
  3. data/CHANGELOG.md +25 -0
  4. data/{LICENSE → LICENSE.md} +0 -0
  5. data/README.md +25 -8
  6. data/lib/faraday/response/raise_octokit_error.rb +4 -1
  7. data/lib/octokit/client.rb +6 -0
  8. data/lib/octokit/client/authorizations.rb +20 -7
  9. data/lib/octokit/client/commits.rb +120 -13
  10. data/lib/octokit/client/contents.rb +3 -4
  11. data/lib/octokit/client/downloads.rb +4 -3
  12. data/lib/octokit/client/emojis.rb +1 -1
  13. data/lib/octokit/client/events.rb +4 -4
  14. data/lib/octokit/client/gists.rb +33 -31
  15. data/lib/octokit/client/issues.rb +15 -15
  16. data/lib/octokit/client/labels.rb +13 -13
  17. data/lib/octokit/client/markdown.rb +2 -1
  18. data/lib/octokit/client/milestones.rb +6 -6
  19. data/lib/octokit/client/notifications.rb +222 -0
  20. data/lib/octokit/client/objects.rb +4 -4
  21. data/lib/octokit/client/organizations.rb +65 -20
  22. data/lib/octokit/client/pub_sub_hubbub.rb +2 -2
  23. data/lib/octokit/client/pulls.rb +91 -3
  24. data/lib/octokit/client/rate_limit.rb +20 -0
  25. data/lib/octokit/client/refs.rb +4 -4
  26. data/lib/octokit/client/repositories.rb +106 -37
  27. data/lib/octokit/client/say.rb +14 -0
  28. data/lib/octokit/client/statuses.rb +2 -2
  29. data/lib/octokit/client/users.rb +92 -24
  30. data/lib/octokit/connection.rb +21 -21
  31. data/lib/octokit/request.rb +47 -36
  32. data/lib/octokit/version.rb +1 -1
  33. data/octokit.gemspec +25 -25
  34. data/spec/fixtures/{v3/authorization.json → authorization.json} +0 -0
  35. data/spec/fixtures/{v3/authorizations.json → authorizations.json} +0 -0
  36. data/spec/fixtures/{v3/blob.json → blob.json} +0 -0
  37. data/spec/fixtures/{v3/blob_create.json → blob_create.json} +0 -0
  38. data/spec/fixtures/{v3/branches.json → branches.json} +0 -0
  39. data/spec/fixtures/{v3/collaborators.json → collaborators.json} +0 -0
  40. data/spec/fixtures/{v3/comment.json → comment.json} +0 -0
  41. data/spec/fixtures/{v3/comments.json → comments.json} +0 -0
  42. data/spec/fixtures/{v3/commit.json → commit.json} +0 -0
  43. data/spec/fixtures/{v3/commit_comment.json → commit_comment.json} +0 -0
  44. data/spec/fixtures/{v3/commit_comment_create.json → commit_comment_create.json} +0 -0
  45. data/spec/fixtures/{v3/commit_comment_update.json → commit_comment_update.json} +0 -0
  46. data/spec/fixtures/{v3/commit_comments.json → commit_comments.json} +0 -0
  47. data/spec/fixtures/{v3/commit_create.json → commit_create.json} +0 -0
  48. data/spec/fixtures/{v3/commits.json → commits.json} +0 -0
  49. data/spec/fixtures/{v3/compare.json → compare.json} +0 -0
  50. data/spec/fixtures/{v3/contents.json → contents.json} +0 -0
  51. data/spec/fixtures/{v3/contributors.json → contributors.json} +0 -0
  52. data/spec/fixtures/{v3/download.json → download.json} +0 -0
  53. data/spec/fixtures/{v3/download_create.json → download_create.json} +0 -0
  54. data/spec/fixtures/{v3/downloads.json → downloads.json} +0 -0
  55. data/spec/fixtures/{v3/emails.json → emails.json} +0 -0
  56. data/spec/fixtures/{v3/emojis.json → emojis.json} +0 -0
  57. data/spec/fixtures/{v3/followers.json → followers.json} +0 -0
  58. data/spec/fixtures/{v3/following.json → following.json} +0 -0
  59. data/spec/fixtures/{v3/forks.json → forks.json} +0 -0
  60. data/spec/fixtures/{v3/gist.json → gist.json} +0 -0
  61. data/spec/fixtures/{v3/gist_comment.json → gist_comment.json} +0 -0
  62. data/spec/fixtures/{v3/gist_comment_create.json → gist_comment_create.json} +0 -0
  63. data/spec/fixtures/{v3/gist_comment_update.json → gist_comment_update.json} +0 -0
  64. data/spec/fixtures/{v3/gist_comments.json → gist_comments.json} +0 -0
  65. data/spec/fixtures/{v3/gists.json → gists.json} +0 -0
  66. data/spec/fixtures/{v3/hook.json → hook.json} +0 -0
  67. data/spec/fixtures/{v3/hooks.json → hooks.json} +0 -0
  68. data/spec/fixtures/{v3/issue.json → issue.json} +0 -0
  69. data/spec/fixtures/{v3/issue_closed.json → issue_closed.json} +0 -0
  70. data/spec/fixtures/{v3/issue_event.json → issue_event.json} +0 -0
  71. data/spec/fixtures/{v3/issue_events.json → issue_events.json} +0 -0
  72. data/spec/fixtures/issue_full.json +38 -0
  73. data/spec/fixtures/{v3/issues.json → issues.json} +0 -0
  74. data/spec/fixtures/{v3/label.json → label.json} +0 -0
  75. data/spec/fixtures/{v3/labels.json → labels.json} +0 -0
  76. data/spec/fixtures/{v3/languages.json → languages.json} +0 -0
  77. data/spec/fixtures/{v3/list_commit_comments.json → list_commit_comments.json} +0 -0
  78. data/spec/fixtures/{v3/markdown_gfm → markdown_gfm} +0 -0
  79. data/spec/fixtures/{v3/merge.json → merge.json} +0 -0
  80. data/spec/fixtures/{v3/milestone.json → milestone.json} +0 -0
  81. data/spec/fixtures/{v3/milestones.json → milestones.json} +0 -0
  82. data/spec/fixtures/{v3/not_found.json → not_found.json} +0 -0
  83. data/spec/fixtures/notification_thread.json +32 -0
  84. data/spec/fixtures/notifications.json +32 -0
  85. data/spec/fixtures/{v3/organization-repositories.json → organization-repositories.json} +0 -0
  86. data/spec/fixtures/{v3/organization-repository.json → organization-repository.json} +0 -0
  87. data/spec/fixtures/{v3/organization.json → organization.json} +0 -0
  88. data/spec/fixtures/{v3/organization_members.json → organization_members.json} +0 -0
  89. data/spec/fixtures/{v3/organization_team_members.json → organization_team_members.json} +0 -0
  90. data/spec/fixtures/{v3/organization_team_repos.json → organization_team_repos.json} +0 -0
  91. data/spec/fixtures/{v3/organizations.json → organizations.json} +0 -0
  92. data/spec/fixtures/{v3/public_events.json → public_events.json} +0 -0
  93. data/spec/fixtures/{v3/public_gists.json → public_gists.json} +0 -0
  94. data/spec/fixtures/{v3/public_key.json → public_key.json} +0 -0
  95. data/spec/fixtures/public_key_update.json +5 -0
  96. data/spec/fixtures/{v3/public_keys.json → public_keys.json} +0 -0
  97. data/spec/fixtures/{v3/pull_created.json → pull_created.json} +0 -0
  98. data/spec/fixtures/{v3/pull_request.json → pull_request.json} +0 -0
  99. data/spec/fixtures/pull_request_comment.json +35 -0
  100. data/spec/fixtures/pull_request_comment_create.json +35 -0
  101. data/spec/fixtures/pull_request_comment_reply.json +35 -0
  102. data/spec/fixtures/pull_request_comment_update.json +35 -0
  103. data/spec/fixtures/{v3/pull_request_comments.json → pull_request_comments.json} +0 -0
  104. data/spec/fixtures/{v3/pull_request_commits.json → pull_request_commits.json} +0 -0
  105. data/spec/fixtures/{v3/pull_request_files.json → pull_request_files.json} +0 -0
  106. data/spec/fixtures/{v3/pull_request_merged.json → pull_request_merged.json} +0 -0
  107. data/spec/fixtures/{v3/pull_requests.json → pull_requests.json} +0 -0
  108. data/spec/fixtures/{v3/pull_update.json → pull_update.json} +0 -0
  109. data/spec/fixtures/{v3/readme.json → readme.json} +0 -0
  110. data/spec/fixtures/{v3/ref.json → ref.json} +0 -0
  111. data/spec/fixtures/{v3/ref_create.json → ref_create.json} +0 -0
  112. data/spec/fixtures/{v3/ref_update.json → ref_update.json} +0 -0
  113. data/spec/fixtures/{v3/refs.json → refs.json} +0 -0
  114. data/spec/fixtures/{v3/refs_tags.json → refs_tags.json} +0 -0
  115. data/spec/fixtures/{v3/repo_assignees.json → repo_assignees.json} +0 -0
  116. data/spec/fixtures/{v3/repo_events.json → repo_events.json} +0 -0
  117. data/spec/fixtures/{v3/repo_issues_events.json → repo_issues_events.json} +0 -0
  118. data/spec/fixtures/{v3/repositories.json → repositories.json} +0 -0
  119. data/spec/fixtures/{v3/repository.json → repository.json} +0 -0
  120. data/spec/fixtures/repository_notifications.json +32 -0
  121. data/spec/fixtures/say.txt +22 -0
  122. data/spec/fixtures/say_custom.txt +22 -0
  123. data/spec/fixtures/{v3/stargazers.json → stargazers.json} +0 -0
  124. data/spec/fixtures/{v3/starred.json → starred.json} +0 -0
  125. data/spec/fixtures/{v3/starred_gists.json → starred_gists.json} +0 -0
  126. data/spec/fixtures/{v3/status.json → status.json} +0 -0
  127. data/spec/fixtures/{v3/statuses.json → statuses.json} +0 -0
  128. data/spec/fixtures/subscribers.json +9 -0
  129. data/spec/fixtures/subscription.json +8 -0
  130. data/spec/fixtures/subscription_update.json +8 -0
  131. data/spec/fixtures/subscriptions.json +39 -0
  132. data/spec/fixtures/{v3/tag.json → tag.json} +0 -0
  133. data/spec/fixtures/{v3/tag_create.json → tag_create.json} +0 -0
  134. data/spec/fixtures/{v3/tags.json → tags.json} +0 -0
  135. data/spec/fixtures/{v3/team.json → team.json} +0 -0
  136. data/spec/fixtures/{v3/teams.json → teams.json} +0 -0
  137. data/spec/fixtures/thread_subscription.json +8 -0
  138. data/spec/fixtures/thread_subscription_update.json +8 -0
  139. data/spec/fixtures/{v3/tree.json → tree.json} +0 -0
  140. data/spec/fixtures/{v3/tree_create.json → tree_create.json} +0 -0
  141. data/spec/fixtures/{v3/user.json → user.json} +0 -0
  142. data/spec/fixtures/{v3/user_events.json → user_events.json} +0 -0
  143. data/spec/fixtures/validation_failed.json +11 -0
  144. data/spec/fixtures/{v3/watched.json → watched.json} +0 -0
  145. data/spec/fixtures/{v3/watchers.json → watchers.json} +0 -0
  146. data/spec/helper.rb +13 -2
  147. data/spec/octokit/client/authorizations_spec.rb +44 -7
  148. data/spec/octokit/client/commits_spec.rb +136 -11
  149. data/spec/octokit/client/contents_spec.rb +6 -3
  150. data/spec/octokit/client/downloads_spec.rb +5 -6
  151. data/spec/octokit/client/emojis_spec.rb +1 -1
  152. data/spec/octokit/client/events_spec.rb +5 -5
  153. data/spec/octokit/client/gists_spec.rb +20 -20
  154. data/spec/octokit/client/issue_events_spec.rb +2 -2
  155. data/spec/octokit/client/issues_spec.rb +25 -14
  156. data/spec/octokit/client/labels_spec.rb +18 -22
  157. data/spec/octokit/client/markdown_spec.rb +1 -1
  158. data/spec/octokit/client/milestones_spec.rb +8 -8
  159. data/spec/octokit/client/notifications_spec.rb +141 -0
  160. data/spec/octokit/client/objects_spec.rb +6 -6
  161. data/spec/octokit/client/organizations_spec.rb +65 -13
  162. data/spec/octokit/client/pub_sub_hubbub/service_hooks_spec.rb +4 -4
  163. data/spec/octokit/client/pub_sub_hubbub_spec.rb +3 -3
  164. data/spec/octokit/client/pulls_spec.rb +81 -10
  165. data/spec/octokit/client/refs_spec.rb +7 -7
  166. data/spec/octokit/client/repositories_spec.rb +86 -34
  167. data/spec/octokit/client/say_spec.rb +37 -0
  168. data/spec/octokit/client/statuses_spec.rb +2 -2
  169. data/spec/octokit/client/users_spec.rb +65 -16
  170. data/spec/octokit/client_spec.rb +37 -11
  171. data/spec/{repository_spec.rb → octokit/repository_spec.rb} +0 -0
  172. data/spec/octokit_spec.rb +1 -1
  173. metadata +240 -196
@@ -0,0 +1,14 @@
1
+ module Octokit
2
+ class Client
3
+ module Say
4
+
5
+ def say(text=nil)
6
+ options = {}
7
+ options[:s] = text if text
8
+ get "/octocat", options
9
+ end
10
+ alias :octocat :say
11
+
12
+ end
13
+ end
14
+ end
@@ -9,7 +9,7 @@ module Octokit
9
9
  # @return [Array] A list of statuses
10
10
  # @see http://developer.github.com/v3/repos/status
11
11
  def statuses(repo, sha, options={})
12
- get("repos/#{Repository.new(repo)}/statuses/#{sha}", options, 3)
12
+ get("repos/#{Repository.new(repo)}/statuses/#{sha}", options)
13
13
  end
14
14
  alias :list_statuses :statuses
15
15
 
@@ -22,7 +22,7 @@ module Octokit
22
22
  # @see http://developer.github.com/v3/repos/status
23
23
  def create_status(repo, sha, state, options={})
24
24
  options.merge!(:state => state)
25
- post("repos/#{Repository.new(repo)}/statuses/#{sha}", options, 3)
25
+ post("repos/#{Repository.new(repo)}/statuses/#{sha}", options)
26
26
  end
27
27
  end
28
28
  end
@@ -1,9 +1,5 @@
1
1
  module Octokit
2
2
  class Client
3
- #@todo Add support for getting a single public key by id.
4
- # http://developer.github.com/v3/users/keys/#get-a-single-public-key
5
- #@todo Add support for updating a public key.
6
- # http://developer.github.com/v3/users/keys/#update-a-public-key
7
3
  module Users
8
4
 
9
5
  # Search for user.
@@ -14,7 +10,7 @@ module Octokit
14
10
  # @example
15
11
  # Octokit.search_users('pengwynn')
16
12
  def search_users(search, options={})
17
- get("legacy/user/search/#{search}", options, 3)['users']
13
+ get("legacy/user/search/#{search}", options)['users']
18
14
  end
19
15
 
20
16
  # Get a single user
@@ -26,9 +22,23 @@ module Octokit
26
22
  # Octokit.user("sferik")
27
23
  def user(user=nil)
28
24
  if user
29
- get("users/#{user}", {}, 3)
25
+ get "users/#{user}", {}
30
26
  else
31
- get("user", {}, 3)
27
+ get "user", {}
28
+ end
29
+ end
30
+
31
+ # Validate user username and password
32
+ #
33
+ # @param options [Hash] User credentials
34
+ # @option options [String] :login GitHub login
35
+ # @option options [String] :password GitHub password
36
+ # @return [Boolean] True if credentials are valid
37
+ def validate_credentials(options = {})
38
+ begin
39
+ !self.class.new(options).user.nil?
40
+ rescue Octokit::Unauthorized
41
+ false
32
42
  end
33
43
  end
34
44
 
@@ -46,7 +56,7 @@ module Octokit
46
56
  # @example
47
57
  # Octokit.user(:name => "Erik Michaels-Ober", :email => "sferik@gmail.com", :company => "Code for America", :location => "San Francisco", :hireable => false)
48
58
  def update_user(options)
49
- patch("user", options, 3)
59
+ patch("user", options)
50
60
  end
51
61
 
52
62
  # Get a user's followers.
@@ -57,7 +67,7 @@ module Octokit
57
67
  # @example
58
68
  # Octokit.followers('pengwynn')
59
69
  def followers(user=login, options={})
60
- get("users/#{user}/followers", options, 3)
70
+ get("users/#{user}/followers", options)
61
71
  end
62
72
 
63
73
  # Get list of users a user is following.
@@ -68,13 +78,13 @@ module Octokit
68
78
  # @example
69
79
  # Octokit.following('pengwynn')
70
80
  def following(user=login, options={})
71
- get("users/#{user}/following", options, 3)
81
+ get("users/#{user}/following", options)
72
82
  end
73
83
 
74
84
  # Check if you are following a user.
75
85
  #
76
86
  # Requries an authenticated client.
77
- #
87
+ #
78
88
  # @param user [String] Username of the user that you want to check if you are following.
79
89
  # @return [Boolean] True if you are following the user, false otherwise.
80
90
  # @see Octokit::Client
@@ -86,7 +96,7 @@ module Octokit
86
96
  user = args.first
87
97
  user ||= login
88
98
  return if user.nil?
89
- get("user/following/#{target}", {}, 3, true, raw=true).status == 204
99
+ request(:get, "user/following/#{target}").status == 204
90
100
  rescue Octokit::NotFound
91
101
  false
92
102
  end
@@ -102,7 +112,7 @@ module Octokit
102
112
  # @example
103
113
  # @client.follow('holman')
104
114
  def follow(user, options={})
105
- put("user/following/#{user}", options, 3, true, raw=true).status == 204
115
+ request(:put, "user/following/#{user}", options).status == 204
106
116
  end
107
117
 
108
118
  # Unfollow a user.
@@ -116,7 +126,7 @@ module Octokit
116
126
  # @example
117
127
  # @client.unfollow('holman')
118
128
  def unfollow(user, options={})
119
- delete("user/following/#{user}", options, 3, true, raw=true).status == 204
129
+ request(:delete, "user/following/#{user}", options).status == 204
120
130
  end
121
131
 
122
132
  # Get list of repos starred by a user.
@@ -127,7 +137,7 @@ module Octokit
127
137
  # @example
128
138
  # Octokit.starred('pengwynn')
129
139
  def starred(user=login, options={})
130
- get("users/#{user}/starred", options, 3)
140
+ get("users/#{user}/starred", options)
131
141
  end
132
142
 
133
143
  # Check if you are starring a repo.
@@ -142,13 +152,13 @@ module Octokit
142
152
  # @example
143
153
  # @client.starred?('pengwynn', 'octokit')
144
154
  def starred?(user, repo, options={})
145
- get("user/starred/#{user}/#{repo}", options, 3, true, raw=true).status == 204
155
+ request(:get, "user/starred/#{user}/#{repo}", options).status == 204
146
156
  rescue Octokit::NotFound
147
157
  false
148
158
  end
149
159
 
150
160
  # Get list of repos watched by a user.
151
- #
161
+ #
152
162
  # Legacy, using github.beta media type. Use `Users#starred` instead.
153
163
  #
154
164
  # @param user [String] Username of the user to get the list of repositories they are watching.
@@ -158,7 +168,34 @@ module Octokit
158
168
  # @example
159
169
  # Octokit.watched('pengwynn')
160
170
  def watched(user=login, options={})
161
- get("users/#{user}/watched", options, 3)
171
+ get("users/#{user}/watched", options)
172
+ end
173
+
174
+ # Get a public key.
175
+ #
176
+ # Note, when using dot notation to retrieve the values, ruby will return
177
+ # the hash key for the public keys value instead of the actual value, use
178
+ # symbol or key string to retrieve the value. See example.
179
+ #
180
+ # Requires authenticated client.
181
+ #
182
+ # @param key_id [Integer] Key to retreive.
183
+ # @param [Hashie::Mash] Hash representing the key.
184
+ # @see http://developer.github.com/v3/users/keys/#get-a-single-public-key
185
+ # @example
186
+ # @client.key(1)
187
+ # @example Retrieve public key contents
188
+ # public_key = @client.key(1)
189
+ # public_key.key
190
+ # # => Error
191
+ #
192
+ # public_key[:key]
193
+ # # => "ssh-rsa AAA..."
194
+ #
195
+ # public_key['key']
196
+ # # => "ssh-rsa AAA..."
197
+ def key(key_id, options={})
198
+ get("user/keys/#{key_id}", options)
162
199
  end
163
200
 
164
201
  # Get list of public keys for user.
@@ -171,7 +208,7 @@ module Octokit
171
208
  # @example
172
209
  # @client.keys
173
210
  def keys(options={})
174
- get("user/keys", options, 3)
211
+ get("user/keys", options)
175
212
  end
176
213
 
177
214
  # Add public key to user account.
@@ -186,7 +223,23 @@ module Octokit
186
223
  # @example
187
224
  # @client.add_key('Personal projects key', 'ssh-rsa AAA...')
188
225
  def add_key(title, key, options={})
189
- post("user/keys", options.merge({:title => title, :key => key}), 3)
226
+ post("user/keys", options.merge({:title => title, :key => key}))
227
+ end
228
+
229
+ # Update a public key
230
+ #
231
+ # Requires authenticated client
232
+ #
233
+ # @param key_id [Integer] Id of key to update.
234
+ # @param options [Hash] Hash containing attributes to update.
235
+ # @option options [String] :title
236
+ # @option options [String] :key
237
+ # @return [Hashie::Mash] Hash representing the updated public key.
238
+ # @see http://developer.github.com/v3/users/keys/#update-a-public-key
239
+ # @example
240
+ # @client.update_key(1, :title => 'new title', :key => "ssh-rsa BBB")
241
+ def update_key(key_id, options={})
242
+ patch("/user/keys/#{key_id}", options)
190
243
  end
191
244
 
192
245
  # Remove a public key from user account.
@@ -200,7 +253,7 @@ module Octokit
200
253
  # @example
201
254
  # @client.remove_key(1)
202
255
  def remove_key(id, options={})
203
- delete("user/keys/#{id}", options, 3, true, raw=true).status == 204
256
+ request(:delete, "user/keys/#{id}", options).status == 204
204
257
  end
205
258
 
206
259
  # List email addresses for a user.
@@ -213,7 +266,7 @@ module Octokit
213
266
  # @example
214
267
  # @client.emails
215
268
  def emails(options={})
216
- get("user/emails", options, 3)
269
+ get("user/emails", options)
217
270
  end
218
271
 
219
272
  # Add email address to user.
@@ -227,7 +280,7 @@ module Octokit
227
280
  # @example
228
281
  # @client.add_email('new_email@user.com')
229
282
  def add_email(email, options={})
230
- post("user/emails", options.merge({:email => email}), 3)
283
+ post("user/emails", options.merge({:email => email}))
231
284
  end
232
285
 
233
286
  # Remove email from user.
@@ -241,8 +294,23 @@ module Octokit
241
294
  # @example
242
295
  # @client.remove_email('old_email@user.com')
243
296
  def remove_email(email, options={})
244
- delete("user/emails", options.merge({:email => email}), 3, true, raw=true).status == 204
297
+ request(:delete, "user/emails", options.merge({:email => email})).status == 204
298
+ end
299
+
300
+ # List repositories being watched by a user.
301
+ #
302
+ # @param user [String] User's GitHub username.
303
+ #
304
+ # @return [Array<Hashie::Mashie>] Array of repositories.
305
+ #
306
+ # @see http://developer.github.com/v3/activity/watching/#list-repositories-being-watched
307
+ #
308
+ # @example
309
+ # @client.subscriptions("pengwynn")
310
+ def subscriptions(user=login, options={})
311
+ get("users/#{user}/subscriptions", options)
245
312
  end
313
+
246
314
  end
247
315
  end
248
316
  end
@@ -6,43 +6,43 @@ module Octokit
6
6
  module Connection
7
7
  private
8
8
 
9
- def connection(authenticate=true, raw=false, version=3, force_urlencoded=false)
10
- case version
11
- when 3
12
- url = Octokit.api_endpoint
13
- end
14
-
9
+ def connection(options={})
15
10
  options = {
11
+ :authenticate => true,
12
+ :force_urlencoded => false,
13
+ :raw => false,
16
14
  :ssl => { :verify => false },
17
- :url => url,
18
- }
15
+ :url => Octokit.api_endpoint
16
+ }.merge(options)
19
17
 
20
- options[:proxy] = proxy unless proxy.nil?
18
+ if !proxy.nil?
19
+ options.merge!(:proxy => proxy)
20
+ end
21
21
 
22
- options.merge!(:params => {:access_token => oauth_token}) if oauthed? && !authenticated?
23
- options.merge!(:params => unauthed_rate_limit_params) if !oauthed? && !authenticated? && unauthed_rate_limited?
22
+ if !oauthed? && !authenticated? && unauthed_rate_limited?
23
+ options.merge!(:params => unauthed_rate_limit_params)
24
+ end
24
25
 
25
26
  # TODO: Don't build on every request
26
27
  connection = Faraday.new(options) do |builder|
27
- if version >= 3 && !force_urlencoded
28
- builder.request :json
29
- else
30
- builder.request :url_encoded
31
- end
28
+
29
+ builder.request :json
32
30
 
33
31
  builder.use Faraday::Response::RaiseOctokitError
32
+ builder.use FaradayMiddleware::FollowRedirects
33
+ builder.use FaradayMiddleware::Mashify
34
34
 
35
- unless raw
36
- builder.use FaradayMiddleware::Mashify
37
- builder.use FaradayMiddleware::ParseJson
38
- end
35
+ builder.use FaradayMiddleware::ParseJson, :content_type => /\bjson$/
39
36
 
40
37
  faraday_config_block.call(builder) if faraday_config_block
41
38
 
42
39
  builder.adapter *adapter
43
40
  end
44
41
 
45
- connection.basic_auth authentication[:login], authentication[:password] if authenticate and authenticated?
42
+ if options[:authenticate] and authenticated?
43
+ connection.basic_auth authentication[:login], authentication[:password]
44
+ end
45
+
46
46
  connection
47
47
  end
48
48
  end
@@ -2,69 +2,79 @@ require 'multi_json'
2
2
 
3
3
  module Octokit
4
4
  module Request
5
- def delete(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false)
6
- request(:delete, path, options, version, authenticate, raw, force_urlencoded)
7
- end
8
5
 
9
- def get(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false)
10
- request(:get, path, options, version, authenticate, raw, force_urlencoded)
6
+ def delete(path, options={})
7
+ request(:delete, path, options).body
11
8
  end
12
9
 
13
- def patch(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false)
14
- request(:patch, path, options, version, authenticate, raw, force_urlencoded)
15
- end
10
+ def get(path, options={})
11
+ response = request(:get, path, options)
12
+ body = response.body
13
+
14
+ if auto_traversal && body.is_a?(Array)
15
+ while next_url = links(response)["next"]
16
+ response = request(:get, next_url, options)
17
+ body += response.body
18
+ end
19
+ end
16
20
 
17
- def post(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false)
18
- request(:post, path, options, version, authenticate, raw, force_urlencoded)
21
+ body
19
22
  end
20
23
 
21
- def put(path, options={}, version=api_version, authenticate=true, raw=false, force_urlencoded=false)
22
- request(:put, path, options, version, authenticate, raw, force_urlencoded)
24
+ def patch(path, options={})
25
+ request(:patch, path, options).body
23
26
  end
24
27
 
25
- def ratelimit
26
- headers = get("rate_limit",{}, api_version, true, true).headers
27
- return headers["X-RateLimit-Limit"].to_i
28
+ def post(path, options={})
29
+ request(:post, path, options).body
28
30
  end
29
- alias rate_limit ratelimit
30
31
 
31
- def ratelimit_remaining
32
- headers = get("rate_limit",{}, api_version, true, true).headers
33
- return headers["X-RateLimit-Remaining"].to_i
32
+ def put(path, options={})
33
+ request(:put, path, options).body
34
34
  end
35
- alias rate_limit_remaining ratelimit_remaining
36
35
 
37
36
  private
38
37
 
39
- def request(method, path, options, version, authenticate, raw, force_urlencoded)
38
+ def request(method, path, options={})
40
39
  path.sub(%r{^/}, '') #leading slash in path fails in github:enterprise
41
- response = connection(authenticate, raw, version, force_urlencoded).send(method) do |request|
40
+
41
+ token = options.delete(:access_token) ||
42
+ options.delete(:oauth_token) ||
43
+ oauth_token
44
+
45
+ conn_options = {
46
+ :authenticate => token.nil?
47
+ }
48
+
49
+ response = connection(conn_options).send(method) do |request|
50
+
51
+ request.headers['Accept'] = options.delete(:accept) || 'application/vnd.github.beta+json'
52
+
53
+ if token
54
+ request.headers[:authorization] = "token #{token}"
55
+ end
56
+
42
57
  case method
43
- when :delete, :get
58
+ when :get
44
59
  if auto_traversal && per_page.nil?
45
60
  self.per_page = 100
46
61
  end
47
62
  options.merge!(:per_page => per_page) if per_page
48
63
  request.url(path, options)
64
+ when :delete, :head
65
+ request.url(path, options)
49
66
  when :patch, :post, :put
50
67
  request.path = path
51
- if 3 == version && !force_urlencoded
52
- request.body = MultiJson.dump(options) unless options.empty?
53
- else
54
- request.body = options unless options.empty?
55
- end
68
+ request.body = MultiJson.dump(options) unless options.empty?
56
69
  end
57
70
 
58
- request.headers['Host'] = Octokit.request_host if Octokit.request_host
59
- end
71
+ if Octokit.request_host
72
+ request.headers['Host'] = Octokit.request_host
73
+ end
60
74
 
61
- if raw
62
- response
63
- elsif auto_traversal && ( next_url = links(response)["next"] )
64
- response.body + request(method, next_url, options, version, authenticate, raw, force_urlencoded)
65
- else
66
- response.body
67
75
  end
76
+
77
+ response
68
78
  end
69
79
 
70
80
  def links(response)
@@ -75,5 +85,6 @@ module Octokit
75
85
 
76
86
  Hash[ *links.flatten ]
77
87
  end
88
+
78
89
  end
79
90
  end