github_api 0.9.0 → 0.9.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (163) hide show
  1. data/README.md +50 -5
  2. data/features/cassettes/git_data/commits/get.yml +69 -0
  3. data/features/git_data/commmits.feature +14 -0
  4. data/lib/github_api.rb +1 -0
  5. data/lib/github_api/activity/events.rb +42 -33
  6. data/lib/github_api/activity/notifications.rb +22 -22
  7. data/lib/github_api/activity/starring.rb +16 -21
  8. data/lib/github_api/activity/watching.rb +16 -19
  9. data/lib/github_api/api.rb +51 -8
  10. data/lib/github_api/arguments.rb +155 -0
  11. data/lib/github_api/authorizations.rb +19 -20
  12. data/lib/github_api/configuration.rb +5 -0
  13. data/lib/github_api/emojis.rb +3 -3
  14. data/lib/github_api/error/validations.rb +2 -2
  15. data/lib/github_api/gists.rb +32 -42
  16. data/lib/github_api/gists/comments.rb +21 -23
  17. data/lib/github_api/git_data/blobs.rb +13 -16
  18. data/lib/github_api/git_data/commits.rb +12 -10
  19. data/lib/github_api/git_data/references.rb +24 -28
  20. data/lib/github_api/git_data/tags.rb +9 -11
  21. data/lib/github_api/git_data/trees.rb +10 -13
  22. data/lib/github_api/gitignore.rb +4 -6
  23. data/lib/github_api/issues.rb +24 -32
  24. data/lib/github_api/issues/assignees.rb +11 -8
  25. data/lib/github_api/issues/comments.rb +21 -26
  26. data/lib/github_api/issues/events.rb +7 -9
  27. data/lib/github_api/issues/labels.rb +39 -53
  28. data/lib/github_api/issues/milestones.rb +26 -33
  29. data/lib/github_api/markdown.rb +5 -6
  30. data/lib/github_api/meta.rb +3 -3
  31. data/lib/github_api/orgs.rb +10 -11
  32. data/lib/github_api/orgs/members.rb +18 -20
  33. data/lib/github_api/orgs/teams.rb +54 -58
  34. data/lib/github_api/pull_requests.rb +40 -54
  35. data/lib/github_api/pull_requests/comments.rb +19 -26
  36. data/lib/github_api/repos.rb +146 -101
  37. data/lib/github_api/repos/collaborators.rb +29 -30
  38. data/lib/github_api/repos/comments.rb +20 -25
  39. data/lib/github_api/repos/commits.rb +12 -14
  40. data/lib/github_api/repos/contents.rb +22 -14
  41. data/lib/github_api/repos/downloads.rb +19 -23
  42. data/lib/github_api/repos/forks.rb +6 -11
  43. data/lib/github_api/repos/hooks.rb +25 -34
  44. data/lib/github_api/repos/keys.rb +25 -27
  45. data/lib/github_api/repos/merging.rb +7 -6
  46. data/lib/github_api/repos/pub_sub_hubbub.rb +14 -18
  47. data/lib/github_api/repos/statuses.rb +13 -14
  48. data/lib/github_api/say.rb +1 -3
  49. data/lib/github_api/search.rb +12 -21
  50. data/lib/github_api/users.rb +10 -9
  51. data/lib/github_api/users/emails.rb +11 -9
  52. data/lib/github_api/users/followers.rb +25 -23
  53. data/lib/github_api/users/keys.rb +27 -29
  54. data/lib/github_api/version.rb +1 -1
  55. data/spec/github/activity/events/org_spec.rb +6 -6
  56. data/spec/github/activity/events/performed_spec.rb +1 -1
  57. data/spec/github/activity/events/received_spec.rb +1 -1
  58. data/spec/github/activity/events/user_org_spec.rb +4 -2
  59. data/spec/github/activity/notifications/create_spec.rb +1 -1
  60. data/spec/github/activity/notifications/delete_spec.rb +1 -1
  61. data/spec/github/activity/notifications/get_spec.rb +1 -1
  62. data/spec/github/activity/notifications/subscribed_spec.rb +1 -1
  63. data/spec/github/activity/starring/list_spec.rb +2 -0
  64. data/spec/github/activity/starring/starring_spec.rb +1 -1
  65. data/spec/github/activity/watching/list_spec.rb +2 -0
  66. data/spec/github/activity/watching/watching_spec.rb +1 -3
  67. data/spec/github/api/set_spec.rb +18 -4
  68. data/spec/github/api/with_spec.rb +28 -0
  69. data/spec/github/api_spec.rb +11 -33
  70. data/spec/github/arguments/parse_spec.rb +68 -0
  71. data/spec/github/authorizations/delete_spec.rb +1 -1
  72. data/spec/github/authorizations/get_spec.rb +1 -1
  73. data/spec/github/error/validations_spec.rb +3 -3
  74. data/spec/github/gists/comments/list_spec.rb +1 -1
  75. data/spec/github/gists/delete_spec.rb +1 -1
  76. data/spec/github/gists/fork_spec.rb +1 -1
  77. data/spec/github/gists/get_spec.rb +1 -1
  78. data/spec/github/gists/is_starred_spec.rb +2 -0
  79. data/spec/github/gists/star_spec.rb +1 -1
  80. data/spec/github/gists/unstar_spec.rb +1 -1
  81. data/spec/github/git_data/blobs/create_spec.rb +2 -0
  82. data/spec/github/git_data/blobs/get_spec.rb +1 -1
  83. data/spec/github/git_data/commits/create_spec.rb +2 -0
  84. data/spec/github/git_data/commits/get_spec.rb +3 -3
  85. data/spec/github/git_data/references/create_spec.rb +1 -1
  86. data/spec/github/git_data/references/delete_spec.rb +3 -1
  87. data/spec/github/git_data/tags/create_spec.rb +2 -0
  88. data/spec/github/gitignore/get_spec.rb +1 -1
  89. data/spec/github/issues/events/get_spec.rb +3 -1
  90. data/spec/github/issues/events/list_spec.rb +3 -1
  91. data/spec/github/issues/labels/add_spec.rb +6 -6
  92. data/spec/github/issues/labels/list_spec.rb +3 -1
  93. data/spec/github/issues/labels/replace_spec.rb +6 -7
  94. data/spec/github/issues/milestones/get_spec.rb +2 -0
  95. data/spec/github/normalizer_spec.rb +18 -6
  96. data/spec/github/orgs/members/conceal_spec.rb +6 -4
  97. data/spec/github/orgs/members/delete_spec.rb +2 -0
  98. data/spec/github/orgs/members/list_spec.rb +1 -1
  99. data/spec/github/orgs/members/member_spec.rb +3 -1
  100. data/spec/github/orgs/members/publicize_spec.rb +2 -0
  101. data/spec/github/orgs/teams/add_member_spec.rb +2 -0
  102. data/spec/github/orgs/teams/create_spec.rb +1 -1
  103. data/spec/github/orgs/teams/delete_spec.rb +1 -1
  104. data/spec/github/orgs/teams/edit_spec.rb +1 -1
  105. data/spec/github/orgs/teams/get_spec.rb +1 -1
  106. data/spec/github/orgs/teams/list_spec.rb +1 -1
  107. data/spec/github/orgs/teams/team_member_spec.rb +3 -1
  108. data/spec/github/parameter_filter_spec.rb +19 -58
  109. data/spec/github/pull_requests/comments/create_spec.rb +3 -1
  110. data/spec/github/pull_requests/comments/delete_spec.rb +1 -1
  111. data/spec/github/pull_requests/comments/edit_spec.rb +2 -0
  112. data/spec/github/pull_requests/comments/get_spec.rb +3 -1
  113. data/spec/github/pull_requests/comments/list_spec.rb +3 -1
  114. data/spec/github/pull_requests/commits_spec.rb +3 -3
  115. data/spec/github/pull_requests/create_spec.rb +4 -0
  116. data/spec/github/pull_requests/files_spec.rb +4 -0
  117. data/spec/github/pull_requests/get_spec.rb +3 -3
  118. data/spec/github/pull_requests/list_spec.rb +3 -3
  119. data/spec/github/pull_requests/merge_spec.rb +2 -0
  120. data/spec/github/pull_requests/merged_spec.rb +3 -1
  121. data/spec/github/pull_requests/update_spec.rb +4 -0
  122. data/spec/github/repos/collaborators/add_spec.rb +3 -1
  123. data/spec/github/repos/collaborators/get_spec.rb +1 -3
  124. data/spec/github/repos/collaborators/list_spec.rb +5 -1
  125. data/spec/github/repos/collaborators/remove_spec.rb +3 -1
  126. data/spec/github/repos/comments/create_spec.rb +4 -0
  127. data/spec/github/repos/comments/delete_spec.rb +2 -2
  128. data/spec/github/repos/comments/get_spec.rb +6 -2
  129. data/spec/github/repos/commits/compare_spec.rb +3 -3
  130. data/spec/github/repos/commits/get_spec.rb +3 -3
  131. data/spec/github/repos/commits/list_spec.rb +3 -3
  132. data/spec/github/repos/contents/archive_spec.rb +12 -0
  133. data/spec/github/repos/contents/get_spec.rb +5 -0
  134. data/spec/github/repos/contributors_spec.rb +7 -2
  135. data/spec/github/repos/downloads/create_spec.rb +4 -0
  136. data/spec/github/repos/downloads/delete_spec.rb +5 -1
  137. data/spec/github/repos/downloads/get_spec.rb +3 -1
  138. data/spec/github/repos/downloads/list_spec.rb +3 -1
  139. data/spec/github/repos/forks/create_spec.rb +2 -0
  140. data/spec/github/repos/forks/list_spec.rb +3 -1
  141. data/spec/github/repos/hooks/edit_spec.rb +1 -1
  142. data/spec/github/repos/keys/delete_spec.rb +1 -1
  143. data/spec/github/repos/keys/edit_spec.rb +2 -0
  144. data/spec/github/repos/keys/get_spec.rb +3 -1
  145. data/spec/github/repos/keys/list_spec.rb +4 -2
  146. data/spec/github/repos/list_spec.rb +6 -1
  147. data/spec/github/repos/pub_sub_hubbub/subscribe_service_spec.rb +27 -0
  148. data/spec/github/repos/pub_sub_hubbub/subscribe_spec.rb +51 -0
  149. data/spec/github/repos/pub_sub_hubbub/unsubscribe_service_spec.rb +21 -0
  150. data/spec/github/repos/pub_sub_hubbub/unsubscribe_spec.rb +58 -0
  151. data/spec/github/repos/statuses/create_spec.rb +2 -0
  152. data/spec/github/search_spec.rb +25 -10
  153. data/spec/github/users/followers/follow_spec.rb +1 -1
  154. data/spec/github/users/followers/is_following_spec.rb +1 -1
  155. data/spec/github/users/followers/unfollow_spec.rb +1 -1
  156. data/spec/github/users/keys/delete_spec.rb +1 -1
  157. data/spec/github/users/keys/get_spec.rb +1 -1
  158. data/spec/github/users/keys/update_spec.rb +1 -1
  159. data/spec/github/users/update_spec.rb +1 -1
  160. data/spec/integration/arguments_spec.rb +76 -0
  161. data/spec/{github → integration}/authorizations_spec.rb +0 -0
  162. metadata +44 -35
  163. data/spec/github/repos/pub_sub_hubbub_spec.rb +0 -78
@@ -35,19 +35,16 @@ module Github
35
35
  # github.pull_requests.list
36
36
  # github.pull_requests.list { |req| ... }
37
37
  #
38
- # pull_reqs = Github::PullRequests.new
39
- # pull_reqs.pull_requests.list 'user-name', 'repo-name'
38
+ # pulls = Github::PullRequests.new
39
+ # pulls.pull_requests.list 'user-name', 'repo-name'
40
40
  #
41
- def list(user_name, repo_name, params={})
42
- set :user => user_name, :repo => repo_name
43
- assert_presence_of user, repo
41
+ def list(*args)
42
+ arguments(args, :required => [:user, :repo]) do
43
+ sift VALID_REQUEST_PARAM_NAMES
44
+ assert_values VALID_REQUEST_PARAM_VALUES
45
+ end
44
46
 
45
- normalize! params
46
- filter! VALID_REQUEST_PARAM_NAMES, params
47
- # _merge_mime_type(:pull_request, params)
48
- assert_valid_values(VALID_REQUEST_PARAM_VALUES, params)
49
-
50
- response = get_request("/repos/#{user}/#{repo}/pulls", params)
47
+ response = get_request("/repos/#{user}/#{repo}/pulls", arguments.params)
51
48
  return response unless block_given?
52
49
  response.each { |el| yield el }
53
50
  end
@@ -59,15 +56,13 @@ module Github
59
56
  # github = Github.new
60
57
  # github.pull_requests.get 'user-name', 'repo-name', 'number'
61
58
  #
62
- # pull_reqs = Github::PullRequests.new
63
- # pull_reqs.get 'user-name', 'repo-name', 'number'
59
+ # pulls = Github::PullRequests.new
60
+ # pulls.get 'user-name', 'repo-name', 'number'
64
61
  #
65
- def get(user_name, repo_name, number, params={})
66
- set :user => user_name, :repo => repo_name
67
- assert_presence_of user, repo, number
68
- normalize! params
62
+ def get(*args)
63
+ arguments(args, :required => [:user, :repo, :number])
69
64
 
70
- get_request("/repos/#{user}/#{repo}/pulls/#{number}", params)
65
+ get_request("/repos/#{user}/#{repo}/pulls/#{number}", arguments.params)
71
66
  end
72
67
  alias :find :get
73
68
 
@@ -100,14 +95,12 @@ module Github
100
95
  # "head" => "octocat:new-feature",
101
96
  # "base" => "master"
102
97
  #
103
- def create(user_name, repo_name, params={})
104
- set :user => user_name, :repo => repo_name
105
- assert_presence_of user, repo
106
-
107
- normalize! params
108
- filter! VALID_REQUEST_PARAM_NAMES, params
98
+ def create(*args)
99
+ arguments(args, :required => [:user, :repo]) do
100
+ sift VALID_REQUEST_PARAM_NAMES
101
+ end
109
102
 
110
- post_request("/repos/#{user}/#{repo}/pulls", params)
103
+ post_request("/repos/#{user}/#{repo}/pulls", arguments.params)
111
104
  end
112
105
 
113
106
  # Update a pull request
@@ -124,14 +117,13 @@ module Github
124
117
  # "body" => "Update body",
125
118
  # "state" => "open",
126
119
  #
127
- def update(user_name, repo_name, number, params={})
128
- set :user => user_name, :repo => repo_name
129
- assert_presence_of user, repo, number
130
- normalize! params
131
- filter! VALID_REQUEST_PARAM_NAMES, params
132
- assert_valid_values(VALID_REQUEST_PARAM_VALUES, params)
120
+ def update(*args)
121
+ arguments(args, :required => [:user, :repo, :number]) do
122
+ sift VALID_REQUEST_PARAM_NAMES
123
+ assert_values VALID_REQUEST_PARAM_VALUES
124
+ end
133
125
 
134
- patch_request("/repos/#{user}/#{repo}/pulls/#{number}", params)
126
+ patch_request("/repos/#{user}/#{repo}/pulls/#{number}", arguments.params)
135
127
  end
136
128
 
137
129
  # List commits on a pull request
@@ -140,12 +132,11 @@ module Github
140
132
  # github = Github.new
141
133
  # github.pull_requests.commits 'user-name', 'repo-name', 'number'
142
134
  #
143
- def commits(user_name, repo_name, number, params={})
144
- set :user => user_name, :repo => repo_name
145
- assert_presence_of user, repo, number
146
- normalize! params
135
+ def commits(*args)
136
+ arguments(args, :required => [:user, :repo, :number])
147
137
 
148
- response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/commits", params)
138
+ response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/commits",
139
+ arguments.params)
149
140
  return response unless block_given?
150
141
  response.each { |el| yield el }
151
142
  end
@@ -156,12 +147,11 @@ module Github
156
147
  # github = Github.new
157
148
  # github.pull_requests.files 'user-name', 'repo-name', 'number'
158
149
  #
159
- def files(user_name, repo_name, number, params={})
160
- set :user => user_name, :repo => repo_name
161
- assert_presence_of user, repo, number
162
- normalize! params
150
+ def files(*args)
151
+ arguments(args, :required => [:user, :repo, :number])
163
152
 
164
- response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/files", params)
153
+ response = get_request("/repos/#{user}/#{repo}/pulls/#{number}/files",
154
+ arguments.params)
165
155
  return response unless block_given?
166
156
  response.each { |el| yield el }
167
157
  end
@@ -172,12 +162,10 @@ module Github
172
162
  # github = Github.new
173
163
  # github.pull_requests.merged? 'user-name', 'repo-name', 'number'
174
164
  #
175
- def merged?(user_name, repo_name, number, params={})
176
- set :user => user_name, :repo => repo_name
177
- assert_presence_of user, repo, number
178
- normalize! params
165
+ def merged?(*args)
166
+ arguments(args, :required => [:user, :repo, :number])
179
167
 
180
- get_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", params)
168
+ get_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", arguments.params)
181
169
  true
182
170
  rescue Github::Error::NotFound
183
171
  false
@@ -193,14 +181,12 @@ module Github
193
181
  # github = Github.new
194
182
  # github.pull_requests.merge 'user-name', 'repo-name', 'number'
195
183
  #
196
- def merge(user_name, repo_name, number, params={})
197
- set :user => user_name, :repo => repo_name
198
- assert_presence_of user, repo, number
199
-
200
- normalize! params
201
- filter! VALID_REQUEST_PARAM_NAMES, params
184
+ def merge(*args)
185
+ arguments(args, :required => [:user, :repo, :number]) do
186
+ sift VALID_REQUEST_PARAM_NAMES
187
+ end
202
188
 
203
- put_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", params)
189
+ put_request("/repos/#{user}/#{repo}/pulls/#{number}/merge", arguments.params)
204
190
  end
205
191
 
206
192
  end # PullRequests
@@ -35,10 +35,9 @@ module Github
35
35
  # github.pull_requests.comments.list 'user-name', 'repo-name'
36
36
  # github.pull_requests.comments.list 'user-name', 'repo-name' { |comm| ... }
37
37
  #
38
- def list(user_name, repo_name, params={})
39
- set :user => user_name, :repo => repo_name
40
- assert_presence_of user, repo
41
- normalize! params
38
+ def list(*args)
39
+ arguments(args, :required => [:user, :repo])
40
+ params = arguments.params
42
41
 
43
42
  response = if (request_id = params.delete('request_id'))
44
43
  get_request("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
@@ -55,12 +54,10 @@ module Github
55
54
  # github = Github.new
56
55
  # github.pull_requests.comments.get 'user-name', 'repo-name', 'comment-id'
57
56
  #
58
- def get(user_name, repo_name, comment_id, params={})
59
- set :user => user_name, :repo => repo_name
60
- assert_presence_of user, repo, comment_id
61
- normalize! params
57
+ def get(*args)
58
+ arguments(args, :required => [:user, :repo, :comment_id])
62
59
 
63
- get_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
60
+ get_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", arguments.params)
64
61
  end
65
62
  alias :find :get
66
63
 
@@ -92,14 +89,13 @@ module Github
92
89
  # "body" => "Nice change",
93
90
  # "in_reply_to" => 4
94
91
  #
95
- def create(user_name, repo_name, request_id, params={})
96
- set :user => user_name, :repo => repo_name
97
- assert_presence_of user, repo, request_id
98
- normalize! params
99
- filter! VALID_REQUEST_COM_PARAM_NAMES, params
92
+ def create(*args)
93
+ arguments(args, :required => [:user, :repo, :request_id]) do
94
+ sift VALID_REQUEST_COM_PARAM_NAMES
95
+ end
100
96
  # _validate_reply_to(params)
101
97
 
102
- post_request("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", params)
98
+ post_request("/repos/#{user}/#{repo}/pulls/#{request_id}/comments", arguments.params)
103
99
  end
104
100
 
105
101
  # Edit a pull request comment
@@ -112,13 +108,12 @@ module Github
112
108
  # github.pull_requests.comments.edit 'user-name', 'repo-name','comment-id',
113
109
  # "body" => "Nice change"
114
110
  #
115
- def edit(user_name, repo_name, comment_id, params={})
116
- set :user => user_name, :repo => repo_name
117
- assert_presence_of user, repo, comment_id
118
- normalize! params
119
- filter! VALID_REQUEST_COM_PARAM_NAMES, params
111
+ def edit(*args)
112
+ arguments(args, :required => [:user, :repo, :comment_id]) do
113
+ sift VALID_REQUEST_COM_PARAM_NAMES
114
+ end
120
115
 
121
- patch_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
116
+ patch_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", arguments.params)
122
117
  end
123
118
 
124
119
  # Delete a pull request comment
@@ -127,12 +122,10 @@ module Github
127
122
  # github = Github.new
128
123
  # github.pull_requests.comments.delete 'user-name', 'repo-name','comment-id'
129
124
  #
130
- def delete(user_name, repo_name, comment_id, params={})
131
- set :user => user_name, :repo => repo_name
132
- assert_presence_of user, repo, comment_id
133
- normalize! params
125
+ def delete(*args)
126
+ arguments(args, :required => [:user, :repo, :comment_id])
134
127
 
135
- delete_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", params)
128
+ delete_request("/repos/#{user}/#{repo}/pulls/comments/#{comment_id}", arguments.params)
136
129
  end
137
130
 
138
131
  private
@@ -26,6 +26,8 @@ module Github
26
26
  "has_downloads" => true
27
27
  }.freeze
28
28
 
29
+ REQUIRED_REPO_OPTIONS = %w[ name ]
30
+
29
31
  VALID_REPO_OPTIONS = %w[
30
32
  name
31
33
  description
@@ -86,7 +88,7 @@ module Github
86
88
  @mergin ||= ApiFactory.new('Repos::Merging', current_options.merge(options), &block)
87
89
  end
88
90
 
89
- # Access to Repos::Watchin API
91
+ # Access to Repos::PubSubHubbub API
90
92
  def pubsubhubbub(options={}, &block)
91
93
  @pubsubhubbub ||= ApiFactory.new('Repos::PubSubHubbub', current_options.merge(options), &block)
92
94
  end
@@ -96,41 +98,74 @@ module Github
96
98
  @statuses ||= ApiFactory.new('Repos::Statuses', current_options.merge(options), &block)
97
99
  end
98
100
 
99
- # List branches
101
+ # List repositories for the authenticated user
100
102
  #
101
103
  # = Examples
104
+ # github = Github.new :oauth_token => '...'
105
+ # github.repos.list
106
+ # github.repos.list { |repo| ... }
107
+ #
108
+ # List all repositories
109
+ #
110
+ # This provides a dump of every repository, in the order that they were created.
111
+ # = Parameters
112
+ # * <tt>:since</tt> - the integer ID of the last Repository that you've seen.
102
113
  #
114
+ # = Examples
103
115
  # github = Github.new
104
- # github.repos.branches 'user-name', 'repo-name'
116
+ # github.repos.list
117
+ # github.repos.list { |repo| ... }
105
118
  #
106
- # repos = Github::Repos.new
107
- # repos.branches 'user-name', 'repo-name'
119
+ # List public repositories for the specified user.
108
120
  #
109
- def branches(user_name, repo_name, params={})
110
- set :user => user_name, :repo => repo_name
111
- assert_presence_of user, repo
112
- normalize! params
121
+ # = Examples
122
+ # github = Github.new
123
+ # github.repos.list :user => 'user-name'
124
+ # github.repos.list :user => 'user-name', { |repo| ... }
125
+ #
126
+ # List repositories for the specified organisation.
127
+ #
128
+ # = Examples
129
+ # github = Github.new
130
+ # github.repos.list :org => 'org-name'
131
+ # github.repos.list :org => 'org-name', { |repo| ... }
132
+ #
133
+ def list(*args)
134
+ arguments(args) do
135
+ sift %w[ user org type sort direction ]
136
+ end
137
+ params = arguments.params
113
138
 
114
- response = get_request("/repos/#{user}/#{repo}/branches", params)
139
+ response = if (user_name = (params.delete("user")))
140
+ get_request("/users/#{user_name}/repos", params)
141
+ elsif (org_name = (params.delete("org")))
142
+ get_request("/orgs/#{org_name}/repos", params)
143
+ elsif authenticated?
144
+ # For authenticated user
145
+ get_request("/user/repos", params)
146
+ else
147
+ get_request("/repositories", params)
148
+ end
115
149
  return response unless block_given?
116
150
  response.each { |el| yield el }
117
151
  end
118
- alias :list_branches :branches
152
+ alias :all :list
119
153
 
120
- # Get branch
154
+ # Get a repository
121
155
  #
122
156
  # = Examples
157
+ # github = Github.new
158
+ # github.repos.get 'user-name', 'repo-name'
159
+ # github.repos.get user: 'user-name', repo: 'repo-name'
160
+ # github.repos(user: 'user-name', repo: 'repo-name').get
123
161
  #
124
- # github = Github.new
125
- # github.repos.branch 'user-name', 'repo-name', 'branch-name'
126
- #
127
- def branch(user_name, repo_name, branch, params={})
128
- set :user => user_name, :repo => repo_name
129
- assert_presence_of user_name, repo_name, branch
130
- normalize! params
162
+ def get(*args)
163
+ arguments(args, :required => [:user, :repo])
164
+ params = arguments.params
131
165
 
132
- get_request("/repos/#{user_name}/#{repo_name}/branches/#{branch}", params)
166
+ get_request("/repos/#{user}/#{repo}", params)
133
167
  end
168
+ alias :find :get
134
169
 
135
170
  # Create a new repository for the autheticated user.
136
171
  #
@@ -163,10 +198,11 @@ module Github
163
198
  # github.repos.create :name => 'repo-name', :org => 'organisation-name'
164
199
  #
165
200
  def create(*args)
166
- params = args.extract_options!
167
- normalize! params
168
- filter! VALID_REPO_OPTIONS + %w[ org ], params
169
- assert_required_keys(%w[ name ], params)
201
+ arguments(args) do
202
+ sift VALID_REPO_OPTIONS + %w[ org ]
203
+ assert_required %w[ name ]
204
+ end
205
+ params = arguments.params
170
206
 
171
207
  # Requires authenticated user
172
208
  if (org = params.delete("org"))
@@ -185,10 +221,9 @@ module Github
185
221
  # github = Github.new :oauth_token => '...'
186
222
  # github.repos.delete 'user-name', 'repo-name'
187
223
  #
188
- def delete(user_name, repo_name, params={})
189
- set :user => user_name, :repo => repo_name
190
- assert_presence_of user, repo
191
- normalize! params
224
+ def delete(*args)
225
+ arguments(args, :required => [:user, :repo])
226
+ params = arguments.params
192
227
 
193
228
  delete_request("/repos/#{user}/#{repo}", params)
194
229
  end
@@ -205,11 +240,11 @@ module Github
205
240
  # github.repos.contributors 'user-name','repo-name'
206
241
  # github.repos.contributors 'user-name','repo-name' { |cont| ... }
207
242
  #
208
- def contributors(user_name, repo_name, params={})
209
- set :user => user_name, :repo => repo_name
210
- assert_presence_of user, repo
211
- normalize! params
212
- filter! ['anon'], params
243
+ def contributors(*args)
244
+ arguments(args, :required => [:user, :repo]) do
245
+ sift %w[ anon ]
246
+ end
247
+ params = arguments.params
213
248
 
214
249
  response = get_request("/repos/#{user}/#{repo}/contributors", params)
215
250
  return response unless block_given?
@@ -238,101 +273,111 @@ module Github
238
273
  # :homepage => "https://github.com",
239
274
  # :public => true, :has_issues => true
240
275
  #
241
- def edit(user_name, repo_name, params={})
242
- set :user => user_name, :repo => repo_name
243
- assert_presence_of user, repo
244
-
245
- normalize! params
246
- filter! VALID_REPO_OPTIONS, params
247
- assert_required_keys(%w[ name ], params)
276
+ def edit(*args)
277
+ arguments(args, :required => [:user, :repo]) do
278
+ sift VALID_REPO_OPTIONS
279
+ assert_required %w[ name ]
280
+ end
281
+ params = arguments.params
248
282
 
249
283
  patch_request("/repos/#{user}/#{repo}", DEFAULT_REPO_OPTIONS.merge(params))
250
284
  end
251
285
 
252
- # Get a repository
286
+ # Delete a repository
287
+ #
288
+ # Deleting a repository requires admin access.
289
+ # If OAuth is used, the delete_repo scope is required.
253
290
  #
254
291
  # = Examples
255
- # github = Github.new
256
- # github.repos.get 'user-name', 'repo-name'
292
+ # github = Github.new :oauth_token => '...'
293
+ # github.repos.delete 'user-name', 'repo-name'
257
294
  #
258
- def get(user_name, repo_name, params={})
259
- set :user => user_name, :repo => repo_name
260
- assert_presence_of user, repo
261
- normalize! params
295
+ def delete(*args)
296
+ arguments(args, :required => [:user, :repo])
297
+ params = arguments.params
262
298
 
263
- get_request("/repos/#{user}/#{repo}", params)
299
+ delete_request("/repos/#{user}/#{repo}", params)
264
300
  end
265
- alias :find :get
301
+ alias :remove :delete
266
302
 
267
- # List languages
303
+ # List branches
268
304
  #
269
305
  # = Examples
270
- # github = Github.new
271
- # github.repos.languages 'user-name', 'repo-name'
272
- # github.repos.languages 'user-name', 'repo-name' { |lang| ... }
273
306
  #
274
- def languages(user_name, repo_name, params={})
275
- set :user => user_name, :repo => repo_name
276
- assert_presence_of user, repo
277
- normalize! params
307
+ # github = Github.new
308
+ # github.repos.branches 'user-name', 'repo-name'
309
+ # github.repos(user: 'user-name', repo: 'repo-name').branches
310
+ #
311
+ # repos = Github::Repos.new
312
+ # repos.branches 'user-name', 'repo-name'
313
+ #
314
+ # def branches(user_name, repo_name, params={})
315
+ def branches(*args)
316
+ arguments(args, :required => [:user, :repo])
317
+ params = arguments.params
278
318
 
279
- response = get_request("/repos/#{user}/#{repo}/languages", params)
319
+ response = get_request("/repos/#{user}/#{repo}/branches", arguments.params)
280
320
  return response unless block_given?
281
321
  response.each { |el| yield el }
282
322
  end
283
- alias :list_languages :languages
323
+ alias :list_branches :branches
284
324
 
285
- # List repositories for the authenticated user
325
+ # Get branch
286
326
  #
287
327
  # = Examples
288
- # github = Github.new :oauth_token => '...'
289
- # github.repos.list
290
- # github.repos.list { |repo| ... }
291
328
  #
292
- # List all repositories
329
+ # github = Github.new
330
+ # github.repos.branch 'user-name', 'repo-name', 'branch-name'
331
+ # github.repos.branch user: 'user-name', repo: 'repo-name', branch: 'branch-name'
332
+ # github.repos(user: 'user-name', repo: 'repo-name', branch: 'branch-name').branch
333
+ #
334
+ def branch(*args)
335
+ arguments(args, :required => [:user, :repo, :branch])
336
+ params = arguments.params
337
+
338
+ get_request("/repos/#{user}/#{repo}/branches/#{branch}", params)
339
+ end
340
+
341
+ # List contributors
293
342
  #
294
- # This provides a dump of every repository, in the order that they were created.
295
343
  # = Parameters
296
- # * <tt>:since</tt> - the integer ID of the last Repository that you've seen.
344
+ # <tt>:anon</tt> - Optional flag. Set to 1 or true to include anonymous contributors.
297
345
  #
298
346
  # = Examples
299
- # github = Github.new
300
- # github.repos.list
301
- # github.repos.list { |repo| ... }
302
- #
303
- # List public repositories for the specified user.
304
347
  #
305
- # = Examples
306
- # github = Github.new
307
- # github.repos.list :user => 'user-name'
308
- # github.repos.list :user => 'user-name', { |repo| ... }
348
+ # github = Github.new
349
+ # github.repos.contributors 'user-name','repo-name'
350
+ # github.repos.contributors 'user-name','repo-name' { |cont| ... }
309
351
  #
310
- # List repositories for the specified organisation.
352
+ def contributors(*args)
353
+ arguments(args, :required => [:user, :repo]) do
354
+ sift ['anon']
355
+ end
356
+ params = arguments.params
357
+
358
+ response = get_request("/repos/#{user}/#{repo}/contributors", params)
359
+ return response unless block_given?
360
+ response.each { |el| yield el }
361
+ end
362
+ alias :list_contributors :contributors
363
+ alias :contribs :contributors
364
+
365
+ # List languages
311
366
  #
312
367
  # = Examples
313
368
  # github = Github.new
314
- # github.repos.list :org => 'org-name'
315
- # github.repos.list :org => 'org-name', { |repo| ... }
369
+ # github.repos.languages 'user-name', 'repo-name'
370
+ # github.repos.languages 'user-name', 'repo-name' { |lang| ... }
316
371
  #
317
- def list(*args)
318
- params = args.extract_options!
319
- normalize! params
320
- filter! %w[ user org type sort direction ], params
372
+ def languages(*args)
373
+ arguments(args, :required => [:user, :repo])
374
+ params = arguments.params
321
375
 
322
- response = if (user_name = params.delete("user"))
323
- get_request("/users/#{user_name}/repos", params)
324
- elsif (org_name = params.delete("org"))
325
- get_request("/orgs/#{org_name}/repos", params)
326
- elsif authenticated?
327
- # For authenticated user
328
- get_request("/user/repos", params)
329
- else
330
- get_request("/repositories", params)
331
- end
376
+ response = get_request("/repos/#{user}/#{repo}/languages", params)
332
377
  return response unless block_given?
333
378
  response.each { |el| yield el }
334
379
  end
335
- alias :all :list
380
+ alias :list_languages :languages
336
381
 
337
382
  # List tags
338
383
  #
@@ -341,10 +386,9 @@ module Github
341
386
  # github.repos.tags 'user-name', 'repo-name'
342
387
  # github.repos.tags 'user-name', 'repo-name' { |tag| ... }
343
388
  #
344
- def tags(user_name, repo_name, params={})
345
- set :user => user_name, :repo => repo_name
346
- assert_presence_of user, repo
347
- normalize! params
389
+ def tags(*args)
390
+ arguments(args, :required => [:user, :repo])
391
+ params = arguments.params
348
392
 
349
393
  response = get_request("/repos/#{user}/#{repo}/tags", params)
350
394
  return response unless block_given?
@@ -361,10 +405,11 @@ module Github
361
405
  # github.repos.teams 'user-name', 'repo-name'
362
406
  # github.repos.teams 'user-name', 'repo-name' { |team| ... }
363
407
  #
364
- def teams(user_name, repo_name, params={})
365
- set :user => user_name, :repo => repo_name
366
- assert_presence_of user, repo
367
- normalize! params
408
+ # github.repos(user: 'user-name, repo: 'repo-name').teams
409
+ #
410
+ def teams(*args)
411
+ arguments(args, :required => [:user, :repo])
412
+ params = arguments.params
368
413
 
369
414
  response = get_request("/repos/#{user}/#{repo}/teams", params)
370
415
  return response unless block_given?