github_api 0.7.0 → 0.7.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (63) hide show
  1. data/README.md +11 -5
  2. data/Rakefile +2 -0
  3. data/features/repos/statuses.feature +12 -12
  4. data/lib/github_api/api.rb +1 -1
  5. data/lib/github_api/authorizations.rb +3 -3
  6. data/lib/github_api/events.rb +7 -7
  7. data/lib/github_api/gists.rb +7 -7
  8. data/lib/github_api/gists/comments.rb +4 -4
  9. data/lib/github_api/git_data/blobs.rb +2 -3
  10. data/lib/github_api/git_data/commits.rb +2 -3
  11. data/lib/github_api/git_data/references.rb +10 -17
  12. data/lib/github_api/git_data/tags.rb +2 -3
  13. data/lib/github_api/git_data/trees.rb +2 -3
  14. data/lib/github_api/issues.rb +4 -6
  15. data/lib/github_api/issues/assignees.rb +5 -4
  16. data/lib/github_api/issues/comments.rb +5 -10
  17. data/lib/github_api/issues/events.rb +2 -3
  18. data/lib/github_api/issues/labels.rb +11 -20
  19. data/lib/github_api/issues/milestones.rb +5 -8
  20. data/lib/github_api/orgs.rb +2 -2
  21. data/lib/github_api/orgs/members.rb +7 -7
  22. data/lib/github_api/orgs/teams.rb +13 -13
  23. data/lib/github_api/page_iterator.rb +3 -1
  24. data/lib/github_api/pull_requests.rb +8 -16
  25. data/lib/github_api/pull_requests/comments.rb +5 -10
  26. data/lib/github_api/repos.rb +27 -8
  27. data/lib/github_api/repos/collaborators.rb +4 -7
  28. data/lib/github_api/repos/commits.rb +9 -16
  29. data/lib/github_api/repos/downloads.rb +5 -7
  30. data/lib/github_api/repos/forks.rb +3 -3
  31. data/lib/github_api/repos/hooks.rb +10 -13
  32. data/lib/github_api/repos/keys.rb +5 -8
  33. data/lib/github_api/repos/pub_sub_hubbub.rb +4 -4
  34. data/lib/github_api/repos/starring.rb +4 -4
  35. data/lib/github_api/repos/statuses.rb +2 -2
  36. data/lib/github_api/repos/watching.rb +4 -4
  37. data/lib/github_api/users/followers.rb +3 -3
  38. data/lib/github_api/users/keys.rb +3 -3
  39. data/lib/github_api/validations/presence.rb +16 -17
  40. data/lib/github_api/version.rb +1 -1
  41. data/spec/fixtures/repos/repos_sorted_by_pushed.json +56 -0
  42. data/spec/github/git_data_spec.rb +5 -7
  43. data/spec/github/issues_spec.rb +12 -12
  44. data/spec/github/orgs_spec.rb +2 -4
  45. data/spec/github/pull_requests_spec.rb +1 -1
  46. data/spec/github/repos/branch_spec.rb +48 -0
  47. data/spec/github/repos/branches_spec.rb +62 -0
  48. data/spec/github/repos/contributors_spec.rb +62 -0
  49. data/spec/github/repos/create_spec.rb +77 -0
  50. data/spec/github/repos/delete_spec.rb +43 -0
  51. data/spec/github/repos/downloads_spec.rb +51 -45
  52. data/spec/github/repos/edit_spec.rb +66 -0
  53. data/spec/github/repos/forks/create_spec.rb +49 -0
  54. data/spec/github/repos/forks/list_spec.rb +65 -0
  55. data/spec/github/repos/get_spec.rb +57 -0
  56. data/spec/github/repos/languages_spec.rb +61 -0
  57. data/spec/github/repos/list_spec.rb +99 -0
  58. data/spec/github/repos/tags_spec.rb +59 -0
  59. data/spec/github/repos/teams_spec.rb +59 -0
  60. data/spec/github/repos_spec.rb +13 -578
  61. data/spec/github/validations/presence_spec.rb +23 -4
  62. metadata +48 -42
  63. data/spec/github/repos/forks_spec.rb +0 -106
data/README.md CHANGED
@@ -11,9 +11,6 @@ A Ruby wrapper for the GitHub REST API v3.
11
11
 
12
12
  Supports all the API methods(nearly 200). It's build in a modular way, that is, you can either instantiate the whole api wrapper Github.new or use parts of it e.i. Github::Repos.new if working solely with repositories is your main concern.
13
13
 
14
- ## Important!!
15
- Since version 0.5 the way the gem queries the GitHub api underwent important changes. It closely mirros the Github api hierarchy e.i. if you want to create a download resource, lookup the github api spec and issue the request as in `github.repos.downloads.create`
16
-
17
14
  ## Installation
18
15
 
19
16
  Install the gem by issuing
@@ -30,7 +27,13 @@ gem "github_api"
30
27
 
31
28
  ## Usage
32
29
 
33
- Create a new client instance
30
+ To start using the gem you can either perform direct call on the `Github`
31
+
32
+ ```ruby
33
+ Github.repos.list user: 'wycats'
34
+ ```
35
+
36
+ or create a new client instance
34
37
 
35
38
  ```ruby
36
39
  github = Github.new
@@ -64,7 +67,10 @@ or use convenience method:
64
67
  github = Github.new basic_auth: 'login:password'
65
68
  ```
66
69
 
67
- You can interact with GitHub interface, for example repositories, by issuing following calls that correspond directly to the GitHub API hierarchy
70
+ This gem closely mirros the GitHub Api hierarchy e.i. if you want to create a download resource,
71
+ lookup the github api spec and issue the request as in `github.repos.downloads.create`
72
+
73
+ For example to interact with GitHub Repositories API, issue the following calls that correspond directly to the GitHub API hierarchy
68
74
 
69
75
  ```ruby
70
76
  github.repos.commits.all 'user-name', 'repo-name'
data/Rakefile CHANGED
@@ -10,4 +10,6 @@ end
10
10
 
11
11
  Cucumber::Rake::Task.new(:features)
12
12
 
13
+ FileList['tasks/**/*.rake'].each { |task| import task }
14
+
13
15
  task :default => [:spec, :features]
@@ -13,15 +13,15 @@ Feature: Statuses API
13
13
  And the response type should be JSON
14
14
  And the response should not be empty
15
15
 
16
- Scenario: Create
17
-
18
- Given I want to create resource with the following params:
19
- | user | repo | sha |
20
- | murek | github_api_test | 0106b45311ab15bf837c2830391b01cd17b33b61 |
21
- And I pass the following request options:
22
- | state | target_url | description |
23
- | success | http://ci.example.com/peter-murach | Test by github_api |
24
- When I make request within a cassette named "repos/statuses/create"
25
- Then the response status should be 201
26
- And the response type should be JSON
27
- And the response should not be empty
16
+ # Scenario: Create
17
+ #
18
+ # Given I want to create resource with the following params:
19
+ # | user | repo | sha |
20
+ # | murek | github_api_test | 0106b45311ab15bf837c2830391b01cd17b33b61 |
21
+ # And I pass the following request options:
22
+ # | state | target_url | description |
23
+ # | success | http://ci.example.com/peter-murach | Test by github_api |
24
+ # When I make request within a cassette named "repos/statuses/create"
25
+ # Then the response status should be 201
26
+ # And the response type should be JSON
27
+ # And the response should not be empty
@@ -88,7 +88,7 @@ module Github
88
88
 
89
89
  def update_settings(options={})
90
90
  options.each do |key, val|
91
- self.instance_variable_set(:"@#{key}", val)
91
+ self.send(:"#{key}", val)
92
92
  end
93
93
  end
94
94
 
@@ -38,7 +38,7 @@ module Github
38
38
  # github.oauth.get 'authorization-id'
39
39
  #
40
40
  def get(authorization_id, params={})
41
- _validate_presence_of(authorization_id)
41
+ assert_presence_of(authorization_id)
42
42
  _check_if_authenticated
43
43
  normalize! params
44
44
 
@@ -81,7 +81,7 @@ module Github
81
81
  #
82
82
  def update(authorization_id, params={})
83
83
  _check_if_authenticated
84
- _validate_presence_of(authorization_id)
84
+ assert_presence_of authorization_id
85
85
 
86
86
  normalize! params
87
87
  filter! VALID_AUTH_PARAM_NAMES, params
@@ -96,7 +96,7 @@ module Github
96
96
  #
97
97
  def delete(authorization_id, params={})
98
98
  _check_if_authenticated
99
- _validate_presence_of(authorization_id)
99
+ assert_presence_of authorization_id
100
100
 
101
101
  normalize! params
102
102
  filter! VALID_AUTH_PARAM_NAMES, params
@@ -35,7 +35,7 @@ module Github
35
35
  #
36
36
  def repository(user_name, repo_name, params={})
37
37
  _update_user_repo_params(user_name, repo_name)
38
- _validate_user_repo_params(user, repo) unless user? && repo?
38
+ assert_presence_of user, repo
39
39
  normalize! params
40
40
 
41
41
  response = get_request("/repos/#{user}/#{repo}/events", params)
@@ -56,7 +56,7 @@ module Github
56
56
  #
57
57
  def issue(user_name, repo_name, params={})
58
58
  _update_user_repo_params(user_name, repo_name)
59
- _validate_user_repo_params(user, repo) unless user? && repo?
59
+ assert_presence_of user, repo
60
60
  normalize! params
61
61
 
62
62
  response = get_request("/repos/#{user}/#{repo}/issues/events", params)
@@ -76,7 +76,7 @@ module Github
76
76
  #
77
77
  def network(user_name, repo_name, params={})
78
78
  _update_user_repo_params(user_name, repo_name)
79
- _validate_user_repo_params(user, repo) unless user? && repo?
79
+ assert_presence_of user, repo
80
80
  normalize! params
81
81
 
82
82
  response = get_request("/networks/#{user}/#{repo}/events", params)
@@ -96,7 +96,7 @@ module Github
96
96
  # github.events.org 'org-name' { |event| ... }
97
97
  #
98
98
  def org(org_name, params={})
99
- _validate_presence_of org_name
99
+ assert_presence_of org_name
100
100
  normalize! params
101
101
 
102
102
  response = get_request("/orgs/#{org_name}/events", params)
@@ -127,7 +127,7 @@ module Github
127
127
  # github.events.received 'user-name', :public => true { |event| ... }
128
128
  #
129
129
  def received(user_name, params={})
130
- _validate_presence_of user_name
130
+ assert_presence_of user_name
131
131
  normalize! params
132
132
 
133
133
  public_events = if params['public']
@@ -160,7 +160,7 @@ module Github
160
160
  # github.events.performed 'user-name', :public => true { |event| ... }
161
161
  #
162
162
  def performed(user_name, params={})
163
- _validate_presence_of user_name
163
+ assert_presence_of user_name
164
164
  normalize! params
165
165
 
166
166
  public_events = if params['public']
@@ -186,7 +186,7 @@ module Github
186
186
  # github.events.user_org 'user-name', 'org-name' { |event| ... }
187
187
  #
188
188
  def user_org(user_name, org_name, params={})
189
- _validate_presence_of user_name, org_name
189
+ assert_presence_of user_name, org_name
190
190
  normalize! params
191
191
 
192
192
  response = get_request("/users/#{user_name}/events/orgs/#{org_name}", params)
@@ -76,7 +76,7 @@ module Github
76
76
  #
77
77
  def get(gist_id, params={})
78
78
  normalize! params
79
- _validate_presence_of(gist_id)
79
+ assert_presence_of gist_id
80
80
 
81
81
  get_request("/gists/#{gist_id}", params)
82
82
  end
@@ -139,7 +139,7 @@ module Github
139
139
  # }
140
140
  #
141
141
  def edit(gist_id, params={})
142
- _validate_presence_of(gist_id)
142
+ assert_presence_of gist_id
143
143
  normalize! params
144
144
 
145
145
  patch_request("/gists/#{gist_id}", params)
@@ -152,7 +152,7 @@ module Github
152
152
  # github.gists.star 'gist-id'
153
153
  #
154
154
  def star(gist_id, params={})
155
- _validate_presence_of(gist_id)
155
+ assert_presence_of gist_id
156
156
  normalize! params
157
157
 
158
158
  put_request("/gists/#{gist_id}/star", params)
@@ -165,7 +165,7 @@ module Github
165
165
  # github.gists.unstar 'gist-id'
166
166
  #
167
167
  def unstar(gist_id, params={})
168
- _validate_presence_of(gist_id)
168
+ assert_presence_of gist_id
169
169
  normalize! params
170
170
 
171
171
  delete_request("/gists/#{gist_id}/star", params)
@@ -178,7 +178,7 @@ module Github
178
178
  # github.gists.starred? 'gist-id'
179
179
  #
180
180
  def starred?(gist_id, params={})
181
- _validate_presence_of(gist_id)
181
+ assert_presence_of gist_id
182
182
  normalize! params
183
183
 
184
184
  get_request("/gists/#{gist_id}/star", params)
@@ -194,7 +194,7 @@ module Github
194
194
  # github.gists.fork 'gist-id'
195
195
  #
196
196
  def fork(gist_id, params={})
197
- _validate_presence_of(gist_id)
197
+ assert_presence_of gist_id
198
198
  normalize! params
199
199
 
200
200
  post_request("/gists/#{gist_id}/fork", params)
@@ -207,7 +207,7 @@ module Github
207
207
  # github.gists.delete 'gist-id'
208
208
  #
209
209
  def delete(gist_id, params={})
210
- _validate_presence_of(gist_id)
210
+ assert_presence_of gist_id
211
211
  normalize! params
212
212
 
213
213
  delete_request("/gists/#{gist_id}", params)
@@ -21,7 +21,7 @@ module Github
21
21
  #
22
22
  def list(gist_id, params={})
23
23
  normalize! params
24
- _validate_presence_of(gist_id)
24
+ assert_presence_of gist_id
25
25
  # _merge_mime_type(:gist_comment, params)
26
26
 
27
27
  response = get_request("/gists/#{gist_id}/comments", params)
@@ -38,7 +38,7 @@ module Github
38
38
  #
39
39
  def get(comment_id, params={})
40
40
  normalize! params
41
- _validate_presence_of(comment_id)
41
+ assert_presence_of comment_id
42
42
  # _merge_mime_type(:gist_comment, params)
43
43
 
44
44
  get_request("/gists/comments/#{comment_id}", params)
@@ -68,7 +68,7 @@ module Github
68
68
  #
69
69
  def edit(comment_id, params={})
70
70
  normalize! params
71
- _validate_presence_of(comment_id)
71
+ assert_presence_of comment_id
72
72
  # _merge_mime_type(:gist_comment, params)
73
73
  filter! ALLOWED_GIST_COMMENT_INPUTS, params
74
74
  assert_required_keys(REQUIRED_GIST_COMMENT_INPUTS, params)
@@ -84,7 +84,7 @@ module Github
84
84
  #
85
85
  def delete(comment_id, params={})
86
86
  normalize! params
87
- _validate_presence_of(comment_id)
87
+ assert_presence_of comment_id
88
88
  # _merge_mime_type(:gist_comment, params)
89
89
 
90
90
  delete_request("/gists/comments/#{comment_id}", params)
@@ -21,8 +21,7 @@ module Github
21
21
  #
22
22
  def get(user_name, repo_name, sha, params={})
23
23
  _update_user_repo_params(user_name, repo_name)
24
- _validate_user_repo_params(user, repo) unless user? && repo?
25
- _validate_presence_of sha
24
+ assert_presence_of user, repo, sha
26
25
  normalize! params
27
26
 
28
27
  get_request("/repos/#{user}/#{repo}/git/blobs/#{sha}", params)
@@ -42,7 +41,7 @@ module Github
42
41
  #
43
42
  def create(user_name, repo_name, params={})
44
43
  _update_user_repo_params(user_name, repo_name)
45
- _validate_user_repo_params(user, repo) unless user? && repo?
44
+ assert_presence_of user, repo
46
45
 
47
46
  normalize! params
48
47
  filter! VALID_BLOB_PARAM_NAMES, params
@@ -33,8 +33,7 @@ module Github
33
33
  #
34
34
  def get(user_name, repo_name, sha, params={})
35
35
  _update_user_repo_params(user_name, repo_name)
36
- _validate_user_repo_params(user, repo) unless user? && repo?
37
- _validate_presence_of sha
36
+ assert_presence_of user, repo, sha
38
37
  normalize! params
39
38
 
40
39
  get_request("/repos/#{user}/#{repo}/git/commits/#{sha}", params)
@@ -75,7 +74,7 @@ module Github
75
74
  #
76
75
  def create(user_name, repo_name, params={})
77
76
  _update_user_repo_params(user_name, repo_name)
78
- _validate_user_repo_params(user, repo) unless user? && repo?
77
+ assert_presence_of user, repo
79
78
  normalize! params
80
79
  filter! VALID_COMMIT_PARAM_NAMES, params
81
80
  assert_required_keys(REQUIRED_COMMIT_PARAMS, params)
@@ -29,12 +29,12 @@ module Github
29
29
  #
30
30
  def list(user_name, repo_name, params={})
31
31
  _update_user_repo_params(user_name, repo_name)
32
- _validate_user_repo_params(user, repo) unless user? && repo?
32
+ assert_presence_of user, repo
33
33
  normalize! params
34
34
 
35
35
  response = if params['ref']
36
36
  ref = params.delete('ref')
37
- _validate_reference ref
37
+ validate_reference ref
38
38
  get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
39
39
  else
40
40
  get_request("/repos/#{user}/#{repo}/git/refs", params)
@@ -57,10 +57,8 @@ module Github
57
57
  #
58
58
  def get(user_name, repo_name, ref, params={})
59
59
  _update_user_repo_params(user_name, repo_name)
60
- _validate_user_repo_params(user, repo) unless user? && repo?
61
-
62
- _validate_presence_of ref
63
- _validate_reference ref
60
+ assert_presence_of user, repo, ref
61
+ validate_reference ref
64
62
  normalize! params
65
63
 
66
64
  get_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
@@ -82,12 +80,10 @@ module Github
82
80
  #
83
81
  def create(user_name, repo_name, params={})
84
82
  _update_user_repo_params(user_name, repo_name)
85
- _validate_user_repo_params(user, repo) unless user? && repo?
86
-
87
83
  normalize! params
88
84
  filter! VALID_REF_PARAM_NAMES, params
89
- _validate_presence_of params['ref']
90
- _validate_reference params['ref']
85
+ assert_presence_of user, repo, params['ref']
86
+ validate_reference params['ref']
91
87
  assert_required_keys(%w[ ref sha ], params)
92
88
 
93
89
  post_request("/repos/#{user}/#{repo}/git/refs", params)
@@ -107,10 +103,8 @@ module Github
107
103
  #
108
104
  def update(user_name, repo_name, ref, params={})
109
105
  _update_user_repo_params(user_name, repo_name)
110
- _validate_user_repo_params(user, repo) unless user? && repo?
111
-
112
- _validate_presence_of ref
113
- _validate_reference ref
106
+ assert_presence_of user, repo, ref
107
+ validate_reference ref
114
108
  normalize! params
115
109
  filter! VALID_REF_PARAM_NAMES, params
116
110
  assert_required_keys(%w[ sha ], params)
@@ -127,9 +121,8 @@ module Github
127
121
  #
128
122
  def delete(user_name, repo_name, ref, params={})
129
123
  _update_user_repo_params(user_name, repo_name)
130
- _validate_user_repo_params(user, repo) unless user? && repo?
124
+ assert_presence_of user, repo, ref
131
125
  normalize! params
132
- _validate_presence_of ref
133
126
 
134
127
  delete_request("/repos/#{user}/#{repo}/git/refs/#{ref}", params)
135
128
  end
@@ -137,7 +130,7 @@ module Github
137
130
 
138
131
  private
139
132
 
140
- def _validate_reference ref
133
+ def validate_reference ref
141
134
  refs = ref.index('ref') ? ref : "refs/#{ref}"
142
135
  unless VALID_REF_PARAM_VALUES['ref'] =~ refs
143
136
  raise ArgumentError, "Provided 'reference' is invalid"
@@ -35,8 +35,7 @@ module Github
35
35
  #
36
36
  def get(user_name, repo_name, sha, params={})
37
37
  _update_user_repo_params(user_name, repo_name)
38
- _validate_user_repo_params(user, repo) unless user? && repo?
39
- _validate_presence_of sha
38
+ assert_presence_of user, repo, sha
40
39
  normalize! params
41
40
 
42
41
  get_request("/repos/#{user}/#{repo}/git/tags/#{sha}", params)
@@ -73,7 +72,7 @@ module Github
73
72
  #
74
73
  def create(user_name, repo_name, params={})
75
74
  _update_user_repo_params(user_name, repo_name)
76
- _validate_user_repo_params(user, repo) unless user? && repo?
75
+ assert_presence_of user, repo
77
76
  normalize! params
78
77
 
79
78
  filter! VALID_TAG_PARAM_NAMES, params
@@ -41,8 +41,7 @@ module Github
41
41
  #
42
42
  def get(user_name, repo_name, sha, params={})
43
43
  _update_user_repo_params(user_name, repo_name)
44
- _validate_user_repo_params(user, repo) unless user? && repo?
45
- _validate_presence_of sha
44
+ assert_presence_of user, repo, sha
46
45
  normalize! params
47
46
 
48
47
  response = if params['recursive']
@@ -87,7 +86,7 @@ module Github
87
86
  #
88
87
  def create(user_name, repo_name, params={})
89
88
  _update_user_repo_params(user_name, repo_name)
90
- _validate_user_repo_params(user, repo) unless user? && repo?
89
+ assert_presence_of user, repo
91
90
  normalize! params
92
91
  assert_required_keys(%w[ tree ], params)
93
92
 
@@ -133,7 +133,7 @@ module Github
133
133
  #
134
134
  def list_repo(user_name, repo_name, params={})
135
135
  _update_user_repo_params(user_name, repo_name)
136
- _validate_user_repo_params(user, repo) unless user? && repo?
136
+ assert_presence_of user, repo
137
137
 
138
138
  normalize! params
139
139
  filter! VALID_ISSUE_PARAM_NAMES, params
@@ -154,8 +154,7 @@ module Github
154
154
  #
155
155
  def get(user_name, repo_name, issue_id, params={})
156
156
  _update_user_repo_params(user_name, repo_name)
157
- _validate_user_repo_params(user, repo) unless user? && repo?
158
- _validate_presence_of issue_id
157
+ assert_presence_of user, repo, issue_id
159
158
 
160
159
  normalize! params
161
160
  # _merge_mime_type(:issue, params)
@@ -186,7 +185,7 @@ module Github
186
185
  #
187
186
  def create(user_name, repo_name, params={})
188
187
  _update_user_repo_params(user_name, repo_name)
189
- _validate_user_repo_params(user, repo) unless user? && repo?
188
+ assert_presence_of user, repo
190
189
 
191
190
  normalize! params
192
191
  # _merge_mime_type(:issue, params)
@@ -220,8 +219,7 @@ module Github
220
219
  #
221
220
  def edit(user_name, repo_name, issue_id, params={})
222
221
  _update_user_repo_params(user_name, repo_name)
223
- _validate_user_repo_params(user, repo) unless user? && repo?
224
- _validate_presence_of issue_id
222
+ assert_presence_of user, repo, issue_id
225
223
 
226
224
  normalize! params
227
225
  # _merge_mime_type(:issue, params)