github_api 0.6.5 → 0.7.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (44) hide show
  1. data/features/cassettes/{repos → issues}/assignees/ckeck.yml +0 -0
  2. data/features/cassettes/{repos → issues}/assignees/ckeck_not.yml +0 -0
  3. data/features/cassettes/{repos → issues}/assignees/list.yml +0 -0
  4. data/features/cassettes/repos/starring/list.yml +98 -0
  5. data/features/cassettes/repos/starring/star.yml +48 -0
  6. data/features/cassettes/repos/starring/starred.yml +195 -0
  7. data/features/cassettes/repos/starring/starring.yml +56 -0
  8. data/features/cassettes/repos/starring/unstar.yml +46 -0
  9. data/features/cassettes/repos/statuses/create.yml +52 -0
  10. data/features/cassettes/repos/statuses/list.yml +64 -0
  11. data/features/cassettes/repos/watching/list.yml +76 -0
  12. data/features/cassettes/repos/watching/unwatch.yml +46 -0
  13. data/features/cassettes/repos/watching/watch.yml +48 -0
  14. data/features/cassettes/repos/watching/watched.yml +166 -0
  15. data/features/cassettes/repos/watching/watching.yml +56 -0
  16. data/features/{repos → issues}/assignees.feature +5 -5
  17. data/features/repos/starring.feature +50 -0
  18. data/features/repos/statuses.feature +27 -0
  19. data/features/repos/watching.feature +50 -0
  20. data/lib/github_api/error/service_error.rb +5 -2
  21. data/lib/github_api/issues.rb +6 -0
  22. data/lib/github_api/{repos → issues}/assignees.rb +2 -2
  23. data/lib/github_api/jsonable.rb +17 -0
  24. data/lib/github_api/orgs/teams.rb +45 -45
  25. data/lib/github_api/repos.rb +23 -11
  26. data/lib/github_api/repos/commits.rb +4 -3
  27. data/lib/github_api/repos/merging.rb +40 -0
  28. data/lib/github_api/repos/starring.rb +97 -0
  29. data/lib/github_api/repos/statuses.rb +64 -0
  30. data/lib/github_api/repos/watching.rb +16 -13
  31. data/lib/github_api/response.rb +1 -0
  32. data/lib/github_api/response/jsonize.rb +4 -5
  33. data/lib/github_api/version.rb +2 -2
  34. data/spec/fixtures/repos/merge.json +48 -0
  35. data/spec/fixtures/repos/stargazers.json +9 -0
  36. data/spec/fixtures/repos/starred.json +34 -0
  37. data/spec/fixtures/repos/status.json +16 -0
  38. data/spec/fixtures/repos/statuses.json +18 -0
  39. data/spec/github/{repos → issues}/assignees_spec.rb +2 -2
  40. data/spec/github/repos/merging_spec.rb +71 -0
  41. data/spec/github/repos/starring_spec.rb +203 -0
  42. data/spec/github/repos/statuses_spec.rb +124 -0
  43. data/spec/github/repos/watching_spec.rb +37 -35
  44. metadata +66 -39
@@ -0,0 +1,56 @@
1
+ ---
2
+ http_interactions:
3
+ - request:
4
+ method: get
5
+ uri: https://<BASIC_AUTH>@api.github.com/user/subscriptions/peter-murach/github?access_token=<TOKEN>
6
+ body:
7
+ encoding: US-ASCII
8
+ string: ""
9
+ headers:
10
+ Accept:
11
+ - application/jsonapplication/vnd.github+json;q=0.7application/vnd.github.v3.raw+json;q=0.5application/vnd.github.beta.raw+json;q=0.1
12
+ Accept-Charset:
13
+ - utf-8
14
+ User-Agent:
15
+ - Github Ruby Gem 0.6.5
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: 404
23
+ message: Not Found
24
+ headers:
25
+ Server:
26
+ - nginx
27
+ Date:
28
+ - Sun, 09 Sep 2012 16:42:42 GMT
29
+ Content-Type:
30
+ - application/json; charset=utf-8
31
+ Transfer-Encoding:
32
+ - chunked
33
+ Connection:
34
+ - keep-alive
35
+ Status:
36
+ - 404 Not Found
37
+ X-Github-Media-Type:
38
+ - github.beta
39
+ X-Content-Type-Options:
40
+ - nosniff
41
+ X-Ratelimit-Limit:
42
+ - "5000"
43
+ X-Ratelimit-Remaining:
44
+ - "4997"
45
+ Cache-Control:
46
+ - ""
47
+ Content-Encoding:
48
+ - gzip
49
+ body:
50
+ encoding: ASCII-8BIT
51
+ string: !binary |
52
+ H4sIAAAAAAAAA6tWyk0tLk5MT1WyUvLLL1Fwyy/NS1GqBQB8+Ys1FwAAAA==
53
+
54
+ http_version:
55
+ recorded_at: Sun, 09 Sep 2012 16:42:42 GMT
56
+ recorded_with: VCR 2.2.0
@@ -1,14 +1,14 @@
1
- Feature: Contents API
1
+ Feature: Assignees API
2
2
 
3
3
  Background:
4
- Given I have "Github::Repos::Assignees" instance
4
+ Given I have "Github::Issues::Assignees" instance
5
5
 
6
6
  Scenario: List
7
7
 
8
8
  Given I want to list resources with the following params:
9
9
  | user | repo |
10
10
  | peter-murach | github |
11
- When I make request within a cassette named "repos/assignees/list"
11
+ When I make request within a cassette named "issues/assignees/list"
12
12
  Then the response status should be 200
13
13
  And the response type should be JSON
14
14
  And the response should not be empty
@@ -18,7 +18,7 @@ Feature: Contents API
18
18
  Given I want to check resource with the following params:
19
19
  | user | repo | assignee |
20
20
  | peter-murach | github | wycats |
21
- When I make request within a cassette named "repos/assignees/ckeck_not"
21
+ When I make request within a cassette named "issues/assignees/ckeck_not"
22
22
  Then the response should be false
23
23
 
24
24
  Scenario: Check assignee belongs to repository
@@ -26,5 +26,5 @@ Feature: Contents API
26
26
  Given I want to check resource with the following params:
27
27
  | user | repo | assignee |
28
28
  | peter-murach | github | peter-murach |
29
- When I make request within a cassette named "repos/assignees/ckeck"
29
+ When I make request within a cassette named "issues/assignees/ckeck"
30
30
  Then the response should be true
@@ -0,0 +1,50 @@
1
+ Feature: Starring API
2
+
3
+ Background:
4
+ Given I have "Github::Repos::Starring" instance
5
+
6
+ Scenario: List
7
+
8
+ Given I want to list resources with the following params:
9
+ | user | repo |
10
+ | peter-murach | github |
11
+ When I make request within a cassette named "repos/starring/list"
12
+ Then the response status should be 200
13
+ And the response type should be JSON
14
+ And the response should not be empty
15
+
16
+ Scenario: Starred
17
+
18
+ Given I want to starred resources
19
+ And I pass the following request options:
20
+ | user |
21
+ | wycats |
22
+ When I make request within a cassette named "repos/starring/starred"
23
+ Then the response status should be 200
24
+ And the response type should be JSON
25
+ And the response should not be empty
26
+
27
+ Scenario: Starring
28
+
29
+ Given I want to starring? resource with the following params:
30
+ | user | repo |
31
+ | peter-murach | github |
32
+ When I make request within a cassette named "repos/starring/starring"
33
+ Then the response should be false
34
+
35
+ Scenario: Star
36
+
37
+ Given I want to star resource with the following params:
38
+ | user | repo |
39
+ | peter-murach | github |
40
+ When I make request within a cassette named "repos/starring/star"
41
+ Then the response status should be 204
42
+
43
+ Scenario: Unstar
44
+
45
+ Given I want to unstar resource with the following params:
46
+ | user | repo |
47
+ | peter-murach | github |
48
+ When I make request within a cassette named "repos/starring/unstar"
49
+ Then the response status should be 204
50
+
@@ -0,0 +1,27 @@
1
+ Feature: Statuses API
2
+
3
+ Background:
4
+ Given I have "Github::Repos::Statuses" instance
5
+
6
+ Scenario: List
7
+
8
+ Given I want to list resources with the following params:
9
+ | user | repo | sha |
10
+ | peter-murach | github | cbdc6a5b133bf460d9c18292dda8fc54adf7e1b1 |
11
+ When I make request within a cassette named "repos/statuses/list"
12
+ Then the response status should be 200
13
+ And the response type should be JSON
14
+ And the response should not be empty
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
@@ -0,0 +1,50 @@
1
+ Feature: Watching API
2
+
3
+ Background:
4
+ Given I have "Github::Repos::Watching" instance
5
+
6
+ Scenario: List
7
+
8
+ Given I want to list resources with the following params:
9
+ | user | repo |
10
+ | peter-murach | github |
11
+ When I make request within a cassette named "repos/watching/list"
12
+ Then the response status should be 200
13
+ And the response type should be JSON
14
+ And the response should not be empty
15
+
16
+ Scenario: Watched
17
+
18
+ Given I want to watched resources
19
+ And I pass the following request options:
20
+ | user |
21
+ | wycats |
22
+ When I make request within a cassette named "repos/watching/watched"
23
+ Then the response status should be 200
24
+ And the response type should be JSON
25
+ And the response should not be empty
26
+
27
+ Scenario: Watching
28
+
29
+ Given I want to watching? resource with the following params:
30
+ | user | repo |
31
+ | peter-murach | github |
32
+ When I make request within a cassette named "repos/watching/watching"
33
+ Then the response should be false
34
+
35
+ Scenario: Watch
36
+
37
+ Given I want to watch resource with the following params:
38
+ | user | repo |
39
+ | peter-murach | github |
40
+ When I make request within a cassette named "repos/watching/watch"
41
+ Then the response status should be 204
42
+
43
+ Scenario: Unwatch
44
+
45
+ Given I want to unwatch resource with the following params:
46
+ | user | repo |
47
+ | peter-murach | github |
48
+ When I make request within a cassette named "repos/watching/unwatch"
49
+ Then the response status should be 204
50
+
@@ -1,10 +1,13 @@
1
1
  # encoding: utf-8
2
- require 'multi_json'
2
+ # require 'multi_json'
3
+ require 'github_api/jsonable'
3
4
 
4
5
  module Github
5
6
  # Raised when GitHub returns any of the HTTP status codes
6
7
  module Error
7
8
  class ServiceError < GithubError
9
+ include ::Github::Jsonable
10
+
8
11
  attr_reader :http_headers
9
12
 
10
13
  def initialize(response)
@@ -20,7 +23,7 @@ module Github
20
23
 
21
24
  def decode_body(body)
22
25
  if body.respond_to?(:to_str) && body.length >= 2
23
- MultiJson.load(body, :symbolize_keys => true)
26
+ decode body, :symbolize_keys => true
24
27
  else
25
28
  body
26
29
  end
@@ -5,6 +5,7 @@ module Github
5
5
  extend AutoloadHelper
6
6
 
7
7
  autoload_all 'github_api/issues',
8
+ :Assignees => 'assignees',
8
9
  :Comments => 'comments',
9
10
  :Events => 'events',
10
11
  :Labels => 'labels',
@@ -39,6 +40,11 @@ module Github
39
40
  super(options)
40
41
  end
41
42
 
43
+ # Access to Issues::Assignees API
44
+ def assignees
45
+ @assignees ||= ApiFactory.new 'Issues::Assignees'
46
+ end
47
+
42
48
  # Access to Issues::Comments API
43
49
  def comments
44
50
  @comments ||= ApiFactory.new 'Issues::Comments'
@@ -1,7 +1,7 @@
1
1
  # encoding: utf-8
2
2
 
3
3
  module Github
4
- class Repos::Assignees < API
4
+ class Issues::Assignees < API
5
5
 
6
6
  # lists all the available assignees (owner + collaborators)
7
7
  # to which issues may be assigned.
@@ -35,5 +35,5 @@ module Github
35
35
  false
36
36
  end
37
37
 
38
- end # Repos::Assignees
38
+ end # Issues::Assignees
39
39
  end # Github
@@ -0,0 +1,17 @@
1
+ # encoding: utf-8
2
+
3
+ require 'multi_json'
4
+
5
+ module Github
6
+ module Jsonable
7
+ extend self
8
+
9
+ def decode(*args)
10
+ if MultiJson.respond_to?(:load)
11
+ MultiJson.load *args
12
+ else
13
+ MultiJson.decode *args
14
+ end
15
+ end
16
+ end
17
+ end
@@ -31,13 +31,13 @@ module Github
31
31
  #
32
32
  # = Examples
33
33
  # github = Github.new :oauth_token => '...'
34
- # github.orgs.teams.get 'team-name'
34
+ # github.orgs.teams.get 'team-id'
35
35
  #
36
- def get(team_name, params={})
37
- _validate_presence_of team_name
36
+ def get(team_id, params={})
37
+ _validate_presence_of team_id
38
38
  normalize! params
39
39
 
40
- get_request("/teams/#{team_name}", params)
40
+ get_request("/teams/#{team_id}", params)
41
41
  end
42
42
  alias :find :get
43
43
 
@@ -83,18 +83,18 @@ module Github
83
83
  #
84
84
  # = Examples
85
85
  # github = Github.new :oauth_token => '...'
86
- # github.orgs.teams.edit 'team-name',
86
+ # github.orgs.teams.edit 'team-id',
87
87
  # "name" => "new team name",
88
88
  # "permission" => "push"
89
89
  #
90
- def edit(team_name, params={})
91
- _validate_presence_of team_name
90
+ def edit(team_id, params={})
91
+ _validate_presence_of team_id
92
92
  normalize! params
93
93
  filter! VALID_TEAM_PARAM_NAMES, params
94
94
  assert_valid_values(VALID_TEAM_PARAM_VALUES, params)
95
95
  assert_required_keys(%w[ name ], params)
96
96
 
97
- patch_request("/teams/#{team_name}", params)
97
+ patch_request("/teams/#{team_id}", params)
98
98
  end
99
99
 
100
100
  # Delete a team
@@ -102,12 +102,12 @@ module Github
102
102
  #
103
103
  # = Examples
104
104
  # github = Github.new :oauth_token => '...'
105
- # github.orgs.teams.delete 'team-name'
105
+ # github.orgs.teams.delete 'team-id'
106
106
  #
107
- def delete(team_name, params={})
108
- _validate_presence_of team_name
107
+ def delete(team_id, params={})
108
+ _validate_presence_of team_id
109
109
  normalize! params
110
- delete_request("/teams/#{team_name}", params)
110
+ delete_request("/teams/#{team_id}", params)
111
111
  end
112
112
  alias :remove :delete
113
113
 
@@ -116,14 +116,14 @@ module Github
116
116
  #
117
117
  # = Examples
118
118
  # github = Github.new :oauth_token => '...'
119
- # github.orgs.teams.list_members 'team-name'
120
- # github.orgs.teams.list_members 'team-name' { |member| ... }
119
+ # github.orgs.teams.list_members 'team-id'
120
+ # github.orgs.teams.list_members 'team-id' { |member| ... }
121
121
  #
122
- def list_members(team_name, params={})
123
- _validate_presence_of team_name
122
+ def list_members(team_id, params={})
123
+ _validate_presence_of team_id
124
124
  normalize! params
125
125
 
126
- response = get_request("/teams/#{team_name}/members", params)
126
+ response = get_request("/teams/#{team_id}/members", params)
127
127
  return response unless block_given?
128
128
  response.each { |el| yield el }
129
129
  end
@@ -133,12 +133,12 @@ module Github
133
133
  #
134
134
  # = Examples
135
135
  # github = Github.new :oauth_token => '...'
136
- # github.orgs.teams.team_member? 'team-name', 'user-name'
136
+ # github.orgs.teams.team_member? 'team-id', 'user-name'
137
137
  #
138
- def team_member?(team_name, member_name, params={})
139
- _validate_presence_of team_name, member_name
138
+ def team_member?(team_id, member_name, params={})
139
+ _validate_presence_of team_id, member_name
140
140
  normalize! params
141
- get_request("/teams/#{team_name}/members/#{member_name}", params)
141
+ get_request("/teams/#{team_id}/members/#{member_name}", params)
142
142
  true
143
143
  rescue Github::Error::NotFound
144
144
  false
@@ -149,12 +149,12 @@ module Github
149
149
  #
150
150
  # = Examples
151
151
  # github = Github.new :oauth_token => '...'
152
- # github.orgs.teams.add_member 'team-name', 'user-name'
152
+ # github.orgs.teams.add_member 'team-id', 'user-name'
153
153
  #
154
- def add_member(team_name, member_name, params={})
155
- _validate_presence_of team_name, member_name
154
+ def add_member(team_id, member_name, params={})
155
+ _validate_presence_of team_id, member_name
156
156
  normalize! params
157
- put_request("/teams/#{team_name}/members/#{member_name}", params)
157
+ put_request("/teams/#{team_id}/members/#{member_name}", params)
158
158
  end
159
159
  alias :add_team_member :add_member
160
160
 
@@ -166,12 +166,12 @@ module Github
166
166
  #
167
167
  # = Examples
168
168
  # github = Github.new :oauth_token => '...'
169
- # github.orgs.teams.remove_member 'team-name', 'member-name'
169
+ # github.orgs.teams.remove_member 'team-id', 'member-name'
170
170
  #
171
- def remove_member(team_name, member_name, params={})
172
- _validate_presence_of team_name, member_name
171
+ def remove_member(team_id, member_name, params={})
172
+ _validate_presence_of team_id, member_name
173
173
  normalize! params
174
- delete_request("/teams/#{team_name}/members/#{member_name}", params)
174
+ delete_request("/teams/#{team_id}/members/#{member_name}", params)
175
175
  end
176
176
  alias :remove_team_member :remove_member
177
177
 
@@ -179,13 +179,13 @@ module Github
179
179
  #
180
180
  # = Examples
181
181
  # github = Github.new :oauth_token => '...'
182
- # github.orgs.teams.list_repos 'team-name'
182
+ # github.orgs.teams.list_repos 'team-id'
183
183
  #
184
- def list_repos(team_name, params={})
185
- _validate_presence_of team_name
184
+ def list_repos(team_id, params={})
185
+ _validate_presence_of team_id
186
186
  normalize! params
187
187
 
188
- response = get_request("/teams/#{team_name}/repos", params)
188
+ response = get_request("/teams/#{team_id}/repos", params)
189
189
  return response unless block_given?
190
190
  response.each { |el| yield el }
191
191
  end
@@ -195,12 +195,12 @@ module Github
195
195
  #
196
196
  # = Examples
197
197
  # github = Github.new :oauth_token => '...'
198
- # github.orgs.teams.team_repo? 'team-name', 'user-name', 'repo-name'
198
+ # github.orgs.teams.team_repo? 'team-id', 'user-name', 'repo-name'
199
199
  #
200
- def team_repo?(team_name, user_name, repo_name, params={})
201
- _validate_presence_of team_name, user_name, repo_name
200
+ def team_repo?(team_id, user_name, repo_name, params={})
201
+ _validate_presence_of team_id, user_name, repo_name
202
202
  normalize! params
203
- get_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
203
+ get_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params)
204
204
  true
205
205
  rescue Github::Error::NotFound
206
206
  false
@@ -216,12 +216,12 @@ module Github
216
216
  #
217
217
  # = Examples
218
218
  # github = Github.new :oauth_token => '...'
219
- # github.orgs.teams.add_repo 'team-name', 'user-name', 'repo-name'
219
+ # github.orgs.teams.add_repo 'team-id', 'user-name', 'repo-name'
220
220
  #
221
- def add_repo(team_name, user_name, repo_name, params={})
222
- _validate_presence_of team_name, user_name, repo_name
221
+ def add_repo(team_id, user_name, repo_name, params={})
222
+ _validate_presence_of team_id, user_name, repo_name
223
223
  normalize! params
224
- put_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
224
+ put_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params)
225
225
  end
226
226
  alias :add_repository :add_repo
227
227
 
@@ -233,12 +233,12 @@ module Github
233
233
  #
234
234
  # = Examples
235
235
  # github = Github.new :oauth_token => '...'
236
- # github.orgs.teams.remove_repo 'team-name', 'user-name', 'repo-name'
236
+ # github.orgs.teams.remove_repo 'team-id', 'user-name', 'repo-name'
237
237
  #
238
- def remove_repo(team_name, user_name, repo_name, params={})
239
- _validate_presence_of team_name, user_name, repo_name
238
+ def remove_repo(team_id, user_name, repo_name, params={})
239
+ _validate_presence_of team_id, user_name, repo_name
240
240
  normalize! params
241
- delete_request("/teams/#{team_name}/repos/#{user_name}/#{repo_name}", params)
241
+ delete_request("/teams/#{team_id}/repos/#{user_name}/#{repo_name}", params)
242
242
  end
243
243
  alias :remove_repository :remove_repo
244
244