github_api 0.8.1 → 0.8.2

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 (99) hide show
  1. data/README.md +2 -1
  2. data/features/README.rdoc +4 -4
  3. data/features/cassettes/gitignore/get.yml +60 -0
  4. data/features/cassettes/gitignore/get_raw.yml +224 -0
  5. data/features/cassettes/gitignore/list.yml +67 -0
  6. data/features/cassettes/issues/comments/get.yml +71 -0
  7. data/features/cassettes/issues/comments/list_issue.yml +82 -0
  8. data/features/cassettes/issues/comments/list_repo.yml +266 -0
  9. data/features/cassettes/pull_requests/comments/get.yml +159 -0
  10. data/features/cassettes/pull_requests/comments/list_pull.yml +54 -0
  11. data/features/cassettes/pull_requests/comments/list_repo.yml +54 -0
  12. data/features/cassettes/repos/list_repos.yml +129 -0
  13. data/features/cassettes/users/all.yml +256 -0
  14. data/features/gitignore.feature +37 -0
  15. data/features/issues/comments.feature +37 -0
  16. data/features/pull_requests/comments.feature +27 -0
  17. data/features/repos.feature +8 -0
  18. data/features/step_definitions/common_steps.rb +2 -0
  19. data/features/users.feature +8 -0
  20. data/lib/github_api.rb +1 -0
  21. data/lib/github_api/client.rb +5 -0
  22. data/lib/github_api/git_data/tags.rb +4 -4
  23. data/lib/github_api/gitignore.rb +56 -0
  24. data/lib/github_api/issues/comments.rb +23 -9
  25. data/lib/github_api/pull_requests/comments.rb +24 -6
  26. data/lib/github_api/repos.rb +14 -1
  27. data/lib/github_api/repos/keys.rb +4 -4
  28. data/lib/github_api/users.rb +21 -0
  29. data/lib/github_api/users/keys.rb +6 -6
  30. data/lib/github_api/version.rb +1 -1
  31. data/spec/fixtures/gitignore/template.json +4 -0
  32. data/spec/fixtures/gitignore/template_raw +1 -0
  33. data/spec/fixtures/gitignore/templates.json +9 -0
  34. data/spec/fixtures/users/users.json +9 -0
  35. data/spec/github/activity/notifications/mark_spec.rb +1 -1
  36. data/spec/github/activity/starring/starring_spec.rb +2 -2
  37. data/spec/github/activity/watching/watching_spec.rb +2 -2
  38. data/spec/github/git_data/commits/create_spec.rb +75 -0
  39. data/spec/github/git_data/commits/get_spec.rb +50 -0
  40. data/spec/github/git_data/commits_spec.rb +1 -126
  41. data/spec/github/git_data/references/create_spec.rb +67 -0
  42. data/spec/github/git_data/references/delete_spec.rb +38 -0
  43. data/spec/github/git_data/references/get_spec.rb +54 -0
  44. data/spec/github/git_data/references/list_spec.rb +77 -0
  45. data/spec/github/git_data/references/update_spec.rb +62 -0
  46. data/spec/github/git_data/references_spec.rb +1 -298
  47. data/spec/github/git_data/tags/create_spec.rb +61 -0
  48. data/spec/github/git_data/tags/get_spec.rb +48 -0
  49. data/spec/github/git_data/tags_spec.rb +0 -108
  50. data/spec/github/git_data/trees/create_spec.rb +62 -0
  51. data/spec/github/git_data/trees/get_spec.rb +69 -0
  52. data/spec/github/git_data/trees_spec.rb +0 -133
  53. data/spec/github/gitignore/get_spec.rb +54 -0
  54. data/spec/github/gitignore/list_spec.rb +42 -0
  55. data/spec/github/issues/comments_spec.rb +46 -11
  56. data/spec/github/pull_requests/comments_spec.rb +46 -11
  57. data/spec/github/pull_requests_spec.rb +3 -3
  58. data/spec/github/repos/contents/archive_spec.rb +26 -0
  59. data/spec/github/repos/contents/get_spec.rb +30 -0
  60. data/spec/github/repos/contents/readme_spec.rb +30 -0
  61. data/spec/github/repos/hooks/create_spec.rb +68 -0
  62. data/spec/github/repos/hooks/delete_spec.rb +40 -0
  63. data/spec/github/repos/hooks/edit_spec.rb +77 -0
  64. data/spec/github/repos/hooks/get_spec.rb +49 -0
  65. data/spec/github/repos/hooks/list_spec.rb +54 -0
  66. data/spec/github/repos/hooks/test_spec.rb +40 -0
  67. data/spec/github/repos/hooks_spec.rb +2 -337
  68. data/spec/github/repos/keys/create_spec.rb +50 -0
  69. data/spec/github/repos/keys/delete_spec.rb +40 -0
  70. data/spec/github/repos/keys/edit_spec.rb +40 -0
  71. data/spec/github/repos/keys/get_spec.rb +43 -0
  72. data/spec/github/repos/keys/list_spec.rb +52 -0
  73. data/spec/github/repos/keys_spec.rb +2 -213
  74. data/spec/github/repos/list_spec.rb +19 -3
  75. data/spec/github/repos/merging/merge_spec.rb +58 -0
  76. data/spec/github/repos/pub_sub_hubbub_spec.rb +16 -14
  77. data/spec/github/repos/statuses/create_spec.rb +54 -0
  78. data/spec/github/repos/statuses/list_spec.rb +53 -0
  79. data/spec/github/repos/statuses_spec.rb +1 -114
  80. data/spec/github/users/emails/add_spec.rb +33 -0
  81. data/spec/github/users/emails/delete_spec.rb +33 -0
  82. data/spec/github/users/emails/list_spec.rb +52 -0
  83. data/spec/github/users/followers/list_spec.rb +68 -0
  84. data/spec/github/users/followers_spec.rb +0 -70
  85. data/spec/github/users/get_spec.rb +66 -0
  86. data/spec/github/users/keys/create_spec.rb +51 -0
  87. data/spec/github/users/keys/delete_spec.rb +37 -0
  88. data/spec/github/users/keys/get_spec.rb +50 -0
  89. data/spec/github/users/keys/list_spec.rb +50 -0
  90. data/spec/github/users/keys/update_spec.rb +56 -0
  91. data/spec/github/users/list_spec.rb +45 -0
  92. data/spec/github/users/update_spec.rb +56 -0
  93. metadata +96 -43
  94. data/spec/github/repos/contents_spec.rb +0 -65
  95. data/spec/github/repos/merging_spec.rb +0 -71
  96. data/spec/github/repos/starring_spec.rb +0 -4
  97. data/spec/github/users/emails_spec.rb +0 -110
  98. data/spec/github/users/keys_spec.rb +0 -256
  99. data/spec/github/users_spec.rb +0 -128
@@ -24,11 +24,12 @@ describe Github::Repos, '#list' do
24
24
  to_return(:body => fixture('repos/repos_sorted_by_pushed.json'), :status => 200,:headers => {:content_type => "application/json; charset=utf-8"} )
25
25
  }
26
26
 
27
- it "fails if user is unauthenticated" do
27
+ it "falls back to all if user is unauthenticated" do
28
28
  subject.oauth_token = nil
29
- stub_get("/user/repos").to_return(:body => '', :status => 401,
29
+ stub_get("/repositories").to_return(:body => '[]', :status => 200,
30
30
  :headers => {:content_type => "application/json; charset=utf-8"} )
31
- expect { subject.list }.to raise_error(Github::Error::Unauthorized)
31
+ subject.list
32
+ a_get('/repositories').should have_been_made
32
33
  end
33
34
 
34
35
  it "should get the resources" do
@@ -57,6 +58,21 @@ describe Github::Repos, '#list' do
57
58
  end
58
59
  end
59
60
 
61
+ context 'all repositories' do
62
+ let(:request_path) { '/repositories' }
63
+
64
+ before {
65
+ stub_get(request_path).to_return(:body => body, :status => status,
66
+ :headers => {:content_type => "application/json; charset=utf-8"} )
67
+ }
68
+
69
+ it "should get the resources" do
70
+ subject.list
71
+ a_get(request_path).should have_been_made
72
+ end
73
+
74
+ end
75
+
60
76
  context "resource found for organization" do
61
77
  let(:org) { '37signals' }
62
78
  let(:request_path) { "/orgs/#{org}/repos" }
@@ -0,0 +1,58 @@
1
+ require 'spec_helper'
2
+
3
+ describe Github::Repos::Merging, '#merge' do
4
+ let(:user) { 'peter-murach' }
5
+ let(:repo) { 'github' }
6
+ let(:request_path) { "/repos/#{user}/#{repo}/merges" }
7
+ let(:inputs) do
8
+ {
9
+ "base" => "master",
10
+ "head" => "cool_feature",
11
+ "commit_message" => "Shipped cool_feature!"
12
+ }
13
+ end
14
+
15
+ before {
16
+ stub_post(request_path).to_return(:body => body, :status => status,
17
+ :headers => {:content_type => "application/json; charset=utf-8"})
18
+ }
19
+
20
+ after { reset_authentication_for(subject) }
21
+
22
+ context "resouce merged" do
23
+ let(:body) { fixture('repos/merge.json') }
24
+ let(:status) { 201 }
25
+
26
+ it "should fail to merge resource if 'base' input is missing" do
27
+ expect {
28
+ subject.merge user, repo, inputs.except('base')
29
+ }.to raise_error(Github::Error::RequiredParams)
30
+ end
31
+
32
+ it "should fail to create resource if 'head' input is missing" do
33
+ expect {
34
+ subject.merge user, repo, inputs.except('head')
35
+ }.to raise_error(Github::Error::RequiredParams)
36
+ end
37
+
38
+ it "should merge resource successfully" do
39
+ subject.merge user, repo, inputs
40
+ a_post(request_path).with(inputs).should have_been_made
41
+ end
42
+
43
+ it "should return the resource" do
44
+ merge = subject.merge user, repo, inputs
45
+ merge.should be_a Hashie::Mash
46
+ end
47
+
48
+ it "should get the commit comment information" do
49
+ merge = subject.merge user, repo, inputs
50
+ merge.commit.author.login.should == 'octocat'
51
+ end
52
+ end
53
+
54
+ it_should_behave_like 'request failure' do
55
+ let(:requestable) { subject.merge user, repo, inputs }
56
+ end
57
+
58
+ end # merge
@@ -1,7 +1,6 @@
1
1
  require 'spec_helper'
2
2
 
3
3
  describe Github::Repos::PubSubHubbub do
4
- let(:github) { Github.new }
5
4
  let(:topic) { "https://github.com/peter-murach/github/events/push"}
6
5
  let(:callback) { "github://campfire?subdomain=github&room=Commits&token=abc123" }
7
6
  let(:hub_inputs) {
@@ -14,32 +13,34 @@ describe Github::Repos::PubSubHubbub do
14
13
  }
15
14
  }
16
15
 
17
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
16
+ after { reset_authentication_for subject }
18
17
 
19
18
  describe "subscribe" do
20
19
  context "success" do
21
20
  before do
22
- github.oauth_token = OAUTH_TOKEN
21
+ subject.oauth_token = OAUTH_TOKEN
23
22
  stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
24
- to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
23
+ to_return(:body => '[]', :status => 200,
24
+ :headers => {:content_type => "application/json; charset=utf-8"})
25
25
  end
26
26
 
27
27
  it "should subscribe to hub" do
28
- github.repos.pubsubhubbub.subscribe topic, callback
28
+ subject.subscribe topic, callback
29
29
  a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
30
30
  end
31
31
  end
32
32
 
33
33
  context "failure" do
34
34
  before do
35
- github.oauth_token = OAUTH_TOKEN
35
+ subject.oauth_token = OAUTH_TOKEN
36
36
  stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).
37
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
37
+ to_return(:body => '[]', :status => 404,
38
+ :headers => {:content_type => "application/json; charset=utf-8"})
38
39
  end
39
40
 
40
41
  it "should fail to subscribe to hub" do
41
42
  expect {
42
- github.repos.pubsubhubbub.subscribe topic, callback
43
+ subject.subscribe topic, callback
43
44
  }.to raise_error(Github::Error::NotFound)
44
45
  end
45
46
  end
@@ -48,27 +49,28 @@ describe Github::Repos::PubSubHubbub do
48
49
  describe "unsubscribe" do
49
50
  context "success" do
50
51
  before do
51
- github.oauth_token = OAUTH_TOKEN
52
+ subject.oauth_token = OAUTH_TOKEN
52
53
  stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
53
- to_return(:body => '', :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
54
+ to_return(:body => '[]', :status => 200,
55
+ :headers => {:content_type => "application/json; charset=utf-8"})
54
56
  end
55
57
 
56
58
  it "should subscribe to hub" do
57
- github.repos.pubsubhubbub.unsubscribe topic, callback
59
+ subject.unsubscribe topic, callback
58
60
  a_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs).should have_been_made
59
61
  end
60
62
  end
61
63
 
62
64
  context "failure" do
63
65
  before do
64
- github.oauth_token = OAUTH_TOKEN
66
+ subject.oauth_token = OAUTH_TOKEN
65
67
  stub_post("/hub?access_token=#{OAUTH_TOKEN}").with(hub_inputs.merge("hub.mode" => 'unsubscribe')).
66
- to_return(:body => '', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
68
+ to_return(:body => '[]', :status => 404, :headers => {:content_type => "application/json; charset=utf-8"})
67
69
  end
68
70
 
69
71
  it "should fail to subscribe to hub" do
70
72
  expect {
71
- github.repos.pubsubhubbub.unsubscribe topic, callback
73
+ subject.unsubscribe topic, callback
72
74
  }.to raise_error(Github::Error::NotFound)
73
75
  end
74
76
  end
@@ -0,0 +1,54 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Statuses, '#create' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:sha) { 'f5f71ce1b7295c31f091be1654618c7ec0cc6b71' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/statuses/#{sha}" }
10
+ let(:inputs) {
11
+ {
12
+ 'state' => 'success'
13
+ }
14
+ }
15
+
16
+ before {
17
+ stub_post(request_path).with(inputs.except('unrelated')).
18
+ to_return(:body => body, :status => status,
19
+ :headers => {:content_type => "application/json; charset=utf-8"})
20
+ }
21
+
22
+ after { reset_authentication_for(subject) }
23
+
24
+ context "resource created" do
25
+ let(:body) { fixture('repos/status.json') }
26
+ let(:status) { 201 }
27
+
28
+ it "should fail to create resource if 'state' input is missing" do
29
+ expect {
30
+ subject.create user, repo, sha, inputs.except('state')
31
+ }.to raise_error(Github::Error::RequiredParams)
32
+ end
33
+
34
+ it "should create resource successfully" do
35
+ subject.create user, repo, sha, inputs
36
+ a_post(request_path).with(inputs).should have_been_made
37
+ end
38
+
39
+ it "should return the resource" do
40
+ status = subject.create user, repo, sha, inputs
41
+ status.should be_a Hashie::Mash
42
+ end
43
+
44
+ it "should get the status information" do
45
+ status = subject.create user, repo, sha, inputs
46
+ status.state.should == 'success'
47
+ end
48
+ end
49
+
50
+ it_should_behave_like 'request failure' do
51
+ let(:requestable) { subject.create user, repo, sha, inputs }
52
+ end
53
+
54
+ end # create
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Repos::Statuses, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:sha) { 'f5f71ce1b7295c31f091be1654618c7ec0cc6b71' }
9
+ let(:request_path) { "/repos/#{user}/#{repo}/statuses/#{sha}" }
10
+
11
+ before {
12
+ stub_get(request_path).to_return(:body => body, :status => status,
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ context "resource found" do
19
+ let(:body) { fixture('repos/statuses.json') }
20
+ let(:status) { 200 }
21
+
22
+ it { should respond_to :all }
23
+
24
+ it "should fail to get resource without sha" do
25
+ expect { subject.list user, repo }.to raise_error(ArgumentError)
26
+ end
27
+
28
+ it "should get the resources" do
29
+ subject.list user, repo, sha
30
+ a_get(request_path).should have_been_made
31
+ end
32
+
33
+ it_should_behave_like 'an array of resources' do
34
+ let(:requestable) { subject.list user, repo, sha }
35
+ end
36
+
37
+ it "should get status information" do
38
+ statuses = subject.list user, repo, sha
39
+ statuses.first.state.should == 'success'
40
+ end
41
+
42
+ it "should yield to a block" do
43
+ yielded = []
44
+ result = subject.list(user, repo, sha) { |obj| yielded << obj }
45
+ yielded.should == result
46
+ end
47
+ end
48
+
49
+ it_should_behave_like 'request failure' do
50
+ let(:requestable) { subject.list user, repo, sha }
51
+ end
52
+
53
+ end # list
@@ -3,122 +3,9 @@
3
3
  require 'spec_helper'
4
4
 
5
5
  describe Github::Repos::Statuses do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
- let(:sha) { 'f5f71ce1b7295c31f091be1654618c7ec0cc6b71' }
10
-
11
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
12
6
 
13
7
  it { described_class::VALID_STATUS_PARAM_NAMES.should_not be_nil }
14
- it { described_class::REQUIRED_PARAMS.should_not be_nil }
15
-
16
- describe "#list" do
17
- it { github.repos.statuses.should respond_to :all }
18
-
19
- context "resource found" do
20
- before do
21
- stub_get("/repos/#{user}/#{repo}/statuses/#{sha}").
22
- to_return(:body => fixture('repos/statuses.json'), :status => 200,
23
- :headers => {:content_type => "application/json; charset=utf-8"})
24
- end
25
-
26
- it "should fail to get resource without sha" do
27
- expect { github.repos.statuses.list }.to raise_error(ArgumentError)
28
- end
29
-
30
- it "should get the resources" do
31
- github.repos.statuses.list user, repo, sha
32
- a_get("/repos/#{user}/#{repo}/statuses/#{sha}").should have_been_made
33
- end
34
-
35
- it "should return array of resources" do
36
- statuses = github.repos.statuses.list user, repo, sha
37
- statuses.should be_an Array
38
- statuses.should have(1).items
39
- end
40
-
41
- it "should be a mash type" do
42
- statuses = github.repos.statuses.list user, repo, sha
43
- statuses.first.should be_a Hashie::Mash
44
- end
45
-
46
- it "should get status information" do
47
- statuses = github.repos.statuses.list user, repo, sha
48
- statuses.first.state.should == 'success'
49
- end
50
-
51
- it "should yield to a block" do
52
- github.repos.statuses.should_receive(:list).with(user, repo, sha).and_yield('web')
53
- github.repos.statuses.list(user, repo, sha) { |param| 'web' }
54
- end
55
- end
56
8
 
57
- context "resource not found" do
58
- before do
59
- stub_get("/repos/#{user}/#{repo}/statuses/#{sha}").
60
- to_return(:body => "", :status => [404, "Not Found"])
61
- end
62
-
63
- it "should return 404 with a message 'Not Found'" do
64
- expect {
65
- github.repos.statuses.list user, repo, sha
66
- }.to raise_error(Github::Error::NotFound)
67
- end
68
- end
69
- end # list
70
-
71
- describe "#create" do
72
- let(:inputs) {
73
- {
74
- 'state' => 'success'
75
- }
76
- }
77
-
78
- context "resource created" do
79
- before do
80
- stub_post("/repos/#{user}/#{repo}/statuses/#{sha}").
81
- with(inputs.except('unrelated')).
82
- to_return(:body => fixture('repos/status.json'),
83
- :status => 201,
84
- :headers => {:content_type => "application/json; charset=utf-8"})
85
- end
86
-
87
- it "should fail to create resource if 'state' input is missing" do
88
- expect {
89
- github.repos.statuses.create user, repo, sha, inputs.except('state')
90
- }.to raise_error(Github::Error::RequiredParams)
91
- end
92
-
93
- it "should create resource successfully" do
94
- github.repos.statuses.create user, repo, sha, inputs
95
- a_post("/repos/#{user}/#{repo}/statuses/#{sha}").with(inputs).should have_been_made
96
- end
97
-
98
- it "should return the resource" do
99
- status = github.repos.statuses.create user, repo, sha, inputs
100
- status.should be_a Hashie::Mash
101
- end
102
-
103
- it "should get the status information" do
104
- status = github.repos.statuses.create user, repo, sha, inputs
105
- status.state.should == 'success'
106
- end
107
- end
108
-
109
- context "fail to create resource" do
110
- before do
111
- stub_post("/repos/#{user}/#{repo}/statuses/#{sha}").with(inputs).
112
- to_return(:body => fixture('repos/status.json'), :status => 404,
113
- :headers => {:content_type => "application/json; charset=utf-8"})
114
- end
115
-
116
- it "should fail to retrieve resource" do
117
- expect {
118
- github.repos.statuses.create user, repo, sha, inputs
119
- }.to raise_error(Github::Error::NotFound)
120
- end
121
- end
122
- end # create
9
+ it { described_class::REQUIRED_PARAMS.should_not be_nil }
123
10
 
124
11
  end # Github::Repos::Statuses
@@ -0,0 +1,33 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Users::Emails, '#add' do
6
+ let(:email) { "octocat@github.com" }
7
+ let(:request_path) { "/user/emails" }
8
+
9
+ before {
10
+ subject.oauth_token = OAUTH_TOKEN
11
+ stub_post(request_path).with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
12
+ to_return(:body => body, :status => status,
13
+ :headers => {:content_type => "application/json; charset=utf-8"})
14
+ }
15
+
16
+ after { reset_authentication_for(subject) }
17
+
18
+ let(:params) { { :per_page => 21, :page => 1 }}
19
+ let(:body) { fixture('users/emails.json') }
20
+ let(:status) { 200 }
21
+
22
+ it 'extracts request parameters and email data' do
23
+ subject.should_receive(:post_request).
24
+ with(request_path, { "per_page" => 21, "page" => 1, "data" => [email] })
25
+ subject.add email, params
26
+ end
27
+
28
+ it 'submits request successfully' do
29
+ subject.add email
30
+ a_post(request_path).with(:query => { :access_token => "#{OAUTH_TOKEN}"}).
31
+ should have_been_made
32
+ end
33
+ end # add