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
@@ -8,8 +8,8 @@ module Github #:nodoc
8
8
  super(
9
9
  generate_message(
10
10
  :problem => "Attempted to send request with nil arguments for #{errors.keys.join(', ')}.",
11
- :summary => 'Each request expects certain number of arguments.',
12
- :resolution => 'Double check that the provided arguments are set to some value.'
11
+ :summary => 'Each request expects certain number of required arguments.',
12
+ :resolution => 'Double check that the provided arguments are set to some value that is neither nil nor empty string.'
13
13
  )
14
14
  )
15
15
  end
@@ -32,12 +32,10 @@ module Github
32
32
  # github = Github.new :oauth_token => '...'
33
33
  # github.gists.list
34
34
  #
35
- def list(params={})
36
- normalize! params
35
+ def list(*args)
36
+ params = arguments(args).params
37
37
 
38
- user = params.delete('user')
39
-
40
- response = if user
38
+ response = if (user = params.delete('user'))
41
39
  get_request("/users/#{user}/gists", params)
42
40
  elsif oauth_token
43
41
  get_request("/gists", params)
@@ -55,10 +53,9 @@ module Github
55
53
  # github = Github.new :oauth_token => '...'
56
54
  # github.gists.starred
57
55
  #
58
- def starred(params={})
59
- normalize! params
60
-
61
- response = get_request("/gists/starred", params)
56
+ def starred(*args)
57
+ arguments(args)
58
+ response = get_request("/gists/starred", arguments.params)
62
59
  return response unless block_given?
63
60
  response.each { |el| yield el }
64
61
  end
@@ -69,11 +66,10 @@ module Github
69
66
  # github = Github.new
70
67
  # github.gists.get 'gist-id'
71
68
  #
72
- def get(gist_id, params={})
73
- normalize! params
74
- assert_presence_of gist_id
69
+ def get(*args)
70
+ arguments(args, :required => [:gist_id])
75
71
 
76
- get_request("/gists/#{gist_id}", params)
72
+ get_request("/gists/#{gist_id}", arguments.params)
77
73
  end
78
74
  alias :find :get
79
75
 
@@ -98,11 +94,12 @@ module Github
98
94
  # }
99
95
  # }
100
96
  #
101
- def create(params={})
102
- normalize! params
103
- assert_required_keys(REQUIRED_GIST_INPUTS, params)
97
+ def create(*args)
98
+ arguments(args) do
99
+ assert_required REQUIRED_GIST_INPUTS
100
+ end
104
101
 
105
- post_request("/gists", params)
102
+ post_request("/gists", arguments.params)
106
103
  end
107
104
 
108
105
  # Edit a gist
@@ -133,11 +130,10 @@ module Github
133
130
  # 'delete_the_file.txt' => nil
134
131
  # }
135
132
  #
136
- def edit(gist_id, params={})
137
- assert_presence_of gist_id
138
- normalize! params
133
+ def edit(*args)
134
+ arguments(args, :required => [:gist_id])
139
135
 
140
- patch_request("/gists/#{gist_id}", params)
136
+ patch_request("/gists/#{gist_id}", arguments.params)
141
137
  end
142
138
 
143
139
  # Star a gist
@@ -146,11 +142,10 @@ module Github
146
142
  # github = Github.new
147
143
  # github.gists.star 'gist-id'
148
144
  #
149
- def star(gist_id, params={})
150
- assert_presence_of gist_id
151
- normalize! params
145
+ def star(*args)
146
+ arguments(args, :required => [:gist_id])
152
147
 
153
- put_request("/gists/#{gist_id}/star", params)
148
+ put_request("/gists/#{gist_id}/star", arguments.params)
154
149
  end
155
150
 
156
151
  # Unstar a gist
@@ -159,11 +154,10 @@ module Github
159
154
  # github = Github.new
160
155
  # github.gists.unstar 'gist-id'
161
156
  #
162
- def unstar(gist_id, params={})
163
- assert_presence_of gist_id
164
- normalize! params
157
+ def unstar(*args)
158
+ arguments(args, :required => [:gist_id])
165
159
 
166
- delete_request("/gists/#{gist_id}/star", params)
160
+ delete_request("/gists/#{gist_id}/star", arguments.params)
167
161
  end
168
162
 
169
163
  # Check if a gist is starred
@@ -172,11 +166,9 @@ module Github
172
166
  # github = Github.new
173
167
  # github.gists.starred? 'gist-id'
174
168
  #
175
- def starred?(gist_id, params={})
176
- assert_presence_of gist_id
177
- normalize! params
178
-
179
- get_request("/gists/#{gist_id}/star", params)
169
+ def starred?(*args)
170
+ arguments(args, :required => [:gist_id])
171
+ get_request("/gists/#{gist_id}/star", arguments.params)
180
172
  true
181
173
  rescue Github::Error::NotFound
182
174
  false
@@ -188,11 +180,10 @@ module Github
188
180
  # github = Github.new
189
181
  # github.gists.fork 'gist-id'
190
182
  #
191
- def fork(gist_id, params={})
192
- assert_presence_of gist_id
193
- normalize! params
183
+ def fork(*args)
184
+ arguments(args, :required => [:gist_id])
194
185
 
195
- post_request("/gists/#{gist_id}/fork", params)
186
+ post_request("/gists/#{gist_id}/fork", arguments.params)
196
187
  end
197
188
 
198
189
  # Delete a gist
@@ -201,11 +192,10 @@ module Github
201
192
  # github = Github.new
202
193
  # github.gists.delete 'gist-id'
203
194
  #
204
- def delete(gist_id, params={})
205
- assert_presence_of gist_id
206
- normalize! params
195
+ def delete(*args)
196
+ arguments(args, :required => [:gist_id])
207
197
 
208
- delete_request("/gists/#{gist_id}", params)
198
+ delete_request("/gists/#{gist_id}", arguments.params)
209
199
  end
210
200
 
211
201
  end # Gists
@@ -19,11 +19,10 @@ module Github
19
19
  # github = Github.new
20
20
  # github.gists.comments.list 'gist-id'
21
21
  #
22
- def list(gist_id, params={})
23
- normalize! params
24
- assert_presence_of gist_id
22
+ def list(*args)
23
+ arguments(args, :required => [:gist_id])
25
24
 
26
- response = get_request("/gists/#{gist_id}/comments", params)
25
+ response = get_request("/gists/#{gist_id}/comments", arguments.params)
27
26
  return response unless block_given?
28
27
  response.each { |el| yield el }
29
28
  end
@@ -35,11 +34,10 @@ module Github
35
34
  # github = Github.new
36
35
  # github.gists.comments.get 'gist-id', 'comment-id'
37
36
  #
38
- def get(gist_id, comment_id, params={})
39
- normalize! params
40
- assert_presence_of comment_id
37
+ def get(*args)
38
+ arguments(args, :required => [:gist_id, :comment_id])
41
39
 
42
- get_request("/gists/#{gist_id}/comments/#{comment_id}", params)
40
+ get_request("/gists/#{gist_id}/comments/#{comment_id}", arguments.params)
43
41
  end
44
42
  alias :find :get
45
43
 
@@ -49,12 +47,13 @@ module Github
49
47
  # github = Github.new
50
48
  # github.gists.comments.create 'gist-id'
51
49
  #
52
- def create(gist_id, params={})
53
- normalize! params
54
- filter! VALID_GIST_COMMENT_OPTIONS, params
55
- assert_required_keys(REQUIRED_GIST_COMMENT_OPTIONS, params)
50
+ def create(*args)
51
+ arguments(args, :required => [:gist_id]) do
52
+ sift VALID_GIST_COMMENT_OPTIONS
53
+ assert_required REQUIRED_GIST_COMMENT_OPTIONS
54
+ end
56
55
 
57
- post_request("/gists/#{gist_id}/comments", params)
56
+ post_request("/gists/#{gist_id}/comments", arguments.params)
58
57
  end
59
58
 
60
59
  # Edit a comment
@@ -63,13 +62,13 @@ module Github
63
62
  # github = Github.new
64
63
  # github.gists.comments.edit 'gist-id', 'comment-id'
65
64
  #
66
- def edit(gist_id, comment_id, params={})
67
- normalize! params
68
- assert_presence_of comment_id
69
- filter! VALID_GIST_COMMENT_OPTIONS, params
70
- assert_required_keys(REQUIRED_GIST_COMMENT_OPTIONS, params)
65
+ def edit(*args)
66
+ arguments(args, :required => [:gist_id, :comment_id]) do
67
+ sift VALID_GIST_COMMENT_OPTIONS
68
+ assert_required REQUIRED_GIST_COMMENT_OPTIONS
69
+ end
71
70
 
72
- patch_request("/gists/#{gist_id}/comments/#{comment_id}", params)
71
+ patch_request("/gists/#{gist_id}/comments/#{comment_id}", arguments.params)
73
72
  end
74
73
 
75
74
  # Delete a comment
@@ -78,11 +77,10 @@ module Github
78
77
  # github = Github.new
79
78
  # github.gists.comments.delete 'gist-id', 'comment-id'
80
79
  #
81
- def delete(gist_id, comment_id, params={})
82
- normalize! params
83
- assert_presence_of comment_id
80
+ def delete(*args)
81
+ arguments(args, :required => [:gist_id, :comment_id])
84
82
 
85
- delete_request("/gists/#{gist_id}/comments/#{comment_id}", params)
83
+ delete_request("/gists/#{gist_id}/comments/#{comment_id}", arguments.params)
86
84
  end
87
85
 
88
86
  end # Gists::Comments
@@ -1,10 +1,11 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+
5
+ # Since blobs can be any arbitrary binary data, the input and responses for
6
+ # the blob api takes an encoding parameter that can be either utf-8 or base64.
7
+ # If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it.
4
8
  class GitData::Blobs < API
5
- # Since blobs can be any arbitrary binary data, the input and responses for
6
- # the blob api takes an encoding parameter that can be either utf-8 or base64.
7
- # If your data cannot be losslessly sent as a UTF-8 string, you can base64 encode it.
8
9
 
9
10
  VALID_BLOB_PARAM_NAMES = %w[ content encoding ].freeze
10
11
 
@@ -14,12 +15,10 @@ module Github
14
15
  # github = Github.new
15
16
  # github.git_data.blobs.get 'user-name', 'repo-name', 'sha'
16
17
  #
17
- def get(user_name, repo_name, sha, params={})
18
- set :user => user_name, :repo => repo_name
19
- assert_presence_of user, repo, sha
20
- normalize! params
18
+ def get(*args)
19
+ arguments(args, :required => [:user, :repo, :sha])
21
20
 
22
- get_request("/repos/#{user}/#{repo}/git/blobs/#{sha}", params)
21
+ get_request("/repos/#{user}/#{repo}/git/blobs/#{sha}", arguments.params)
23
22
  end
24
23
  alias :find :get
25
24
 
@@ -34,15 +33,13 @@ module Github
34
33
  # "content" => "Content of the blob",
35
34
  # "encoding" => "utf-8"
36
35
  #
37
- def create(user_name, repo_name, params={})
38
- set :user => user_name, :repo => repo_name
39
- assert_presence_of user, repo
40
-
41
- normalize! params
42
- filter! VALID_BLOB_PARAM_NAMES, params
43
- assert_required_keys(VALID_BLOB_PARAM_NAMES, params)
36
+ def create(*args)
37
+ arguments(args, :required => [:user, :repo]) do
38
+ sift VALID_BLOB_PARAM_NAMES
39
+ assert_required VALID_BLOB_PARAM_NAMES
40
+ end
44
41
 
45
- post_request("/repos/#{user}/#{repo}/git/blobs", params)
42
+ post_request("/repos/#{user}/#{repo}/git/blobs", arguments.params)
46
43
  end
47
44
 
48
45
  end # GitData::Blobs
@@ -26,10 +26,12 @@ module Github
26
26
  # github = Github.new
27
27
  # github.git_data.commits.get 'user-name', 'repo-name', 'sha'
28
28
  #
29
- def get(user_name, repo_name, sha, params={})
30
- set :user => user_name, :repo => repo_name
31
- assert_presence_of user, repo, sha
32
- normalize! params
29
+ # commits = Github::Commits.new user: 'user-name', repo: 'repo-name'
30
+ # commits.get sha: '...'
31
+ #
32
+ def get(*args)
33
+ arguments(args, :required => [:user, :repo, :sha])
34
+ params = arguments.params
33
35
 
34
36
  get_request("/repos/#{user}/#{repo}/git/commits/#{sha}", params)
35
37
  end
@@ -67,12 +69,12 @@ module Github
67
69
  # ],
68
70
  # "tree": "827efc6d56897b048c772eb4087f854f46256132"]
69
71
  #
70
- def create(user_name, repo_name, params={})
71
- set :user => user_name, :repo => repo_name
72
- assert_presence_of user, repo
73
- normalize! params
74
- filter! VALID_COMMIT_PARAM_NAMES, params
75
- assert_required_keys(REQUIRED_COMMIT_PARAMS, params)
72
+ def create(*args)
73
+ arguments(args, :required => [:user, :repo]) do
74
+ sift VALID_COMMIT_PARAM_NAMES
75
+ assert_required REQUIRED_COMMIT_PARAMS
76
+ end
77
+ params = arguments.params
76
78
 
77
79
  post_request("/repos/#{user}/#{repo}/git/commits", params)
78
80
  end
@@ -5,6 +5,8 @@ module Github
5
5
 
6
6
  VALID_REF_PARAM_NAMES = %w[ ref sha force ].freeze
7
7
 
8
+ REQUIRED_REF_PARAMS = %w[ ref sha ].freeze
9
+
8
10
  VALID_REF_PARAM_VALUES = {
9
11
  'ref' => %r{^refs\/\w+(\/\w+)*} # test fully qualified reference
10
12
  }
@@ -22,13 +24,11 @@ module Github
22
24
  #
23
25
  # github.git_data.references.list 'user-name', 'repo-name', ref:'tags'
24
26
  #
25
- def list(user_name, repo_name, params={})
26
- set :user => user_name, :repo => repo_name
27
- assert_presence_of user, repo
28
- normalize! params
27
+ def list(*args)
28
+ arguments(args, :required => [:user, :repo])
29
+ params = arguments.params
29
30
 
30
- response = if params['ref']
31
- ref = params.delete('ref')
31
+ response = if (ref = params.delete('ref'))
32
32
  validate_reference ref
33
33
  get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
34
34
  else
@@ -50,17 +50,15 @@ module Github
50
50
  # github = Github.new
51
51
  # github.git_data.references.get 'user-name', 'repo-name', 'heads/branch'
52
52
  #
53
- def get(user_name, repo_name, ref, params={})
54
- set :user => user_name, :repo => repo_name
55
- assert_presence_of user, repo, ref
53
+ def get(*args)
54
+ arguments(args, :required => [:user, :repo, :ref])
56
55
  validate_reference ref
57
- normalize! params
56
+ params = arguments.params
58
57
 
59
58
  get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
60
59
  end
61
60
  alias :find :get
62
61
 
63
-
64
62
  # Create a reference
65
63
  #
66
64
  # = Inputs
@@ -73,13 +71,13 @@ module Github
73
71
  # "ref" => "refs/heads/master",
74
72
  # "sha" => "827efc6d56897b048c772eb4087f854f46256132"
75
73
  #
76
- def create(user_name, repo_name, params={})
77
- set :user => user_name, :repo => repo_name
78
- normalize! params
79
- filter! VALID_REF_PARAM_NAMES, params
80
- assert_presence_of user, repo, params['ref']
74
+ def create(*args)
75
+ arguments(args, :required => [:user, :repo]) do
76
+ sift VALID_REF_PARAM_NAMES
77
+ assert_required REQUIRED_REF_PARAMS
78
+ end
79
+ params = arguments.params
81
80
  validate_reference params['ref']
82
- assert_required_keys(%w[ ref sha ], params)
83
81
 
84
82
  post_request("/repos/#{user}/#{repo}/git/refs", params)
85
83
  end
@@ -96,13 +94,12 @@ module Github
96
94
  # "sha" => "827efc6d56897b048c772eb4087f854f46256132",
97
95
  # "force" => true
98
96
  #
99
- def update(user_name, repo_name, ref, params={})
100
- set :user => user_name, :repo => repo_name
101
- assert_presence_of user, repo, ref
102
- validate_reference ref
103
- normalize! params
104
- filter! VALID_REF_PARAM_NAMES, params
105
- assert_required_keys(%w[ sha ], params)
97
+ def update(*args)
98
+ arguments(args, :required => [:user, :repo, :ref]) do
99
+ sift VALID_REF_PARAM_NAMES
100
+ assert_required %w[ sha ]
101
+ end
102
+ params = arguments.params
106
103
 
107
104
  patch_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
108
105
  end
@@ -114,10 +111,9 @@ module Github
114
111
  # github.git_data.references.delete 'user-name', 'repo-name',
115
112
  # "ref" => "refs/heads/master",
116
113
  #
117
- def delete(user_name, repo_name, ref, params={})
118
- set :user => user_name, :repo => repo_name
119
- assert_presence_of user, repo, ref
120
- normalize! params
114
+ def delete(*args)
115
+ arguments(args, :required => [:user, :repo, :ref])
116
+ params = arguments.params
121
117
 
122
118
  delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
123
119
  end
@@ -28,10 +28,9 @@ module Github
28
28
  # github = Github.new
29
29
  # github.git_data.tags.get 'user-name', 'repo-name', 'sha'
30
30
  #
31
- def get(user_name, repo_name, sha, params={})
32
- set :user => user_name, :repo => repo_name
33
- assert_presence_of user, repo, sha
34
- normalize! params
31
+ def get(*args)
32
+ arguments(args, :required => [:user, :repo, :sha])
33
+ params = arguments.params
35
34
 
36
35
  get_request("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
37
36
  end
@@ -65,13 +64,12 @@ module Github
65
64
  # "date" => "2011-06-17T14:53:3"
66
65
  # }
67
66
  #
68
- def create(user_name, repo_name, params={})
69
- set :user => user_name, :repo => repo_name
70
- assert_presence_of user, repo
71
- normalize! params
72
-
73
- filter! VALID_TAG_PARAM_NAMES, params
74
- assert_valid_values(VALID_TAG_PARAM_VALUES, params)
67
+ def create(*args)
68
+ arguments(args, :required => [:user, :repo]) do
69
+ sift VALID_TAG_PARAM_NAMES
70
+ assert_values VALID_TAG_PARAM_VALUES
71
+ end
72
+ params = arguments.params
75
73
 
76
74
  post_request("/repos/#{user}/#{repo}/git/tags", params)
77
75
  end