github_api 0.2.0 → 0.2.1

Sign up to get free protection for your applications and to get access to all the features.
Files changed (40) hide show
  1. data/README.rdoc +51 -20
  2. data/lib/github_api.rb +3 -1
  3. data/lib/github_api/api.rb +8 -2
  4. data/lib/github_api/authorization.rb +52 -0
  5. data/lib/github_api/cache_control.rb +19 -0
  6. data/lib/github_api/configuration.rb +8 -11
  7. data/lib/github_api/connection.rb +18 -36
  8. data/lib/github_api/gists/comments.rb +17 -5
  9. data/lib/github_api/issues.rb +9 -1
  10. data/lib/github_api/issues/comments.rb +15 -4
  11. data/lib/github_api/mime_type.rb +55 -0
  12. data/lib/github_api/pull_requests.rb +14 -0
  13. data/lib/github_api/pull_requests/comments.rb +10 -0
  14. data/lib/github_api/repos/collaborators.rb +41 -19
  15. data/lib/github_api/repos/commits.rb +108 -43
  16. data/lib/github_api/repos/forks.rb +32 -13
  17. data/lib/github_api/request.rb +12 -3
  18. data/lib/github_api/request/caching.rb +33 -0
  19. data/lib/github_api/version.rb +1 -1
  20. data/spec/fixtures/repos/collaborators.json +8 -0
  21. data/spec/fixtures/repos/commit.json +53 -0
  22. data/spec/fixtures/repos/commit_comment.json +16 -0
  23. data/spec/fixtures/repos/commit_comments.json +18 -0
  24. data/spec/fixtures/repos/commits.json +27 -0
  25. data/spec/fixtures/{repos_list.json → repos/fork.json} +0 -0
  26. data/spec/fixtures/repos/forks.json +29 -0
  27. data/spec/fixtures/repos/repo_comments.json +18 -0
  28. data/spec/github/authorization_spec.rb +71 -0
  29. data/spec/github/mime_type_spec.rb +70 -0
  30. data/spec/github/repos/collaborators_spec.rb +166 -3
  31. data/spec/github/repos/commits_spec.rb +421 -2
  32. data/spec/github/repos/forks_spec.rb +101 -3
  33. data/spec/github/repos/watching_spec.rb +6 -0
  34. data/spec/github_spec.rb +8 -4
  35. metadata +17 -9
  36. data/lib/github_api/api/extract_options.rb +0 -17
  37. data/lib/github_api/api/mime.rb +0 -5
  38. data/spec/fixtures/collaborators_list.json +0 -6
  39. data/spec/fixtures/commits_list.json +0 -25
  40. data/spec/fixtures/repos_branches_list.json +0 -7
@@ -1,5 +1,103 @@
1
1
  require 'spec_helper'
2
2
 
3
- describe Github::Repos::Forks do
4
- pending
5
- end
3
+ describe Github::Repos::Forks do
4
+
5
+ let(:github) { Github.new }
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ describe "forks" do
10
+ context "resource found" do
11
+ before do
12
+ stub_get("/repos/#{user}/#{repo}/forks").
13
+ to_return(:body => fixture('repos/forks.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
14
+ end
15
+
16
+ it "should fail to get resource without username" do
17
+ github.user, github.repo = nil, nil
18
+ expect { github.repos.forks }.to raise_error(ArgumentError)
19
+ end
20
+
21
+ it "should get the resources" do
22
+ github.repos.forks user, repo
23
+ a_get("/repos/#{user}/#{repo}/forks").should have_been_made
24
+ end
25
+
26
+ it "should return array of resources" do
27
+ forks = github.repos.forks user, repo
28
+ forks.should be_an Array
29
+ forks.should have(1).items
30
+ end
31
+
32
+ it "should be a mash type" do
33
+ forks = github.repos.forks user, repo
34
+ forks.first.should be_a Hashie::Mash
35
+ end
36
+
37
+ it "should get fork information" do
38
+ forks = github.repos.forks user, repo
39
+ forks.first.name.should == 'Hello-World'
40
+ end
41
+
42
+ it "should yield to a block" do
43
+ github.repos.should_receive(:forks).with(user, repo).and_yield('web')
44
+ github.repos.forks(user, repo) { |param| 'web' }
45
+ end
46
+ end
47
+
48
+ context "resource not found" do
49
+ before do
50
+ stub_get("/repos/#{user}/#{repo}/forks").
51
+ to_return(:body => "", :status => [404, "Not Found"])
52
+ end
53
+
54
+ it "should return 404 with a message 'Not Found'" do
55
+ expect {
56
+ github.repos.forks user, repo
57
+ }.to raise_error(Github::ResourceNotFound)
58
+ end
59
+ end
60
+ end # forks
61
+
62
+ describe "create_hook" do
63
+ let(:inputs) { {:org => 'github'} }
64
+
65
+ context "resouce created" do
66
+ before do
67
+ stub_post("/repos/#{user}/#{repo}/forks").with(inputs).
68
+ to_return(:body => fixture('repos/fork.json'), :status => 201, :headers => {:content_type => "application/json; charset=utf-8"})
69
+
70
+ end
71
+
72
+ it "should create resource successfully" do
73
+ github.repos.create_fork(user, repo, inputs)
74
+ a_post("/repos/#{user}/#{repo}/forks").with(inputs).should have_been_made
75
+ end
76
+
77
+ it "should return the resource" do
78
+ fork = github.repos.create_fork user, repo, inputs
79
+ fork.should be_a Hashie::Mash
80
+ end
81
+
82
+ it "should get the fork information" do
83
+ fork = github.repos.create_fork(user, repo, inputs)
84
+ fork.name.should == 'Hello-World'
85
+ end
86
+ end
87
+
88
+ context "failed to create resource" do
89
+ before do
90
+ stub_post("/repos/#{user}/#{repo}/forks").with(inputs).
91
+ to_return(:body => fixture('repos/fork.json'), :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
92
+
93
+ end
94
+
95
+ it "should faile to retrieve resource" do
96
+ expect {
97
+ github.repos.create_fork user, repo, inputs
98
+ }.to raise_error(Github::ResourceNotFound)
99
+ end
100
+ end
101
+ end # create_fork
102
+
103
+ end # Github::Repos::Forks
@@ -10,6 +10,7 @@ describe Github::Repos::Watching do
10
10
 
11
11
  describe "watchers" do
12
12
  before do
13
+ github.oauth_token = nil
13
14
  stub_get("/repos/#{user}/#{repo}/watchers").
14
15
  to_return(:body => fixture("repos/watchers.json"), :status => 200, :headers => {})
15
16
  end
@@ -63,6 +64,7 @@ describe Github::Repos::Watching do
63
64
 
64
65
  context "if user unauthenticated" do
65
66
  before do
67
+ github.oauth_token = nil
66
68
  WebMock.reset!
67
69
  end
68
70
 
@@ -155,6 +157,10 @@ describe Github::Repos::Watching do
155
157
  to_return(:body => "", :status => 204, :headers => {})
156
158
  end
157
159
 
160
+ after do
161
+ github.oauth_token = nil # ensure authentication is reset
162
+ end
163
+
158
164
  it "should successfully watch a repo" do
159
165
  github.repos.start_watching(user, repo)
160
166
  a_put("/user/watched/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").should have_been_made
data/spec/github_spec.rb CHANGED
@@ -74,12 +74,12 @@ describe Github do
74
74
  Github.repo.should == 'github'
75
75
  end
76
76
 
77
- it "should have faraday options as hash" do
78
- Github.faraday_options.should be_a Hash
77
+ it "should have connection options as hash" do
78
+ Github.connection_options.should be_a Hash
79
79
  end
80
80
 
81
- it "should initialize faraday options to empty hash" do
82
- Github.faraday_options.should be_empty
81
+ it "should initialize connection options to empty hash" do
82
+ Github.connection_options.should be_empty
83
83
  end
84
84
 
85
85
  it "shoulve have not set user's login" do
@@ -89,6 +89,10 @@ describe Github do
89
89
  it "should have not set user's password" do
90
90
  Github.password.should be_nil
91
91
  end
92
+
93
+ it "should have set mime type to json" do
94
+ Github.mime_type.should == :json
95
+ end
92
96
  end
93
97
 
94
98
  describe ".configure" do
metadata CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
5
5
  segments:
6
6
  - 0
7
7
  - 2
8
- - 0
9
- version: 0.2.0
8
+ - 1
9
+ version: 0.2.1
10
10
  platform: ruby
11
11
  authors:
12
12
  - Piotr Murach
@@ -14,7 +14,7 @@ autorequire:
14
14
  bindir: bin
15
15
  cert_chain: []
16
16
 
17
- date: 2011-10-23 00:00:00 +01:00
17
+ date: 2011-10-29 00:00:00 +01:00
18
18
  default_executable:
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
@@ -193,10 +193,10 @@ files:
193
193
  - features/github.feature
194
194
  - features/step_definitions/github_steps.rb
195
195
  - features/support/env.rb
196
- - lib/github_api/api/extract_options.rb
197
- - lib/github_api/api/mime.rb
198
196
  - lib/github_api/api/utils.rb
199
197
  - lib/github_api/api.rb
198
+ - lib/github_api/authorization.rb
199
+ - lib/github_api/cache_control.rb
200
200
  - lib/github_api/client.rb
201
201
  - lib/github_api/configuration.rb
202
202
  - lib/github_api/connection.rb
@@ -216,6 +216,7 @@ files:
216
216
  - lib/github_api/issues/labels.rb
217
217
  - lib/github_api/issues/milestones.rb
218
218
  - lib/github_api/issues.rb
219
+ - lib/github_api/mime_type.rb
219
220
  - lib/github_api/orgs/members.rb
220
221
  - lib/github_api/orgs/teams.rb
221
222
  - lib/github_api/orgs.rb
@@ -231,6 +232,7 @@ files:
231
232
  - lib/github_api/repos/watching.rb
232
233
  - lib/github_api/repos.rb
233
234
  - lib/github_api/request/basic_auth.rb
235
+ - lib/github_api/request/caching.rb
234
236
  - lib/github_api/request/oauth2.rb
235
237
  - lib/github_api/request.rb
236
238
  - lib/github_api/response/jsonize.rb
@@ -243,24 +245,29 @@ files:
243
245
  - lib/github_api/users.rb
244
246
  - lib/github_api/version.rb
245
247
  - lib/github_api.rb
246
- - spec/fixtures/collaborators_list.json
247
- - spec/fixtures/commits_list.json
248
248
  - spec/fixtures/repos/branches.json
249
+ - spec/fixtures/repos/collaborators.json
250
+ - spec/fixtures/repos/commit.json
251
+ - spec/fixtures/repos/commit_comment.json
252
+ - spec/fixtures/repos/commit_comments.json
253
+ - spec/fixtures/repos/commits.json
249
254
  - spec/fixtures/repos/contributors.json
255
+ - spec/fixtures/repos/fork.json
256
+ - spec/fixtures/repos/forks.json
250
257
  - spec/fixtures/repos/hook.json
251
258
  - spec/fixtures/repos/hooks.json
252
259
  - spec/fixtures/repos/key.json
253
260
  - spec/fixtures/repos/keys.json
254
261
  - spec/fixtures/repos/languages.json
255
262
  - spec/fixtures/repos/repo.json
263
+ - spec/fixtures/repos/repo_comments.json
256
264
  - spec/fixtures/repos/repos.json
257
265
  - spec/fixtures/repos/tags.json
258
266
  - spec/fixtures/repos/teams.json
259
267
  - spec/fixtures/repos/watched.json
260
268
  - spec/fixtures/repos/watchers.json
261
- - spec/fixtures/repos_branches_list.json
262
- - spec/fixtures/repos_list.json
263
269
  - spec/github/api_spec.rb
270
+ - spec/github/authorization_spec.rb
264
271
  - spec/github/client_spec.rb
265
272
  - spec/github/core_ext/hash_spec.rb
266
273
  - spec/github/gists/comments_spec.rb
@@ -276,6 +283,7 @@ files:
276
283
  - spec/github/issues/labels_spec.rb
277
284
  - spec/github/issues/milestones_spec.rb
278
285
  - spec/github/issues_spec.rb
286
+ - spec/github/mime_type_spec.rb
279
287
  - spec/github/orgs/members_spec.rb
280
288
  - spec/github/orgs/teams_spec.rb
281
289
  - spec/github/orgs_spec.rb
@@ -1,17 +0,0 @@
1
- # encoding: utf-8
2
-
3
- class Hash
4
- def extractable_options?
5
- instance_of?(Hash)
6
- end
7
- end
8
-
9
- class Array
10
- def extract_options!
11
- if last.is_a?(Hash) && last.extractable_options?
12
- pop
13
- else
14
- {}
15
- end
16
- end
17
- end
@@ -1,5 +0,0 @@
1
- module Github
2
- class Mime < API
3
-
4
- end
5
- end
@@ -1,6 +0,0 @@
1
- {
2
- "login": "octocat",
3
- "id": 1,
4
- "avatar_url": "https://github.com/images/error/octocat_happy.gif",
5
- "url": "https://api.github.com/users/octocat"
6
- }
@@ -1,25 +0,0 @@
1
- {
2
- "sha": "7638417db6d59f3c431d3e1f261cc637155684cd",
3
- "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/7638417db6d59f3c431d3e1f261cc637155684cd",
4
- "author": {
5
- "date": "2010-04-10T14:10:01-07:00",
6
- "name": "Scott Chacon",
7
- "email": "schacon@gmail.com"
8
- },
9
- "committer": {
10
- "date": "2010-04-10T14:10:01-07:00",
11
- "name": "Scott Chacon",
12
- "email": "schacon@gmail.com"
13
- },
14
- "message": "added readme, because im a good github citizen\n",
15
- "tree": {
16
- "url": "https://api.github.com/repos/octocat/Hello-World/git/trees/691272480426f78a0138979dd3ce63b77f706feb",
17
- "sha": "691272480426f78a0138979dd3ce63b77f706feb"
18
- },
19
- "parents": [
20
- {
21
- "url": "https://api.github.com/repos/octocat/Hello-World/git/commits/1acc419d4d6a9ce985db7be48c6349a0475975b5",
22
- "sha": "1acc419d4d6a9ce985db7be48c6349a0475975b5"
23
- }
24
- ]
25
- }
@@ -1,7 +0,0 @@
1
- {
2
- "name": "master",
3
- "commit": {
4
- "sha": "6dcb09b5b57875f334f61aebed695e2e4193db5e",
5
- "url": "https://api.github.com/octocat/Hello-World/commits/c5b97d5ae6c19d5c5df71a34c7fbeeda2479ccbc"
6
- }
7
- }