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
@@ -3,6 +3,23 @@
3
3
  module Github
4
4
  class Repos::Collaborators < API
5
5
 
6
+ # List collaborators
7
+ #
8
+ # Examples:
9
+ # github = Github.new
10
+ # github.repos.collaborators.list 'user-name', 'repo-name'
11
+ # github.repos.collaborators.list 'user-name', 'repo-name' { |cbr| .. }
12
+ #
13
+ def list(*args)
14
+ arguments(args, :required => [:user, :repo])
15
+ params = arguments.params
16
+
17
+ response = get_request("/repos/#{user}/#{repo}/collaborators", params)
18
+ return response unless block_given?
19
+ response.each { |el| yield el }
20
+ end
21
+ alias :all :list
22
+
6
23
  # Add collaborator
7
24
  #
8
25
  # Examples:
@@ -12,10 +29,9 @@ module Github
12
29
  # collaborators = Github::Repos::Collaborators.new
13
30
  # collaborators.add 'user', 'repo', 'collaborator'
14
31
  #
15
- def add(user_name, repo_name, collaborator, params={})
16
- set :user => user_name, :repo => repo_name
17
- assert_presence_of user, repo, collaborator
18
- normalize! params
32
+ def add(*args)
33
+ arguments(args, :required => [:user, :repo, :collaborator])
34
+ params = arguments.params
19
35
 
20
36
  put_request("/repos/#{user}/#{repo}/collaborators/#{collaborator}", params)
21
37
  end
@@ -27,10 +43,12 @@ module Github
27
43
  # github = Github.new
28
44
  # github.repos.collaborators.collaborator?('user', 'repo', 'collaborator')
29
45
  #
30
- def collaborator?(user_name, repo_name, collaborator, params={})
31
- set :user => user_name, :repo => repo_name
32
- assert_presence_of user, repo, collaborator
33
- normalize! params
46
+ # github = Github.new user: 'user-name', repo: 'repo-name'
47
+ # github.collaborators.collaborator? collaborator: 'collaborator'
48
+ #
49
+ def collaborator?(*args)
50
+ arguments(args, :required => [:user, :repo, :collaborator])
51
+ params = arguments.params
34
52
 
35
53
  get_request("/repos/#{user}/#{repo}/collaborators/#{collaborator}", params)
36
54
  true
@@ -38,34 +56,15 @@ module Github
38
56
  false
39
57
  end
40
58
 
41
- # List collaborators
42
- #
43
- # Examples:
44
- # github = Github.new
45
- # github.repos.collaborators.list 'user-name', 'repo-name'
46
- # github.repos.collaborators.list 'user-name', 'repo-name' { |cbr| .. }
47
- #
48
- def list(user_name, repo_name, params={})
49
- set :user => user_name, :repo => repo_name
50
- assert_presence_of user, repo
51
- normalize! params
52
-
53
- response = get_request("/repos/#{user}/#{repo}/collaborators", params)
54
- return response unless block_given?
55
- response.each { |el| yield el }
56
- end
57
- alias :all :list
58
-
59
59
  # Removes collaborator
60
60
  #
61
61
  # Examples:
62
62
  # github = Github.new
63
63
  # github.repos.collaborators.remove 'user', 'repo', 'collaborator'
64
64
  #
65
- def remove(user_name, repo_name, collaborator, params={})
66
- set :user => user_name, :repo => repo_name
67
- assert_presence_of collaborator
68
- normalize! params
65
+ def remove(*args)
66
+ arguments(args, :required => [:user, :repo, :collaborator])
67
+ params = arguments.params
69
68
 
70
69
  delete_request("/repos/#{user}/#{repo}/collaborators/#{collaborator}", params)
71
70
  end
@@ -25,10 +25,9 @@ module Github
25
25
  # github.repos.comments.list 'user-name', 'repo-name',
26
26
  # :sha => '6dcb09b5b57875f334f61aebed695e2e4193db5e'
27
27
  #
28
- def list(user_name, repo_name, params={})
29
- set :user => user_name, :repo => repo_name
30
- assert_presence_of user, repo
31
- normalize! params
28
+ def list(*args)
29
+ arguments(args, :required => [:user, :repo])
30
+ params = arguments.params
32
31
 
33
32
  response = if (sha = params.delete('sha'))
34
33
  get_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
@@ -46,10 +45,9 @@ module Github
46
45
  # github = Github.new
47
46
  # github.repos.comments.get 'user-name', 'repo-name', 'comment-id'
48
47
  #
49
- def get(user_name, repo_name, comment_id, params={})
50
- set :user => user_name, :repo => repo_name
51
- assert_presence_of user, repo, comment_id
52
- normalize! params
48
+ def get(*args)
49
+ arguments(args, :required => [:user, :repo, :comment_id])
50
+ params = arguments.params
53
51
 
54
52
  get_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
55
53
  end
@@ -73,14 +71,12 @@ module Github
73
71
  # "path" => "file1.txt",
74
72
  # "position" => 4
75
73
  #
76
- def create(user_name, repo_name, sha, params={})
77
- set :user => user_name, :repo => repo_name
78
- assert_presence_of user, repo, sha
79
-
80
- normalize! params
81
- filter! VALID_COMMENT_OPTIONS, params
82
-
83
- assert_required_keys(REQUIRED_COMMENT_OPTIONS, params)
74
+ def create(*args)
75
+ arguments(args, :required => [:user, :repo, :sha]) do
76
+ sift VALID_COMMENT_OPTIONS
77
+ assert_required REQUIRED_COMMENT_OPTIONS
78
+ end
79
+ params = arguments.params
84
80
 
85
81
  post_request("/repos/#{user}/#{repo}/commits/#{sha}/comments", params)
86
82
  end
@@ -95,11 +91,11 @@ module Github
95
91
  # github.repos.comments.update 'user-name', 'repo-name',
96
92
  # 'comment-id', "body" => "Nice change"
97
93
  #
98
- def update(user_name, repo_name, comment_id, params={})
99
- set :user => user_name, :repo => repo_name
100
- assert_presence_of user, repo, comment_id
101
- normalize! params
102
- assert_required_keys(REQUIRED_COMMENT_OPTIONS, params)
94
+ def update(*args)
95
+ arguments(args, :required => [:user, :repo, :comment_id]) do
96
+ assert_required REQUIRED_COMMENT_OPTIONS
97
+ end
98
+ params = arguments.params
103
99
 
104
100
  patch_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
105
101
  end
@@ -110,10 +106,9 @@ module Github
110
106
  # github = Github.new
111
107
  # github.repos.comments.delete 'user-name', 'repo-name', 'comment-id'
112
108
  #
113
- def delete(user_name, repo_name, comment_id, params={})
114
- set :user => user_name, :repo => repo_name
115
- assert_presence_of user, repo, comment_id
116
- normalize! params
109
+ def delete(*args)
110
+ arguments(args, :required => [:user, :repo, :comment_id])
111
+ params = arguments.params
117
112
 
118
113
  delete_request("/repos/#{user}/#{repo}/comments/#{comment_id}", params)
119
114
  end
@@ -23,11 +23,11 @@ module Github
23
23
  # github.repos.commits.list 'user-name', 'repo-name', :sha => '...'
24
24
  # github.repos.commits.list 'user-name', 'repo-name', :sha => '...' { |commit| ... }
25
25
  #
26
- def list(user_name, repo_name, params={})
27
- set :user => user_name, :repo => repo_name
28
- assert_presence_of user, repo
29
- normalize! params
30
- filter! VALID_COMMITS_OPTIONS, params
26
+ def list(*args)
27
+ arguments(args, :required => [:user, :repo]) do
28
+ sift VALID_COMMITS_OPTIONS
29
+ end
30
+ params = arguments.params
31
31
 
32
32
  response = get_request("/repos/#{user}/#{repo}/commits", params)
33
33
  return response unless block_given?
@@ -41,10 +41,9 @@ module Github
41
41
  # github = Github.new
42
42
  # github.repos.commits.get 'user-name', 'repo-name', '6dcb09b5b57875f334f61aebed6')
43
43
  #
44
- def get(user_name, repo_name, sha, params={})
45
- set :user => user_name, :repo => repo_name
46
- assert_presence_of user, repo, sha
47
- normalize! params
44
+ def get(*args)
45
+ arguments(args, :required => [:user, :repo, :sha])
46
+ params = arguments.params
48
47
 
49
48
  get_request("/repos/#{user}/#{repo}/commits/#{sha}", params)
50
49
  end
@@ -60,12 +59,11 @@ module Github
60
59
  # 'v0.4.8',
61
60
  # 'master'
62
61
  #
63
- def compare(user_name, repo_name, base, head, params={})
64
- set :user => user_name, :repo => repo_name
65
- assert_presence_of base, head
66
- normalize! params
62
+ def compare(*args)
63
+ arguments(args, :required => [:user, :repo, :base, :head])
64
+ params = arguments.params
67
65
 
68
- get_request("/repos/#{user_name}/#{repo_name}/compare/#{base}...#{head}", params)
66
+ get_request("/repos/#{user}/#{repo}/compare/#{base}...#{head}", params)
69
67
  end
70
68
 
71
69
  end # Repos::Commits
@@ -1,8 +1,10 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+
5
+ # These API methods let you retrieve the contents of files within a repository
6
+ # as Base64 encoded content.
4
7
  class Repos::Contents < API
5
- # These API methods let you retrieve the contents of files within a repository as Base64 encoded content
6
8
 
7
9
  # Get the README
8
10
  #
@@ -12,11 +14,14 @@ module Github
12
14
  # github = Github.new
13
15
  # github.repos.contents.readme 'user-name', 'repo-name'
14
16
  #
15
- def readme(user_name, repo_name, params={})
16
- set :user => user_name, :repo => repo_name
17
- normalize! params
17
+ # content = Github::Repos;:Contents.new user: 'user-name', 'repo-name'
18
+ # content.readme
19
+ #
20
+ def readme(*args)
21
+ arguments(args, :required => [:user, :repo])
22
+ params = arguments.params
18
23
 
19
- get_request("/repos/#{user_name}/#{repo_name}/readme", params)
24
+ get_request("/repos/#{user}/#{repo}/readme", params)
20
25
  end
21
26
 
22
27
  # Get contents
@@ -30,11 +35,14 @@ module Github
30
35
  # github = Github.new
31
36
  # github.repos.contents.get 'user-name', 'repo-name', 'path'
32
37
  #
33
- def get(user_name, repo_name, path, params={})
34
- set :user => user_name, :repo => repo_name
35
- normalize! params
38
+ # github = Github.new user: 'user-name', repo: 'repo-name'
39
+ # github.repos.contents.get path: 'README.md'
40
+ #
41
+ def get(*args)
42
+ arguments(args, :required => [:user, :repo, :path])
43
+ params = arguments.params
36
44
 
37
- get_request("/repos/#{user_name}/#{repo_name}/contents/#{path}", params)
45
+ get_request("/repos/#{user}/#{repo}/contents/#{path}", params)
38
46
  end
39
47
  alias :find :get
40
48
 
@@ -57,13 +65,13 @@ module Github
57
65
  # "archive_format" => "tarball",
58
66
  # "ref" => "master"
59
67
  #
60
- def archive(user_name, repo_name, params={})
61
- set :user => user_name, :repo => repo_name
62
- normalize! params
68
+ def archive(*args)
69
+ arguments(args, :required => [:user, :repo])
70
+ params = arguments.params
63
71
  archive_format = params.delete('archive_format') || 'zipball'
64
- ref = params.delete('ref') || 'master'
72
+ ref = params.delete('ref') || 'master'
65
73
 
66
- get_request("/repos/#{user_name}/#{repo_name}/#{archive_format}/#{ref}", params)
74
+ get_request("/repos/#{user}/#{repo}/#{archive_format}/#{ref}", params)
67
75
  end
68
76
 
69
77
  end # Repos::Contents
@@ -5,7 +5,7 @@ require 'github_api/s3_uploader'
5
5
  module Github
6
6
  class Repos::Downloads < API
7
7
 
8
- REQUIRED_PARAMS = %w[ name size ]
8
+ REQUIRED_PARAMS = %w[ name size ].freeze
9
9
 
10
10
  VALID_DOWNLOAD_PARAM_NAMES = %w[
11
11
  name
@@ -21,12 +21,10 @@ module Github
21
21
  # github.repos.downloads.list 'user-name', 'repo-name'
22
22
  # github.repos.downloads.list 'user-name', 'repo-name' { |downl| ... }
23
23
  #
24
- def list(user_name, repo_name, params={})
25
- set :user => user_name, :repo => repo_name
26
- assert_presence_of user, repo
27
- normalize! params
24
+ def list(*args)
25
+ arguments(args, :required => [:user, :repo])
28
26
 
29
- response = get_request("/repos/#{user}/#{repo}/downloads", params)
27
+ response = get_request("/repos/#{user}/#{repo}/downloads", arguments.params)
30
28
  return response unless block_given?
31
29
  response.each { |el| yield el }
32
30
  end
@@ -38,10 +36,9 @@ module Github
38
36
  # github = Github.new
39
37
  # github.repos.downloads.get 'user-name', 'repo-name', 'download-id'
40
38
  #
41
- def get(user_name, repo_name, download_id, params={})
42
- set :user => user_name, :repo => repo_name
43
- assert_presence_of user, repo, download_id
44
- normalize! params
39
+ def get(*args)
40
+ arguments(args, :required => [:user, :repo, :download_id])
41
+ params = arguments.params
45
42
 
46
43
  get_request("/repos/#{user}/#{repo}/downloads/#{download_id}", params)
47
44
  end
@@ -53,13 +50,13 @@ module Github
53
50
  # github = Github.new
54
51
  # github.repos.downloads.delete 'user-name', 'repo-name', 'download-id'
55
52
  #
56
- def delete(user_name, repo_name, download_id, params={})
57
- set :user => user_name, :repo => repo_name
58
- assert_presence_of user, repo, download_id
59
- normalize! params
53
+ def delete(*args)
54
+ arguments(args, :required => [:user, :repo, :download_id])
55
+ params = arguments.params
60
56
 
61
57
  delete_request("/repos/#{user}/#{repo}/downloads/#{download_id}", params)
62
58
  end
59
+ alias :remove :delete
63
60
 
64
61
  # Creating a new download is a two step process.
65
62
  # You must first create a new download resource using this method.
@@ -79,13 +76,12 @@ module Github
79
76
  # "description" => "Latest release",
80
77
  # "content_type" => "text/plain"
81
78
  #
82
- def create(user_name, repo_name, params={})
83
- set :user => user_name, :repo => repo_name
84
- assert_presence_of user, repo
85
-
86
- normalize! params
87
- filter! VALID_DOWNLOAD_PARAM_NAMES, params
88
- assert_required_keys(REQUIRED_PARAMS, params)
79
+ def create(*args)
80
+ arguments(args, :required => [:user, :repo]) do
81
+ sift VALID_DOWNLOAD_PARAM_NAMES
82
+ assert_required REQUIRED_PARAMS
83
+ end
84
+ params = arguments.params
89
85
 
90
86
  post_request("/repos/#{user}/#{repo}/downloads", params)
91
87
  end
@@ -103,8 +99,8 @@ module Github
103
99
  #
104
100
  # github.repos.downloads.upload resource, '/users/octokit/image.jpg'
105
101
  #
106
- def upload(resource, filename)
107
- assert_presence_of resource, filename
102
+ def upload(*args)
103
+ arguments(args, :required => [:resource, :filename])
108
104
 
109
105
  response = Github::S3Uploader.new(resource, filename).send
110
106
  response.body
@@ -13,12 +13,10 @@ module Github
13
13
  # github.repos.forks.list 'user-name', 'repo-name'
14
14
  # github.repos.forks.list 'user-name', 'repo-name' { |fork| ... }
15
15
  #
16
- def list(user_name, repo_name, params = {})
17
- set :user => user_name, :repo => repo_name
18
- assert_presence_of user, repo
19
- normalize! params
16
+ def list(*args)
17
+ arguments(args, :required => [:user, :repo])
20
18
 
21
- response = get_request("/repos/#{user}/#{repo}/forks", params)
19
+ response = get_request("/repos/#{user}/#{repo}/forks", arguments.params)
22
20
  return response unless block_given?
23
21
  response.each { |el| yield el }
24
22
  end
@@ -34,13 +32,10 @@ module Github
34
32
  # github.repos.forks.create 'user-name', 'repo-name',
35
33
  # "org" => "github"
36
34
  #
37
- def create(user_name, repo_name, params={})
38
- set :user => user_name, :repo => repo_name
39
- assert_presence_of user, repo
40
- normalize! params
41
- filter! %w[ org ], params
35
+ def create(*args)
36
+ arguments(args, :required => [:user, :repo])
42
37
 
43
- post_request("/repos/#{user}/#{repo}/forks", params)
38
+ post_request("/repos/#{user}/#{repo}/forks", arguments.params)
44
39
  end
45
40
 
46
41
  end # Repos::Forks
@@ -1,6 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
+
4
5
  # The Repository Hooks API manages the post-receive web and
5
6
  # service hooks for a repository.
6
7
  class Repos::Hooks < API
@@ -42,12 +43,10 @@ module Github
42
43
  # github.repos.hooks.list 'user-name', 'repo-name'
43
44
  # github.repos.hooks.list 'user-name', 'repo-name' { |hook| ... }
44
45
  #
45
- def list(user_name, repo_name, params={})
46
- set :user => user_name, :repo => repo_name
47
- assert_presence_of user, repo
48
- normalize! params
46
+ def list(*args)
47
+ arguments(args, :required => [:user, :repo])
49
48
 
50
- response = get_request("/repos/#{user}/#{repo}/hooks", params)
49
+ response = get_request("/repos/#{user}/#{repo}/hooks", arguments.params)
51
50
  return response unless block_given?
52
51
  response.each { |el| yield el }
53
52
  end
@@ -59,12 +58,10 @@ module Github
59
58
  # github = Github.new
60
59
  # github.repos.hooks.get 'user-name', 'repo-name'
61
60
  #
62
- def get(user_name, repo_name, hook_id, params={})
63
- set :user => user_name, :repo => repo_name
64
- assert_presence_of user, repo, hook_id
65
- normalize! params
61
+ def get(*args)
62
+ arguments(args, :required => [:user, :repo, :hook_id])
66
63
 
67
- get_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
64
+ get_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", arguments.params)
68
65
  end
69
66
  alias :find :get
70
67
 
@@ -86,15 +83,13 @@ module Github
86
83
  # }
87
84
  # }
88
85
  #
89
- def create(user_name, repo_name, params={})
90
- set :user => user_name, :repo => repo_name
91
- assert_presence_of user, repo
92
-
93
- normalize! params
94
- filter! VALID_HOOK_PARAM_NAMES, params, :recursive => false
95
- assert_required_keys(REQUIRED_PARAMS, params)
86
+ def create(*args)
87
+ arguments(args, :required => [:user, :repo]) do
88
+ sift VALID_HOOK_PARAM_NAMES, :recursive => false
89
+ assert_required REQUIRED_PARAMS
90
+ end
96
91
 
97
- post_request("/repos/#{user}/#{repo}/hooks", params)
92
+ post_request("/repos/#{user}/#{repo}/hooks", arguments.params)
98
93
  end
99
94
 
100
95
  # Edit a hook
@@ -118,15 +113,13 @@ module Github
118
113
  # "token" => "abc123"
119
114
  # }
120
115
  #
121
- def edit(user_name, repo_name, hook_id, params={})
122
- set :user => user_name, :repo => repo_name
123
- assert_presence_of user, repo, hook_id
124
-
125
- normalize! params
126
- filter! VALID_HOOK_PARAM_NAMES, params, :recursive => false
127
- assert_required_keys(REQUIRED_PARAMS, params)
116
+ def edit(*args)
117
+ arguments(args, :required => [:user, :repo, :hook_id]) do
118
+ sift VALID_HOOK_PARAM_NAMES, :recursive => false
119
+ assert_required REQUIRED_PARAMS
120
+ end
128
121
 
129
- patch_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
122
+ patch_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", arguments.params)
130
123
  end
131
124
 
132
125
  # Test a hook
@@ -137,10 +130,9 @@ module Github
137
130
  # github = Github.new
138
131
  # github.repos.hooks.test 'user-name', 'repo-name', 'hook-id'
139
132
  #
140
- def test(user_name, repo_name, hook_id, params={})
141
- set :user => user_name, :repo => repo_name
142
- assert_presence_of user, repo, hook_id
143
- normalize! params
133
+ def test(*args)
134
+ arguments(args, :required => [:user, :repo, :hook_id])
135
+ params = arguments.params
144
136
 
145
137
  post_request("/repos/#{user}/#{repo}/hooks/#{hook_id}/test", params)
146
138
  end
@@ -151,10 +143,9 @@ module Github
151
143
  # github = Github.new
152
144
  # github.repos.hooks.delete 'user-name', 'repo-name', 'hook-id'
153
145
  #
154
- def delete(user_name, repo_name, hook_id, params={})
155
- set :user => user_name, :repo => repo_name
156
- assert_presence_of user, repo, hook_id
157
- normalize! params
146
+ def delete(*args)
147
+ arguments(args, :required => [:user, :repo, :hook_id])
148
+ params = arguments.params
158
149
 
159
150
  delete_request("/repos/#{user}/#{repo}/hooks/#{hook_id}", params)
160
151
  end