github_api 0.7.2 → 0.8.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 (74) hide show
  1. data/README.md +6 -5
  2. data/features/{events.feature → activity/events.feature} +8 -8
  3. data/features/{repos → activity}/starring.feature +6 -6
  4. data/features/{repos → activity}/watching.feature +6 -6
  5. data/features/cassettes/{events → activity/events}/issue.yml +0 -0
  6. data/features/cassettes/{events → activity/events}/network.yml +0 -0
  7. data/features/cassettes/{events → activity/events}/org.yml +0 -0
  8. data/features/cassettes/{events → activity/events}/performed.yml +0 -0
  9. data/features/cassettes/{events → activity/events}/public.yml +0 -0
  10. data/features/cassettes/{events → activity/events}/received.yml +0 -0
  11. data/features/cassettes/{events → activity/events}/repo.yml +0 -0
  12. data/features/cassettes/{events → activity/events}/user_org.yml +0 -0
  13. data/features/cassettes/{repos → activity}/starring/list.yml +0 -0
  14. data/features/cassettes/{repos → activity}/starring/star.yml +0 -0
  15. data/features/cassettes/{repos → activity}/starring/starred.yml +0 -0
  16. data/features/cassettes/{repos → activity}/starring/starring.yml +0 -0
  17. data/features/cassettes/{repos → activity}/starring/unstar.yml +0 -0
  18. data/features/cassettes/{repos → activity}/watching/list.yml +0 -0
  19. data/features/cassettes/{repos → activity}/watching/unwatch.yml +0 -0
  20. data/features/cassettes/{repos → activity}/watching/watch.yml +0 -0
  21. data/features/cassettes/{repos → activity}/watching/watched.yml +0 -0
  22. data/features/cassettes/{repos → activity}/watching/watching.yml +0 -0
  23. data/features/github_api.feature +3 -3
  24. data/lib/github_api.rb +1 -1
  25. data/lib/github_api/activity.rb +39 -0
  26. data/lib/github_api/{events.rb → activity/events.rb} +5 -5
  27. data/lib/github_api/activity/notifications.rb +162 -0
  28. data/lib/github_api/{repos → activity}/starring.rb +9 -9
  29. data/lib/github_api/{repos → activity}/watching.rb +9 -9
  30. data/lib/github_api/client.rb +6 -4
  31. data/lib/github_api/repos.rb +2 -14
  32. data/lib/github_api/response.rb +0 -1
  33. data/lib/github_api/version.rb +2 -2
  34. data/spec/fixtures/activity/notifications.json +32 -0
  35. data/spec/fixtures/activity/subscribed.json +8 -0
  36. data/spec/fixtures/activity/threads.json +32 -0
  37. data/spec/github/activity/activity_spec.rb +16 -0
  38. data/spec/github/activity/events/issue_spec.rb +63 -0
  39. data/spec/github/activity/events/network_spec.rb +61 -0
  40. data/spec/github/activity/events/org_spec.rb +60 -0
  41. data/spec/github/activity/events/performed_spec.rb +91 -0
  42. data/spec/github/activity/events/public_spec.rb +55 -0
  43. data/spec/github/activity/events/received_spec.rb +91 -0
  44. data/spec/github/activity/events/repository_spec.rb +65 -0
  45. data/spec/github/activity/events/user_org_spec.rb +63 -0
  46. data/spec/github/activity/notifications/create_spec.rb +44 -0
  47. data/spec/github/activity/notifications/delete_spec.rb +41 -0
  48. data/spec/github/activity/notifications/get_spec.rb +58 -0
  49. data/spec/github/activity/notifications/list_spec.rb +82 -0
  50. data/spec/github/activity/notifications/mark_spec.rb +74 -0
  51. data/spec/github/activity/notifications/subscribed_spec.rb +48 -0
  52. data/spec/github/activity/starring/list_spec.rb +64 -0
  53. data/spec/github/activity/starring/star_spec.rb +36 -0
  54. data/spec/github/activity/starring/starred_spec.rb +53 -0
  55. data/spec/github/activity/starring/starring_spec.rb +38 -0
  56. data/spec/github/activity/starring/unstar_spec.rb +37 -0
  57. data/spec/github/activity/watching/list_spec.rb +59 -0
  58. data/spec/github/activity/watching/unwatch_spec.rb +37 -0
  59. data/spec/github/activity/watching/watch_spec.rb +37 -0
  60. data/spec/github/activity/watching/watched_spec.rb +53 -0
  61. data/spec/github/activity/watching/watching_spec.rb +41 -0
  62. data/spec/github/authorization_spec.rb +2 -2
  63. data/spec/github/issues_spec.rb +1 -1
  64. data/spec/github/repos/comments/delete_spec.rb +2 -0
  65. data/spec/github/repos/delete_spec.rb +1 -1
  66. data/spec/github/repos/get_spec.rb +2 -2
  67. data/spec/github/repos/starring_spec.rb +0 -199
  68. data/spec/github/repos_spec.rb +0 -4
  69. data/spec/github/result_spec.rb +1 -1
  70. metadata +88 -62
  71. data/features/cassettes/git_data/tags/get.yml +0 -54
  72. data/features/git_data/tags.feature +0 -17
  73. data/spec/github/events_spec.rb +0 -491
  74. data/spec/github/repos/watching_spec.rb +0 -203
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Starring, '#unstar' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/user/starred/#{user}/#{repo}" }
9
+
10
+ after { reset_authentication_for subject }
11
+
12
+ context "user authenticated" do
13
+ context "with correct information" do
14
+ before do
15
+ subject.oauth_token = OAUTH_TOKEN
16
+ stub_delete("/user/starred/#{user}/#{repo}").
17
+ with(:query => {:access_token => OAUTH_TOKEN}).
18
+ to_return(:body => "", :status => 204, :headers => {})
19
+ end
20
+
21
+ it "should successfully unstar a repo" do
22
+ subject.unstar user, repo
23
+ a_delete(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
24
+ should have_been_made
25
+ end
26
+ end
27
+ end
28
+
29
+ context "user unauthenticated" do
30
+ it "should fail" do
31
+ stub_delete(request_path).to_return(:body => "", :status => 401, :headers => {})
32
+ expect {
33
+ subject.unstar user, repo
34
+ }.to raise_error(Github::Error::Unauthorized)
35
+ end
36
+ end
37
+ end # unstar
@@ -0,0 +1,59 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Watching, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/subscribers" }
9
+ let(:body) { fixture("repos/watchers.json") }
10
+ let(:status) { 200 }
11
+
12
+ after { reset_authentication_for subject }
13
+
14
+ before {
15
+ stub_get(request_path).
16
+ to_return(:body => body, :status => status, :headers => {})
17
+ }
18
+
19
+ it "should fail to get resource without username" do
20
+ expect { subject.list }.to raise_error(ArgumentError)
21
+ end
22
+
23
+ it "should yield iterator if block given" do
24
+ subject.should_receive(:list).with(user, repo).and_yield('github')
25
+ subject.list(user, repo) { |param| 'github' }
26
+ end
27
+
28
+ it "should get the resources" do
29
+ subject.list user, repo
30
+ a_get(request_path).should have_been_made
31
+ end
32
+
33
+ it "should return array of resources" do
34
+ watchers = subject.list user, repo
35
+ watchers.should be_an Array
36
+ watchers.should have(1).items
37
+ end
38
+
39
+ it "should return result of mash type" do
40
+ watchers = subject.list user, repo
41
+ watchers.first.should be_a Hashie::Mash
42
+ end
43
+
44
+ it "should get watcher information" do
45
+ watchers = subject.list user, repo
46
+ watchers.first.login.should == 'octocat'
47
+ end
48
+
49
+ context "fail to find resource" do
50
+ let(:body) { '' }
51
+ let(:status) { 404 }
52
+
53
+ it "should return 404 not found message" do
54
+ expect {
55
+ subject.list user, repo
56
+ }.to raise_error(Github::Error::NotFound)
57
+ end
58
+ end
59
+ end # list
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Watching, '#unwatch' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/user/subscriptions/#{user}/#{repo}" }
9
+
10
+ after { reset_authentication_for subject }
11
+
12
+ context "user authenticated" do
13
+ context "with correct information" do
14
+ before do
15
+ subject.oauth_token = OAUTH_TOKEN
16
+ stub_delete(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
17
+ to_return(:body => "", :status => 204, :headers => {})
18
+ end
19
+
20
+ it "should successfully watch a repo" do
21
+ subject.unwatch user, repo
22
+ a_delete(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
23
+ should have_been_made
24
+ end
25
+ end
26
+ end
27
+
28
+ context "user unauthenticated" do
29
+ it "should fail" do
30
+ stub_delete(request_path).
31
+ to_return(:body => "", :status => 401, :headers => {})
32
+ expect {
33
+ subject.unwatch user, repo
34
+ }.to raise_error(Github::Error::Unauthorized)
35
+ end
36
+ end
37
+ end # unwatch
@@ -0,0 +1,37 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Watching, '#watch' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/user/subscriptions/#{user}/#{repo}" }
9
+
10
+ after { reset_authentication_for subject }
11
+
12
+ context "user authenticated" do
13
+ context "with correct information" do
14
+ before do
15
+ subject.oauth_token = OAUTH_TOKEN
16
+ stub_put(request_path).
17
+ with(:query => {:access_token => OAUTH_TOKEN}).
18
+ to_return(:body => "", :status => 204, :headers => {})
19
+ end
20
+
21
+ it "should successfully watch a repo" do
22
+ subject.watch user, repo
23
+ a_put(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
24
+ should have_been_made
25
+ end
26
+ end
27
+ end
28
+
29
+ context "user unauthenticated" do
30
+ it "should fail" do
31
+ stub_put(request_path).to_return(:body => "", :status => 401, :headers => {})
32
+ expect {
33
+ subject.watch user, repo
34
+ }.to raise_error(Github::Error::Unauthorized)
35
+ end
36
+ end
37
+ end # watch
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Watching, '#watched' do
6
+ let(:user) { 'peter-murach' }
7
+
8
+ after { reset_authentication_for subject }
9
+
10
+ context "if user unauthenticated" do
11
+ it "should fail to get resource without username " do
12
+ stub_get("/user/subscriptions").
13
+ to_return(:body => '', :status => 401, :headers => {})
14
+ expect {
15
+ subject.watched
16
+ }.to raise_error(Github::Error::Unauthorized)
17
+ end
18
+
19
+ it "should get the resource with username" do
20
+ stub_get("/users/#{user}/subscriptions").
21
+ to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
22
+ subject.watched :user => user
23
+ a_get("/users/#{user}/subscriptions").should have_been_made
24
+ end
25
+ end
26
+
27
+ context "if user authenticated" do
28
+ before do
29
+ subject.oauth_token = OAUTH_TOKEN
30
+ stub_get("/user/subscriptions").
31
+ with(:query => {:access_token => OAUTH_TOKEN}).
32
+ to_return(:body => fixture("repos/watched.json"), :status => 200, :headers => {})
33
+ end
34
+
35
+ it "should get the resources" do
36
+ subject.watched
37
+ a_get("/user/subscriptions").with(:query => {:access_token => OAUTH_TOKEN}).
38
+ should have_been_made
39
+ end
40
+
41
+ it "should return array of resources" do
42
+ watched = subject.watched
43
+ watched.should be_an Array
44
+ watched.should have(1).items
45
+ end
46
+
47
+ it "should get watched information" do
48
+ watched = subject.watched
49
+ watched.first.name.should == 'Hello-World'
50
+ end
51
+ end
52
+ end # watched
53
+
@@ -0,0 +1,41 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Watching, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/user/subscriptions/#{user}/#{repo}" }
9
+
10
+ after { reset_authentication_for subject }
11
+
12
+ context "with username ane reponame passed" do
13
+ context "this repo is being watched by the user"
14
+ before do
15
+ stub_get(request_path).
16
+ to_return(:body => "", :status => 404,
17
+ :headers => {:user_agent => subject.user_agent})
18
+ end
19
+
20
+ it "should return false if resource not found" do
21
+ watching = subject.watching? user, repo
22
+ watching.should be_false
23
+ end
24
+
25
+ it "should return true if resoure found" do
26
+ stub_get(request_path).
27
+ to_return(:body => "", :status => 200,
28
+ :headers => {:user_agent => subject.user_agent})
29
+ watching = subject.watching? user, repo
30
+ watching.should be_true
31
+ end
32
+ end
33
+
34
+ context "without username and reponame passed" do
35
+ it "should fail validation " do
36
+ expect {
37
+ subject.watching?(nil, nil)
38
+ }.to raise_error(ArgumentError)
39
+ end
40
+ end
41
+ end # watching?
@@ -40,12 +40,12 @@ describe Github::Authorization do
40
40
 
41
41
  it "should throw an error if no client_id" do
42
42
  github.client_id = nil
43
- expect { github.auth_code }.should raise_error(ArgumentError)
43
+ expect { github.auth_code }.to raise_error(ArgumentError)
44
44
  end
45
45
 
46
46
  it "should throw an error if no client_secret" do
47
47
  github.client_secret = nil
48
- expect { github.auth_code }.should raise_error(ArgumentError)
48
+ expect { github.auth_code }.to raise_error(ArgumentError)
49
49
  end
50
50
 
51
51
  it "should return authentication token code" do
@@ -78,7 +78,7 @@ describe Github::Issues do
78
78
  it "should raise error if user-name empty" do
79
79
  expect {
80
80
  github.issues.list_repo nil, repo
81
- }.should raise_error(ArgumentError)
81
+ }.to raise_error(ArgumentError)
82
82
  end
83
83
 
84
84
  it "should get the resources" do
@@ -14,6 +14,8 @@ describe Github::Repos::Comments, '#delete' do
14
14
  :headers => { :content_type => "application/json; charset=utf-8"})
15
15
  }
16
16
 
17
+ after { reset_authentication_for subject }
18
+
17
19
  context "resource deleted successfully" do
18
20
  let(:body) { '' }
19
21
  let(:status) { 204 }
@@ -2,7 +2,7 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Github::Repos do
5
+ describe Github::Repos, '#delete' do
6
6
  let(:user) { 'peter-murach' }
7
7
  let(:repo) { 'github' }
8
8
  let(:request_path) { "/repos/#{user}/#{repo}" }
@@ -8,8 +8,8 @@ describe Github::Repos, '#get' do
8
8
  let(:request_path) { "/repos/#{user}/#{repo}" }
9
9
 
10
10
  before {
11
- stub_get(request_path).
12
- to_return(:body => body, :status => status, :headers => {:content_type => "application/json; charset=utf-8"})
11
+ stub_get(request_path).to_return(:body => body, :status => status,
12
+ :headers => {:content_type => "application/json; charset=utf-8"})
13
13
  }
14
14
 
15
15
  after { reset_authentication_for subject }
@@ -2,202 +2,3 @@
2
2
 
3
3
  require 'spec_helper'
4
4
 
5
- describe Github::Repos::Starring do
6
- let(:github) { Github.new }
7
- let(:user) { 'peter-murach' }
8
- let(:repo) { 'github' }
9
-
10
- after { github.user, github.repo, github.oauth_token = nil, nil, nil }
11
-
12
- describe "#list" do
13
- before do
14
- stub_get("/repos/#{user}/#{repo}/stargazers").
15
- to_return(:body => fixture("repos/stargazers.json"),
16
- :status => 200, :headers => {})
17
- end
18
-
19
- it "should fail to get resource without username" do
20
- expect {
21
- github.repos.starring.list
22
- }.to raise_error(ArgumentError)
23
- end
24
-
25
- it "should yield iterator if block given" do
26
- github.repos.starring.should_receive(:list).
27
- with(user, repo).and_yield('github')
28
- github.repos.starring.list(user, repo) { |param| 'github' }
29
- end
30
-
31
- it "should get the resources" do
32
- github.repos.starring.list user, repo
33
- a_get("/repos/#{user}/#{repo}/stargazers").should have_been_made
34
- end
35
-
36
- it "should return array of resources" do
37
- stargazers = github.repos.starring.list user, repo
38
- stargazers.should be_an Array
39
- stargazers.should have(1).items
40
- end
41
-
42
- it "should return result of mash type" do
43
- stargazers = github.repos.starring.list user, repo
44
- stargazers.first.should be_a Hashie::Mash
45
- end
46
-
47
- it "should get watcher information" do
48
- stargazers = github.repos.starring.list user, repo
49
- stargazers.first.login.should == 'octocat'
50
- end
51
-
52
- context "fail to find resource" do
53
- before do
54
- stub_get("/repos/#{user}/#{repo}/stargazers").
55
- to_return(:body => "", :status => 404)
56
- end
57
-
58
- it "should return 404 not found message" do
59
- expect {
60
- github.repos.starring.list user, repo
61
- }.to raise_error(Github::Error::NotFound)
62
- end
63
- end
64
- end
65
-
66
- describe "#starred" do
67
- context "if user unauthenticated" do
68
- it "should fail to get resource without username " do
69
- stub_get("/user/starred").
70
- to_return(:body => '', :status => 401, :headers => {})
71
- expect {
72
- github.repos.starring.starred
73
- }.to raise_error(Github::Error::Unauthorized)
74
- end
75
-
76
- it "should get the resource with username" do
77
- stub_get("/users/#{user}/starred").
78
- to_return(:body => fixture("repos/starred.json"), :status => 200, :headers => {})
79
- github.repos.starring.starred :user => user
80
- a_get("/users/#{user}/starred").should have_been_made
81
- end
82
- end
83
-
84
- context "if user authenticated" do
85
- before do
86
- github.oauth_token = OAUTH_TOKEN
87
- stub_get("/user/starred").
88
- with(:query => {:access_token => OAUTH_TOKEN}).
89
- to_return(:body => fixture("repos/starred.json"),
90
- :status => 200, :headers => {})
91
- end
92
-
93
- it "should get the resources" do
94
- github.repos.starring.starred
95
- a_get("/user/starred").with(:query => {:access_token => OAUTH_TOKEN}).
96
- should have_been_made
97
- end
98
-
99
- it "should return array of resources" do
100
- starred = github.repos.starring.starred
101
- starred.should be_an Array
102
- starred.should have(1).items
103
- end
104
-
105
- it "should get starred information" do
106
- starred = github.repos.starring.starred
107
- starred.first.name.should == 'Hello-World'
108
- starred.first.owner.login.should == 'octocat'
109
- end
110
- end
111
- end # starred
112
-
113
- describe "starring?" do
114
- context "with username ane reponame passed" do
115
- context "this repo is being watched by the user"
116
- before do
117
- stub_get("/user/starred/#{user}/#{repo}").
118
- to_return(:body => "", :status => 404,
119
- :headers => {:user_agent => github.user_agent})
120
- end
121
-
122
- it "should return false if resource not found" do
123
- starring = github.repos.starring.starring? user, repo
124
- starring.should be_false
125
- end
126
-
127
- it "should return true if resoure found" do
128
- stub_get("/user/starred/#{user}/#{repo}").
129
- to_return(:body => "", :status => 200,
130
- :headers => {:user_agent => github.user_agent})
131
- starring = github.repos.starring.starring? user, repo
132
- starring.should be_true
133
- end
134
- end
135
-
136
- context "without username and reponame passed" do
137
- it "should fail validation " do
138
- expect {
139
- github.repos.starring.starring?(nil, nil)
140
- }.to raise_error(ArgumentError)
141
- end
142
- end
143
- end # starring?
144
-
145
- describe "#star" do
146
- context "user authenticated" do
147
- context "with correct information" do
148
- before do
149
- github.oauth_token = OAUTH_TOKEN
150
- stub_put("/user/starred/#{user}/#{repo}").
151
- with(:query => {:access_token => OAUTH_TOKEN}).
152
- to_return(:body => "", :status => 204, :headers => {})
153
- end
154
-
155
- it "should successfully star a repo" do
156
- github.repos.starring.star user, repo
157
- a_put("/user/starred/#{user}/#{repo}").
158
- with(:query => {:access_token => OAUTH_TOKEN}).
159
- should have_been_made
160
- end
161
- end
162
- end
163
-
164
- context "user unauthenticated" do
165
- it "should fail" do
166
- stub_put("/user/starred/#{user}/#{repo}").
167
- to_return(:body => "", :status => 401, :headers => {})
168
- expect {
169
- github.repos.starring.star user, repo
170
- }.to raise_error(Github::Error::Unauthorized)
171
- end
172
- end
173
- end # star
174
-
175
- describe "#unstar" do
176
- context "user authenticated" do
177
- context "with correct information" do
178
- before do
179
- github.oauth_token = OAUTH_TOKEN
180
- stub_delete("/user/starred/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
181
- to_return(:body => "", :status => 204, :headers => {})
182
- end
183
-
184
- it "should successfully unstar a repo" do
185
- github.repos.starring.unstar user, repo
186
- a_delete("/user/starred/#{user}/#{repo}?access_token=#{OAUTH_TOKEN}").
187
- should have_been_made
188
- end
189
- end
190
- end
191
-
192
- context "user unauthenticated" do
193
- it "should fail" do
194
- stub_delete("/user/starred/#{user}/#{repo}").
195
- to_return(:body => "", :status => 401, :headers => {})
196
- expect {
197
- github.repos.starring.unstar user, repo
198
- }.to raise_error(Github::Error::Unauthorized)
199
- end
200
- end
201
- end # stop_watching
202
-
203
- end # Github::Respos::Starring