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
data/.document CHANGED
@@ -2,4 +2,4 @@ lib/**/*.rb
2
2
  bin/*
3
3
  features/**/*.feature
4
4
  -
5
- LICENSE
5
+ LICENSE.md
data/.rspec CHANGED
@@ -1,2 +1,3 @@
1
1
  --color
2
+ --fail-fast
2
3
  --order random
data/CHANGELOG.md CHANGED
@@ -1,5 +1,27 @@
1
1
  # CHANGELOG
2
2
 
3
+ # 1.19.0
4
+
5
+ This version has some substantial rewiring internally to support non-JSON
6
+ [media types][media-types]:
7
+
8
+ ```ruby
9
+ Octokit.contents 'pengwynn/octokit', :path => 'README.md', :accept => 'application/vnd.github.html'
10
+ ```
11
+
12
+ Additionally, all methods that return empty body responses for `GET`, `DELETE`,
13
+ and `PUT`, return a Boolean instead of raw HTTP Response or status code.
14
+
15
+ This version also introduces a couple of new methods:
16
+
17
+ * `scopes`: Check the scopes on an OAuth token
18
+ * `octocat`: Your daily dose of GitHub API Zen.
19
+
20
+ View [the full changelog][1.19.0].
21
+ [1.19.0]: https://github.com/pengwynn/octokit/compare/v1.18.0...v1.19.0
22
+
23
+ ## Previous versions
24
+
3
25
  * [1.18.0 - October 15, 2012](https://github.com/pengwynn/octokit/compare/v1.17.1...v1.18.0)
4
26
  * [1.17.1 - October 11, 2012](https://github.com/pengwynn/octokit/compare/v1.17.0...v1.17.1)
5
27
  * [1.17.0 - October 8, 2012](https://github.com/pengwynn/octokit/compare/v1.16.0...v1.17.0)
@@ -53,3 +75,6 @@
53
75
  * [0.1.1 - December 15, 2009](https://github.com/pengwynn/octokit/compare/v0.1.0...v0.1.1)
54
76
  * [0.1.0 - December 12, 2009](https://github.com/pengwynn/octokit/compare/v0.0.1...v0.1.0)
55
77
  * [0.0.1 - December 12, 2009](https://github.com/pengwynn/octokit/compare/cb7d5480944229e1a5ddfa9d1113903628765584...v0.0.1)
78
+
79
+
80
+ [media-types]: http://developer.github.com/v3/media/
File without changes
data/README.md CHANGED
@@ -31,21 +31,27 @@ For convenience, methods that require a repository argument may be passed in
31
31
  any of the following forms:
32
32
 
33
33
  ```ruby
34
- # String
35
34
  Octokit.repo("pengwynn/octokit")
36
35
 
37
- # Hash
38
36
  Octokit.repo({:username => "pengwynn", :name => "octokit"})
39
37
 
40
- # or
41
38
  Octokit.repo({:username => "pengwynn", :repo => "octokit"})
42
39
 
43
- # Instance of Repository
44
40
  Octokit.repo(Repository.new('pengwynn/octokit'))
45
41
 
46
42
  => <#Hashie::Rash created_at="2009/12/10 13:41:49 -0800" description="Simple Ruby wrapper for the GitHub API and feeds" fork=false forks=25 has_downloads=true has_issues=true has_wiki=true homepage="http://wynnnetherland.com/projects/octokit" integrate_branch="master" language="Ruby" name="octokit" open_issues=8 owner="pengwynn" private=false pushed_at="2011/05/05 10:48:57 -0700" size=1804 url="https://github.com/pengwynn/octokit" watchers=92>
47
43
  ```
48
44
 
45
+ ### List the commits for a repository
46
+
47
+ ```ruby
48
+ Octokit.commits("pengwynn/octokit")
49
+
50
+ Octokit.list_commits("pengwynn/octokit")
51
+
52
+ => [#<Hashie::Mash author=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> commit=#<Hashie::Mash author=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> comment_count=0 committer=#<Hashie::Mash date="2012-10-31T15:17:51Z" email="wynn@github.com" name="Wynn Netherland"> message="Fix bug with archive_link for private repo" tree=#<Hashie::Mash sha="49bf2a476aa819f29b0fc1a8805f7567f010006d" url="https://api.github.com/repos/pengwynn/octokit/git/trees/49bf2a476aa819f29b0fc1a8805f7567f010006d"> url="https://api.github.com/repos/pengwynn/octokit/git/commits/8db3df37fad3a021eb8036b007c718149836cb32"> committer=#<Hashie::Mash avatar_url="https://secure.gravatar.com/avatar/7e19cd5486b5d6dc1ef90e671ba52ae0?d=https://a248.e.akamai.net/assets.github.com%2Fimages%2Fgravatars%2Fgravatar-user-420.png" gravatar_id="7e19cd5486b5d6dc1ef90e671ba52ae0" id=865 login="pengwynn" url="https://api.github.com/users/pengwynn"> parents=[#<Hashie::Mash sha="7a67f4b47791cb77de33e491df87cef06012c79f" url="https://api.github.com/repos/pengwynn/octokit/commits/7a67f4b47791cb77de33e491df87cef06012c79f">] sha="8db3df37fad3a021eb8036b007c718149836cb32" url="https://api.github.com/repos/pengwynn/octokit/commits/8db3df37fad3a021eb8036b007c718149836cb32">, ... , ...]
53
+ ```
54
+
49
55
  ## Authenticated Requests
50
56
  For methods that require authentication, you'll need to setup a client with
51
57
  your login and password.
@@ -55,15 +61,22 @@ client = Octokit::Client.new(:login => "me", :password => "sekret")
55
61
  client.follow("sferik")
56
62
  ```
57
63
 
58
- Alternately, you can authenticate with a GitHub OAuth2 token. Note: this is
59
- **NOT** the GitHub API token on your [account page][account].
64
+ Alternately, you can authenticate with a [GitHub OAuth2 token][oauth].
60
65
 
61
- [account]: https://github.com/account
62
66
  ```ruby
63
67
  client = Octokit::Client.new(:login => "me", :oauth_token => "oauth2token")
64
68
  client.follow("sferik")
65
69
  ```
66
70
 
71
+ ## Requesting a specific media type
72
+
73
+ You can pass an `:accept` option value to request a particular [media
74
+ type][media-types].
75
+
76
+ ```ruby
77
+ Octokit.contents 'pengwynn/octokit', :path => 'README.md', :accept => 'application/vnd.github.html'
78
+ ```
79
+
67
80
  ## Using with GitHub Enterprise
68
81
 
69
82
  To use with [GitHub Enterprise](https://enterprise.github.com/), you'll need to
@@ -133,6 +146,8 @@ contributors:
133
146
 
134
147
  * [Erik Michaels-Ober](http://github.com/sferik)
135
148
  * [Clint Shryock](http://github.com/ctshryock)
149
+ * [Joey Wendt](http://github.com/joeyw)
150
+
136
151
 
137
152
  ## Inspiration
138
153
  Octokit was inspired by [Octopi][] and aims to be a lightweight,
@@ -144,4 +159,6 @@ less-ActiveResourcey alternative.
144
159
  Copyright (c) 2011 Wynn Netherland, Adam Stacoviak, Erik Michaels-Ober. See
145
160
  [LICENSE][] for details.
146
161
 
147
- [license]: https://github.com/pengwynn/octokit/blob/master/LICENSE
162
+ [license]: https://github.com/pengwynn/octokit/blob/master/LICENSE.md
163
+ [media-types]: http://developer.github.com/v3/media/
164
+ [oauth]: http://developer.github.com/v3/oauth
@@ -38,7 +38,10 @@ module Faraday
38
38
  else
39
39
  ''
40
40
  end
41
- "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}"
41
+ errors = unless message.empty?
42
+ body[:errors] ? ": #{body[:errors].map{|e|e[:message]}.join(', ')}" : ''
43
+ end
44
+ "#{response[:method].to_s.upcase} #{response[:url].to_s}: #{response[:status]}#{message}#{errors}"
42
45
  end
43
46
  end
44
47
  end
@@ -18,12 +18,15 @@ require 'octokit/client/pulls'
18
18
  require 'octokit/client/repositories'
19
19
  require 'octokit/client/users'
20
20
  require 'octokit/client/events'
21
+ require 'octokit/client/notifications'
21
22
  require 'octokit/client/authorizations'
22
23
  require 'octokit/client/refs'
23
24
  require 'octokit/client/contents'
24
25
  require 'octokit/client/markdown'
25
26
  require 'octokit/client/emojis'
26
27
  require 'octokit/client/statuses'
28
+ require 'octokit/client/say'
29
+ require 'octokit/client/rate_limit'
27
30
 
28
31
  module Octokit
29
32
  class Client
@@ -54,11 +57,14 @@ module Octokit
54
57
  include Octokit::Client::Repositories
55
58
  include Octokit::Client::Users
56
59
  include Octokit::Client::Events
60
+ include Octokit::Client::Notifications
57
61
  include Octokit::Client::Authorizations
58
62
  include Octokit::Client::Refs
59
63
  include Octokit::Client::Contents
60
64
  include Octokit::Client::Markdown
61
65
  include Octokit::Client::Emojis
62
66
  include Octokit::Client::Statuses
67
+ include Octokit::Client::Say
68
+ include Octokit::Client::RateLimit
63
69
  end
64
70
  end
@@ -13,8 +13,8 @@ module Octokit
13
13
  # @example List authorizations for user ctshryock
14
14
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
15
15
  # client.authorizations
16
- def authorizations
17
- get('authorizations')
16
+ def authorizations(options={})
17
+ get 'authorizations', options
18
18
  end
19
19
 
20
20
 
@@ -28,8 +28,8 @@ module Octokit
28
28
  # @example Show authorization for user ctshryock's Travis auth
29
29
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
30
30
  # client.authorization(999999)
31
- def authorization(number)
32
- get("authorizations/#{number}")
31
+ def authorization(number, options={})
32
+ get "authorizations/#{number}", options
33
33
  end
34
34
 
35
35
  # Create an authorization for the authenticated user.
@@ -87,13 +87,26 @@ module Octokit
87
87
  #
88
88
  # @param number [Number] An existing Authorization ID
89
89
  #
90
- # @return [Status] A raw status response
90
+ # @return [Boolean] Success
91
91
  # @see http://developer.github.com/v3/oauth/#delete-an-authorization
92
92
  # @example Delete an authorization
93
93
  # client = Octokit::Client.new(:login => 'ctshryock', :password => 'secret')
94
94
  # client.delete_authorization(999999)
95
- def delete_authorization(number)
96
- delete("authorizations/#{number}", {}, 3, true, true)
95
+ def delete_authorization(number, option={})
96
+ request(:delete, "authorizations/#{number}").status == 204
97
+ end
98
+
99
+ # Check scopes for a token
100
+ #
101
+ # @param token [String] GitHub OAuth token
102
+ # @return [Array<String>] OAuth scopes
103
+ # @see http://developer.github.com/v3/oauth/#scopes
104
+ def scopes(token=nil)
105
+ request(:get, "user", :access_token => token).
106
+ headers[:x_oauth_scopes].
107
+ split(',').
108
+ map(&:strip).
109
+ sort
97
110
  end
98
111
 
99
112
  end
@@ -1,3 +1,5 @@
1
+ require 'date'
2
+
1
3
  module Octokit
2
4
  class Client
3
5
  module Commits
@@ -13,7 +15,7 @@ module Octokit
13
15
  # @see http://developer.github.com/v3/repos/commits/
14
16
  def commits(repo, sha_or_branch="master", options={})
15
17
  params = { :sha => sha_or_branch, :per_page => 35 }
16
- get("repos/#{Repository.new(repo)}/commits", params.merge(options), 3)
18
+ get("repos/#{Repository.new(repo)}/commits", params.merge(options))
17
19
  end
18
20
  alias :list_commits :commits
19
21
 
@@ -24,7 +26,7 @@ module Octokit
24
26
  # @return [Hashie::Mash] A hash representing the commit
25
27
  # @see http://developer.github.com/v3/repos/commits/
26
28
  def commit(repo, sha, options={})
27
- get("repos/#{Repository.new(repo)}/commits/#{sha}", options, 3)
29
+ get("repos/#{Repository.new(repo)}/commits/#{sha}", options)
28
30
  end
29
31
 
30
32
  # Create a commit
@@ -49,7 +51,7 @@ module Octokit
49
51
  def create_commit(repo, message, tree, parents=nil, options={})
50
52
  params = { :message => message, :tree => tree }
51
53
  params[:parents] = [parents].flatten if parents
52
- post("repos/#{Repository.new(repo)}/git/commits", options.merge(params), 3)
54
+ post("repos/#{Repository.new(repo)}/git/commits", options.merge(params))
53
55
  end
54
56
 
55
57
  # List all commit comments
@@ -58,7 +60,7 @@ module Octokit
58
60
  # @return [Array] An array of hashes representing comments
59
61
  # @see http://developer.github.com/v3/repos/comments/
60
62
  def list_commit_comments(repo, options={})
61
- get("repos/#{Repository.new(repo)}/comments", options, 3)
63
+ get("repos/#{Repository.new(repo)}/comments", options)
62
64
  end
63
65
 
64
66
  # List comments for a single commit
@@ -68,7 +70,7 @@ module Octokit
68
70
  # @return [Array] An array of hashes representing comments
69
71
  # @see http://developer.github.com/v3/repos/comments/
70
72
  def commit_comments(repo, sha, options={})
71
- get("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options, 3)
73
+ get("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options)
72
74
  end
73
75
 
74
76
  # Get a single commit comment
@@ -78,7 +80,7 @@ module Octokit
78
80
  # @return [Hashie::Mash] A hash representing the comment
79
81
  # @see http://developer.github.com/v3/repos/comments/
80
82
  def commit_comment(repo, id, options={})
81
- get("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
83
+ get("repos/#{Repository.new(repo)}/comments/#{id}", options)
82
84
  end
83
85
 
84
86
  # Create a commit comment
@@ -106,7 +108,7 @@ module Octokit
106
108
  :line => line,
107
109
  :position => position
108
110
  }
109
- post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params), 3)
111
+ post("repos/#{Repository.new(repo)}/commits/#{sha}/comments", options.merge(params))
110
112
  end
111
113
 
112
114
  # Update a commit comment
@@ -124,7 +126,7 @@ module Octokit
124
126
  params = {
125
127
  :body => body
126
128
  }
127
- patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params), 3)
129
+ patch("repos/#{Repository.new(repo)}/comments/#{id}", options.merge(params))
128
130
  end
129
131
 
130
132
  # Delete a commit comment
@@ -134,18 +136,18 @@ module Octokit
134
136
  # @return [nil] nil
135
137
  # @see http://developer.github.com/v3/repos/comments/
136
138
  def delete_commit_comment(repo, id, options={})
137
- delete("repos/#{Repository.new(repo)}/comments/#{id}", options, 3)
139
+ request(:delete, "repos/#{Repository.new(repo)}/comments/#{id}", options).status == 204
138
140
  end
139
141
 
140
142
  # Compare two commits
141
143
  #
142
144
  # @param repo [String, Hash, Repository] A GitHub repository
143
- # @param base [String] The sha of the starting commit
144
- # @param end [String] The sha of the ending commit
145
+ # @param start [String] The sha of the starting commit
146
+ # @param endd [String] The sha of the ending commit
145
147
  # @return [Hashie::Mash] A hash representing the comparison
146
148
  # @see http://developer.github.com/v3/repos/commits/
147
149
  def compare(repo, start, endd, options={})
148
- get("repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options, 3)
150
+ get("repos/#{Repository.new(repo)}/compare/#{start}...#{endd}", options)
149
151
  end
150
152
 
151
153
  # Merge a branch or sha
@@ -161,9 +163,114 @@ module Octokit
161
163
  :base => base,
162
164
  :head => head
163
165
  }.merge(options)
164
- post("repos/#{Repository.new(repo)}/merges", params, 3)
166
+ post("repos/#{Repository.new(repo)}/merges", params)
167
+ end
168
+
169
+ # Get commits based on time windows
170
+
171
+ # Get commits after a specified date
172
+ #
173
+ # @param repo [String, Hash, Repository] A GitHub repository
174
+ # @param date [String] Date on which we want to compare
175
+ # @param sha_or_branch [String] Commit SHA or branch name from which to start the list
176
+ # @return [Array] An array of hashes representing commits
177
+ # @see http://developer.github.com/v3/repos/commits/
178
+ # @example
179
+ # Octokit.commits_since('pengwynn/octokit', '2012-10-01')
180
+ def commits_since(repo, date, sha_or_branch="master", options={})
181
+ begin
182
+ date = DateTime.parse(date)
183
+ rescue ArgumentError
184
+ raise ArgumentError, "#{date} is not a valid date"
185
+ end
186
+
187
+ params = {:since => iso8601(date) }
188
+ commits(repo, sha_or_branch, params.merge(options))
189
+ end
190
+
191
+ # Get commits before a specified date
192
+ #
193
+ # @param repo [String, Hash, Repository] A GitHub repository
194
+ # @param date [String] Date on which we want to compare
195
+ # @param sha_or_branch [String] Commit SHA or branch name from which to start the list
196
+ # @return [Array] An array of hashes representing commits
197
+ # @see http://developer.github.com/v3/repos/commits/
198
+ # @example
199
+ # Octokit.commits_before('pengwynn/octokit', '2012-10-01')
200
+ def commits_before(repo, date, sha_or_branch="master", options={})
201
+ begin
202
+ date = DateTime.parse(date)
203
+ rescue ArgumentError
204
+ raise ArgumentError, "#{date} is not a valid date"
205
+ end
206
+ params = {:until => iso8601(date)}
207
+ commits(repo, sha_or_branch, params.merge(options))
165
208
  end
166
209
 
210
+ # Get commits on a specified date
211
+ #
212
+ # @param repo [String, Hash, Repository] A GitHub repository
213
+ # @param date [String] Date on which we want to compare
214
+ # @param sha_or_branch [String] Commit SHA or branch name from which to start the list
215
+ # @return [Array] An array of hashes representing commits
216
+ # @see http://developer.github.com/v3/repos/commits/
217
+ # @example
218
+ # Octokit.commits_on('pengwynn/octokit', '2012-10-01')
219
+ def commits_on(repo, date, sha_or_branch="master", options={})
220
+ begin
221
+ # defaults to 00:00:00
222
+ start_date = DateTime.parse(date)
223
+ # addition defaults to n days
224
+ end_date = start_date + 1
225
+ rescue ArgumentError
226
+ raise ArgumentError, "#{date} is not a valid date"
227
+ end
228
+ params = { :since => iso8601(start_date), :until => iso8601(end_date) }
229
+ commits(repo, sha_or_branch, params.merge(options))
230
+ end
231
+
232
+ # Get commits made between two nominated dates
233
+ #
234
+ # @param repo [String, Hash, Repository] A GitHub repository
235
+ # @param start_date [String] Start Date on which we want to compare
236
+ # @param end_date [String] End Date on which we want to compare
237
+ # @param sha_or_branch [String] Commit SHA or branch name from which to start the list
238
+ # @return [Array] An array of hashes representing commits
239
+ # @see http://developer.github.com/v3/repos/commits/
240
+ # @example
241
+ # Octokit.commits_on('pengwynn/octokit', '2012-10-01', '2012-11-01')
242
+ def commits_between(repo, start_date, end_date, sha_or_branch="master", options={})
243
+ begin
244
+ # defaults to 00:00:00
245
+ # use a second var for the parsed date so error message is consistent
246
+ _start_date = DateTime.parse(start_date)
247
+ rescue ArgumentError
248
+ raise ArgumentError, "#{start_date} is not a valid date"
249
+ end
250
+ begin
251
+ # defaults to 00:00:00
252
+ # use a second var for the parsed date so error message is consistent
253
+ _end_date = DateTime.parse(end_date)
254
+ rescue ArgumentError
255
+ raise ArgumentError, "#{end_date} is not a valid date"
256
+ end
257
+ if _end_date < _start_date
258
+ raise ArgumentError, "Start date #{start_date} does not precede #{end_date}"
259
+ end
260
+ params = {:since => iso8601(_start_date),
261
+ :until => iso8601(_end_date) }
262
+ commits(repo, sha_or_branch, params.merge(options))
263
+ end
264
+
265
+ protected
266
+
267
+ def iso8601(date)
268
+ if date.respond_to?(:iso8601)
269
+ date.iso8601
270
+ else
271
+ date.strftime("%Y-%m-%dT%H:%M:%S%Z")
272
+ end
273
+ end
167
274
 
168
275
  end
169
276
  end
@@ -12,7 +12,7 @@ module Octokit
12
12
  # @example Get the readme file for a repo
13
13
  # Octokit.readme("pengwynn/octokit")
14
14
  def readme(repo, options={})
15
- get("repos/#{Repository.new repo}/readme", options, 3)
15
+ get("repos/#{Repository.new repo}/readme", options)
16
16
  end
17
17
 
18
18
  # Receive a listing of a repository folder or the contents of a file
@@ -27,7 +27,7 @@ module Octokit
27
27
  def contents(repo, options={})
28
28
  repo_path = options.delete :path
29
29
  url = "repos/#{Repository.new repo}/contents/#{repo_path}"
30
- get(url, options, 3)
30
+ get(url, options)
31
31
  end
32
32
 
33
33
  # This method will provide a URL to download a tarball or zipball archive for a repository.
@@ -43,8 +43,7 @@ module Octokit
43
43
  repo_ref = options.delete :ref
44
44
  format = (options.delete :format) || 'tarball'
45
45
  url = "repos/#{Repository.new repo}/#{format}/#{repo_ref}"
46
- headers = get(url, options, 3, false, true).headers
47
- return headers['location']
46
+ request(:head, url, options).env[:url].to_s
48
47
  end
49
48
  end
50
49
  end