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
data/README.md CHANGED
@@ -18,13 +18,13 @@ Supports all the API methods(nearly 200). It's build in a modular way, that is,
18
18
  * Modular design allows for working with parts of API.
19
19
  * Fully customizable including advanced middleware stack construction.
20
20
  * Its comprehensive, you can request all GitHub API resources.
21
+ * Flexible arguments parsing, you can write expressive and natural queries.
21
22
  * Requests pagination with convenient DSL.
22
23
  * Easy error handling split for client and server type errors.
23
24
  * Supports multithreaded environment.
24
- * Custom mime types specification (Status: TODO)
25
- * Flexible arguments parsing (Status: In progress).
25
+ * Custom mime types specification (Status: In Progess)
26
26
  * Request results caching (Status: TODO)
27
- * Fully tested with test coverage above 90% with over 1,400 specs and 700 features.
27
+ * Fully tested with test coverage above 90% with over 1,500 specs and 700 features.
28
28
 
29
29
  ## Installation
30
30
 
@@ -60,11 +60,12 @@ At this stage you can also supply various configuration parameters, such as `:us
60
60
  github = Github.new oauth_token: 'token'
61
61
  ```
62
62
 
63
- Alternatively, you can configure the Github settings by passing a block, for instance, with custom enterprise endpoint like
63
+ Alternatively, you can configure the Github settings by passing a block, for instance, with custom enterprise endpoint and website like
64
64
 
65
65
  ```ruby
66
66
  github = Github.new do |config|
67
67
  config.endpoint = 'https://github.company.com/api/v3'
68
+ config.site = 'https://github.company.com'
68
69
  config.oauth_token = 'token'
69
70
  config.adapter = :net_http
70
71
  config.ssl = {:verify => false}
@@ -110,7 +111,51 @@ repos.branches do |branch|
110
111
  end
111
112
  ```
112
113
 
113
- ## Inputs
114
+ ## Arguments & Parameters
115
+
116
+ The library allows for flexible arguments parsing. Therefore arguments can be passed during instance creation:
117
+
118
+ ```ruby
119
+ issues = Github::Issues.new user: 'peter-murach', repo: 'github'
120
+ issues.milestones.list state: 'open'
121
+ ```
122
+
123
+ Further, arguments can be passed directly inside method called but then the order of parameters matters and hence please consult the method documentation or GitHub specification. For instance:
124
+
125
+ ```ruby
126
+ issues = Github::Issues.new
127
+ issues.milestones.list 'peter-murach', 'github', state: 'open'
128
+ ```
129
+
130
+ Similarly, the arguments for the request can be passed inside the current scope such as:
131
+
132
+ ```ruby
133
+ issues = Github::Issues.new
134
+ issues.milestones(user: 'peter-murach', repo: 'github').list
135
+ ```
136
+
137
+ But why limit ourselves? You can mix and match arguments, for example:
138
+
139
+ ```ruby
140
+ issues = Github::Issues.new user: 'peter-murach'
141
+ issues.milestones(repo: 'github').list
142
+ issues.milestones(repo: 'tty').list
143
+ ```
144
+
145
+ Finally, you can use a bit of syntactic sugar common among ruby libraries whereby "username/repository" can be passed as well:
146
+
147
+ ```ruby
148
+ issues = Github::Issues.new
149
+ issues.milestones('peter-murach/github').list
150
+ issues.milestones.list 'peter-murach/github'
151
+ ```
152
+
153
+ Finally, use `with` scope to clearly denote your requests
154
+
155
+ ```ruby
156
+ issues = Github::Issues.new
157
+ issues.milestones.with(user:'peter-murach', repo: 'github').list
158
+ ```
114
159
 
115
160
  Some API methods apart from required parameters such as username, repository name
116
161
  or organisation name, allow you to switch the way the data is returned to you, for instance
@@ -0,0 +1,69 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://<BASIC_AUTH>@api.github.com/repos/boyan/github/git/commits/aca2a25d442a9545b01f42574c46f59035993b02?access_token=<TOKEN>
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ''
9
+ headers:
10
+ Accept:
11
+ - application/vnd.github.v3.full+json,application/vnd.github.beta.full+json;q=0.7,application/vnd.github+json;q=0.5,application/json;q=0.1
12
+ Accept-Charset:
13
+ - utf-8
14
+ User-Agent:
15
+ - Github Ruby Gem 0.9.0
16
+ Content-Type:
17
+ - application/json
18
+ Accept-Encoding:
19
+ - gzip;q=1.0,deflate;q=0.6,identity;q=0.3
20
+ response:
21
+ status:
22
+ code: 200
23
+ message: OK
24
+ headers:
25
+ Server:
26
+ - GitHub.com
27
+ Date:
28
+ - Tue, 19 Feb 2013 22:32:05 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 200 OK
37
+ X-Ratelimit-Limit:
38
+ - '5000'
39
+ X-Ratelimit-Remaining:
40
+ - '4999'
41
+ Vary:
42
+ - Accept, Authorization, Cookie
43
+ Cache-Control:
44
+ - private, max-age=60, s-maxage=60
45
+ Last-Modified:
46
+ - Thu, 14 Feb 2013 13:30:02 GMT
47
+ Etag:
48
+ - ! '"ebbd81db82247bdc737b6bed8b3a8f14"'
49
+ X-Github-Media-Type:
50
+ - github.v3; param=full; format=json
51
+ X-Content-Type-Options:
52
+ - nosniff
53
+ Content-Encoding:
54
+ - gzip
55
+ body:
56
+ encoding: ASCII-8BIT
57
+ string: !binary |-
58
+ H4sIAAAAAAAAA7WSwW7cIBRFfwWxapVkDBh7jFdtpar9gK7a6eJhHgbFxhbg
59
+ NtFo/r04SaMs00hdIb3H5VwdcabJAe0pDCBANEZKAaqRjWbcStEc5SBb2yhW
60
+ N0rVmgl6Tbc4lYDLeU19VcHqD6PPbtOHYZmriOuSKr3cQ6gex/tRldXsc6r+
61
+ AQNbdkuk/ZkGmLEQP+2Pko8T3kEwcflVquAMfi/zwPsAz6uDz2VrIO85wXh9
62
+ w8QNl9943desZ+I7vVzTx04Z/ycjRywVzk+S1WD0YJUWrBlQ1Nx23HDbCoO6
63
+ xc7KGgDKDN8oeYel6tWQomDGlGDcJa2QElkhO+JDygiGLJakweGMV25J+eph
64
+ V2YrxISmHKMPkP0SyOTDbTqFU8gOI+p7Yv2dD+PLKz6QLz5/3TT5HIrwNfqE
65
+ 5N1v5yckYclER4TbPeNz4Z9CxHGbID6F3hcfBYshJ9r/eJZpOsWUNkfbSVsf
66
+ eddJOTSqbg0b2hZFwy3jSvA3yvz7Y9VrMZeflz8/MxWrTQMAAA==
67
+ http_version: !!null
68
+ recorded_at: Tue, 19 Feb 2013 22:32:05 GMT
69
+ recorded_with: VCR 2.4.0
@@ -0,0 +1,14 @@
1
+ Feature: GitData Commits API
2
+
3
+ Background:
4
+ Given I have "Github::GitData::Commits" instance
5
+
6
+ Scenario: Gets a single commit
7
+
8
+ Given I want to get resource with the following params:
9
+ | user | repo | sha |
10
+ | boyan | github | aca2a25d442a9545b01f42574c46f59035993b02 |
11
+ When I make request within a cassette named "git_data/commits/get"
12
+ Then the response status should be 200
13
+ And the response type should be JSON
14
+ And the response should not be empty
data/lib/github_api.rb CHANGED
@@ -57,6 +57,7 @@ module Github
57
57
 
58
58
  autoload_all 'github_api',
59
59
  :API => 'api',
60
+ :Arguments => 'arguments',
60
61
  :Activity => 'activity',
61
62
  :ApiFactory => 'api_factory',
62
63
  :Client => 'client',
@@ -10,10 +10,10 @@ module Github
10
10
  # github.activity.events.public
11
11
  # github.activity.events.public { |event| ... }
12
12
  #
13
- def public(params={})
14
- normalize! params
13
+ def public(*args)
14
+ arguments(args)
15
15
 
16
- response = get_request("/events", params)
16
+ response = get_request("/events", arguments.params)
17
17
  return response unless block_given?
18
18
  response.each { |el| yield el }
19
19
  end
@@ -28,12 +28,13 @@ module Github
28
28
  # github.activity.events.repository 'user-name', 'repo-name'
29
29
  # github.activity.events.repository 'user-name', 'repo-name' { |event| ... }
30
30
  #
31
- def repository(user_name, repo_name, params={})
32
- set :user => user_name, :repo => repo_name
33
- assert_presence_of user, repo
34
- normalize! params
31
+ # github.events.repository user: 'user-name', repo: 'repo-name'
32
+ # github.events.repository user: 'user-name', repo: 'repo-name' {|event| ... }
33
+ #
34
+ def repository(*args)
35
+ arguments(args, :required => [:user, :repo])
35
36
 
36
- response = get_request("/repos/#{user}/#{repo}/events", params)
37
+ response = get_request("/repos/#{user}/#{repo}/events", arguments.params)
37
38
  return response unless block_given?
38
39
  response.each { |el| yield el }
39
40
  end
@@ -49,10 +50,12 @@ module Github
49
50
  # github.activity.events.issue 'user-name', 'repo-name'
50
51
  # github.activity.events.issue 'user-name', 'repo-name' { |event| ... }
51
52
  #
52
- def issue(user_name, repo_name, params={})
53
- set :user => user_name, :repo => repo_name
54
- assert_presence_of user, repo
55
- normalize! params
53
+ # github.events.issue user: 'user-name', repo: 'repo-name'
54
+ # github.events.issue user: 'user-name', repo: 'repo-name' { |event| ... }
55
+ #
56
+ def issue(*args)
57
+ arguments(args, :required => [:user, :repo])
58
+ params = arguments.params
56
59
 
57
60
  response = get_request("/repos/#{user}/#{repo}/issues/events", params)
58
61
  return response unless block_given?
@@ -69,12 +72,13 @@ module Github
69
72
  # github.activity.events.network 'user-name', 'repo-name'
70
73
  # github.activity.events.network 'user-name', 'repo-name' { |event| ... }
71
74
  #
72
- def network(user_name, repo_name, params={})
73
- set :user => user_name, :repo => repo_name
74
- assert_presence_of user, repo
75
- normalize! params
75
+ # github.events.network user: 'user-name', repo: 'repo-name'
76
+ # github.events.network user: 'user-name', repo: 'repo-name' { |event| ... }
77
+ #
78
+ def network(*args)
79
+ arguments(args, :required => [:user, :repo])
76
80
 
77
- response = get_request("/networks/#{user}/#{repo}/events", params)
81
+ response = get_request("/networks/#{user}/#{repo}/events", arguments.params)
78
82
  return response unless block_given?
79
83
  response.each { |el| yield el }
80
84
  end
@@ -90,11 +94,13 @@ module Github
90
94
  # github.activity.events.org 'org-name'
91
95
  # github.activity.events.org 'org-name' { |event| ... }
92
96
  #
93
- def org(org_name, params={})
94
- assert_presence_of org_name
95
- normalize! params
97
+ # github.events.org org: 'org-name'
98
+ # github.events.org org: 'org-name' { |event| ... }
99
+ #
100
+ def org(*args)
101
+ arguments(args, :required => [:org_name])
96
102
 
97
- response = get_request("/orgs/#{org_name}/events", params)
103
+ response = get_request("/orgs/#{org_name}/events", arguments.params)
98
104
  return response unless block_given?
99
105
  response.each { |el| yield el }
100
106
  end
@@ -121,16 +127,16 @@ module Github
121
127
  # github.activity.events.received 'user-name', :public => true
122
128
  # github.activity.events.received 'user-name', :public => true { |event| ... }
123
129
  #
124
- def received(user_name, params={})
125
- assert_presence_of user_name
126
- normalize! params
130
+ def received(*args)
131
+ arguments(args, :required => [:user])
132
+ params = arguments.params
127
133
 
128
134
  public_events = if params['public']
129
135
  params.delete('public')
130
136
  '/public'
131
137
  end
132
138
 
133
- response = get_request("/users/#{user_name}/received_events#{public_events}", params)
139
+ response = get_request("/users/#{user}/received_events#{public_events}", params)
134
140
  return response unless block_given?
135
141
  response.each { |el| yield el }
136
142
  end
@@ -154,16 +160,16 @@ module Github
154
160
  # github.activity.events.performed 'user-name', :public => true
155
161
  # github.activity.events.performed 'user-name', :public => true { |event| ... }
156
162
  #
157
- def performed(user_name, params={})
158
- assert_presence_of user_name
159
- normalize! params
163
+ def performed(*args)
164
+ arguments(args, :required => [:user])
165
+ params = arguments.params
160
166
 
161
167
  public_events = if params['public']
162
168
  params.delete('public')
163
169
  '/public'
164
170
  end
165
171
 
166
- response = get_request("/users/#{user_name}/events#{public_events}", params)
172
+ response = get_request("/users/#{user}/events#{public_events}", params)
167
173
  return response unless block_given?
168
174
  response.each { |el| yield el }
169
175
  end
@@ -180,11 +186,14 @@ module Github
180
186
  # github.activity.events.user_org 'user-name', 'org-name'
181
187
  # github.activity.events.user_org 'user-name', 'org-name' { |event| ... }
182
188
  #
183
- def user_org(user_name, org_name, params={})
184
- assert_presence_of user_name, org_name
185
- normalize! params
189
+ # github.events.user_org user: 'user-name', org_name: 'org-name'
190
+ # github.events.user_org user: 'user-name', org_name: 'org-name' {|event| ...}
191
+ #
192
+ def user_org(*args)
193
+ arguments(args, :required => [:user, :org_name])
194
+ params = arguments.params
186
195
 
187
- response = get_request("/users/#{user_name}/events/orgs/#{org_name}", params)
196
+ response = get_request("/users/#{user}/events/orgs/#{org_name}", params)
188
197
  return response unless block_given?
189
198
  response.each { |el| yield el }
190
199
  end
@@ -28,9 +28,9 @@ module Github
28
28
  # github.activity.notifications.list user: 'user-name', repo: 'repo-name'
29
29
  #
30
30
  def list(*args)
31
- params = args.extract_options!
32
- normalize! params
33
- filter! %w[ all participating since user repo], params
31
+ params = arguments(args) do
32
+ sift %w[ all participating since user repo]
33
+ end.params
34
34
 
35
35
  response = if ( (user_name = params.delete("user")) &&
36
36
  (repo_name = params.delete("repo")) )
@@ -50,10 +50,10 @@ module Github
50
50
  # github.activity.notifications.get 'thread_id'
51
51
  # github.activity.notifications.get 'thread_id' { |thread| ... }
52
52
  #
53
- def get(thread_id, params={})
54
- assert_presence_of thread_id
55
- normalize! params
56
- response = get_request("/notifications/threads/#{thread_id}", params)
53
+ def get(*args)
54
+ arguments(args, :required => [:thread_id])
55
+
56
+ response = get_request("/notifications/threads/#{thread_id}", arguments.params)
57
57
  return response unless block_given?
58
58
  response.each { |el| yield el }
59
59
  end
@@ -89,9 +89,9 @@ module Github
89
89
  # github.activity.notifications.mark thread_id: 'id', read: true
90
90
  #
91
91
  def mark(*args)
92
- params = args.extract_options!
93
- normalize! params
94
- filter! %w[ unread read last_read_at user repo thread_id], params
92
+ params = arguments(args) do
93
+ sift %w[ unread read last_read_at user repo thread_id]
94
+ end.params
95
95
 
96
96
  if ( (user_name = params.delete("user")) &&
97
97
  (repo_name = params.delete("repo")) )
@@ -110,10 +110,10 @@ module Github
110
110
  # github = Github.new oauth_token: 'token'
111
111
  # github.activity.notifications.subscribed? 'thread-id'
112
112
  #
113
- def subscribed?(thread_id, params={})
114
- assert_presence_of thread_id
115
- normalize! params
116
- get_request("/notifications/threads/#{thread_id}/subscription", params)
113
+ def subscribed?(*args)
114
+ arguments(args, :required => [:thread_id])
115
+
116
+ get_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
117
117
  end
118
118
 
119
119
  # Create a thread subscription
@@ -134,10 +134,10 @@ module Github
134
134
  # 'subscribed': true
135
135
  # 'ignored': false
136
136
  #
137
- def create(thread_id, params={})
138
- assert_presence_of thread_id
139
- normalize! params
140
- put_request("/notifications/threads/#{thread_id}/subscription", params)
137
+ def create(*args)
138
+ arguments(args, :required => [:thread_id])
139
+
140
+ put_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
141
141
  end
142
142
 
143
143
  # Delete a thread subscription
@@ -146,10 +146,10 @@ module Github
146
146
  # github = Github.new oauth_token: 'token'
147
147
  # github.activity.notifications.delete 'thread_id'
148
148
  #
149
- def delete(thread_id, params={})
150
- assert_presence_of thread_id
151
- normalize! params
152
- delete_request("/notifications/threads/#{thread_id}/subscription", params)
149
+ def delete(*args)
150
+ arguments(args, :required => [:thread_id])
151
+
152
+ delete_request("/notifications/threads/#{thread_id}/subscription", arguments.params)
153
153
  end
154
154
  alias :remove :delete
155
155
 
@@ -12,12 +12,10 @@ module Github
12
12
  # github.activity.starring.list
13
13
  # github.activity.starring.list { |star| ... }
14
14
  #
15
- def list(user_name, repo_name, params={})
16
- set :user => user_name, :repo => repo_name
17
- assert_presence_of user, repo
18
- normalize! params
15
+ def list(*args)
16
+ arguments(args, :required => [:user, :repo])
19
17
 
20
- response = get_request("/repos/#{user}/#{repo}/stargazers", params)
18
+ response = get_request("/repos/#{user}/#{repo}/stargazers", arguments.params)
21
19
  return response unless block_given?
22
20
  response.each { |el| yield el }
23
21
  end
@@ -36,8 +34,7 @@ module Github
36
34
  # github.activity.starring.starred
37
35
  #
38
36
  def starred(*args)
39
- params = args.extract_options!
40
- normalize! params
37
+ params = arguments(args).params
41
38
 
42
39
  response = if (user_name = params.delete('user'))
43
40
  get_request("/users/#{user_name}/starred", params)
@@ -56,10 +53,10 @@ module Github
56
53
  # github = Github.new
57
54
  # github.activity.starring.starring? 'user-name', 'repo-name'
58
55
  #
59
- def starring?(user_name, repo_name, params={})
60
- assert_presence_of user_name, repo_name
61
- normalize! params
62
- get_request("/user/starred/#{user_name}/#{repo_name}", params)
56
+ def starring?(*args)
57
+ arguments(args, :required => [:user, :repo])
58
+
59
+ get_request("/user/starred/#{user}/#{repo}", arguments.params)
63
60
  true
64
61
  rescue Github::Error::NotFound
65
62
  false
@@ -73,11 +70,10 @@ module Github
73
70
  # github = Github.new
74
71
  # github.activity.starring.star 'user-name', 'repo-name'
75
72
  #
76
- def star(user_name, repo_name, params={})
77
- set :user => user_name, :repo => repo_name
78
- assert_presence_of user_name, repo_name
79
- normalize! params
80
- put_request("/user/starred/#{user_name}/#{repo_name}", params)
73
+ def star(*args)
74
+ arguments(args, :required => [:user, :repo])
75
+
76
+ put_request("/user/starred/#{user}/#{repo}", arguments.params)
81
77
  end
82
78
 
83
79
  # Unstar a repository
@@ -88,11 +84,10 @@ module Github
88
84
  # github = Github.new
89
85
  # github.activity.starring.unstar 'user-name', 'repo-name'
90
86
  #
91
- def unstar(user_name, repo_name, params={})
92
- set :user => user_name, :repo => repo_name
93
- assert_presence_of user_name, repo_name
94
- normalize! params
95
- delete_request("/user/starred/#{user_name}/#{repo_name}", params)
87
+ def unstar(*args)
88
+ arguments(args, :required => [:user, :repo])
89
+
90
+ delete_request("/user/starred/#{user}/#{repo}", arguments.params)
96
91
  end
97
92
 
98
93
  end # Activity::Starring