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,58 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Notifications, '#get' do
6
+ let(:thread_id) { 1 }
7
+ let(:request_path) { "/notifications/threads/#{thread_id}" }
8
+
9
+ before {
10
+ stub_get(request_path).to_return(:body => body, :status => status,
11
+ :headers => {:content_type => "application/json; charset=utf-8"})
12
+ }
13
+
14
+ after { reset_authentication_for subject }
15
+
16
+ context "resource found" do
17
+ let(:body) { fixture('activity/threads.json') }
18
+ let(:status) { 200 }
19
+
20
+ it { should respond_to(:find) }
21
+
22
+ it "should raise error when no thread-id parameter" do
23
+ expect { subject.get nil }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should find resources" do
27
+ subject.get thread_id
28
+ a_get(request_path).should have_been_made
29
+ end
30
+
31
+ it "should return repository mash" do
32
+ threads = subject.get thread_id
33
+ threads.should be_an Array
34
+ threads.should have(1).items
35
+ end
36
+
37
+ it "should get repository information" do
38
+ threads = subject.get thread_id
39
+ threads.first.repository.name.should == 'Hello-World'
40
+ end
41
+
42
+ it "should yield repositories to a block" do
43
+ subject.should_receive(:get).and_yield('octocat')
44
+ subject.get(thread_id) { |repo| 'octocat' }
45
+ end
46
+ end
47
+
48
+ context "resource not found" do
49
+ let(:body) { '' }
50
+ let(:status) { 404 }
51
+
52
+ it "should fail to get resource" do
53
+ expect {
54
+ subject.get thread_id
55
+ }.to raise_error(Github::Error::NotFound)
56
+ end
57
+ end
58
+ end # get
@@ -0,0 +1,82 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Notifications, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ before { subject.oauth_token = OAUTH_TOKEN }
10
+
11
+ after { reset_authentication_for subject }
12
+
13
+ context 'resource found for authenticated user' do
14
+ let(:request_path) { "/notifications" }
15
+ let(:body) { fixture('activity/notifications.json') }
16
+ let(:status) { 200 }
17
+
18
+ before {
19
+ stub_get(request_path).with(:query => {:access_token => OAUTH_TOKEN }).
20
+ to_return(:body => body, :status => status,
21
+ :headers => {:content_type => "application/json; charset=utf-8"})
22
+ }
23
+
24
+ it { should respond_to :all }
25
+
26
+ it 'filters unkown parameters' do
27
+ subject.list :unkown => true
28
+ a_get(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
29
+ should have_been_made
30
+ end
31
+
32
+ it 'should get the resource' do
33
+ subject.list
34
+ a_get(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
35
+ should have_been_made
36
+ end
37
+
38
+ it "should return array of resources" do
39
+ notifications = subject.list
40
+ notifications.should be_an Array
41
+ notifications.should have(1).items
42
+ end
43
+
44
+ it "should get resource information" do
45
+ notifications = subject.list
46
+ notifications.first.repository.name.should == 'Hello-World'
47
+ end
48
+
49
+ it "should yield repositories to a block" do
50
+ subject.should_receive(:list).and_yield('octocat')
51
+ subject.list { |repo| 'octocat' }
52
+ end
53
+
54
+ context "resource not found for a user" do
55
+ let(:body) { '' }
56
+ let(:status) { [404, "Not Found"] }
57
+
58
+ it "should return 404 with a message 'Not Found'" do
59
+ expect { subject.list }.to raise_error(Github::Error::NotFound)
60
+ end
61
+ end
62
+ end
63
+
64
+ context 'resource found for repository' do
65
+ let(:body) { fixture('activity/notifications.json') }
66
+ let(:status) { 200 }
67
+ let(:request_path) { "/repos/#{user}/#{repo}/notifications"}
68
+
69
+ before {
70
+ stub_get(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
71
+ to_return(:body => body, :status => status,
72
+ :headers => {:content_type => "application/json; charset=utf-8"})
73
+ }
74
+
75
+ it "should get the resource" do
76
+ subject.list :user => user, :repo => repo
77
+ a_get(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
78
+ should have_been_made
79
+ end
80
+ end
81
+
82
+ end
@@ -0,0 +1,74 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Notifications, '#mark' do
6
+ let(:body) { '' }
7
+ let(:status) { 205 }
8
+ let(:inputs) { {
9
+ :read => true,
10
+ :unread => false,
11
+ :last_read_at => "2012-10-09T23:39:01Z"
12
+ }}
13
+
14
+ before { subject.oauth_token = OAUTH_TOKEN }
15
+
16
+ after { reset_authentication_for subject }
17
+
18
+ context 'an authenticate user' do
19
+ let(:request_path) { '/notifications'}
20
+
21
+ before {
22
+ stub_put(request_path).
23
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN }).
24
+ to_return(:body => body, :status => status,
25
+ :headers => {:content_type => "application/json; charset=utf-8"})
26
+ }
27
+
28
+ it 'should get the resource' do
29
+ subject.mark inputs.merge(:unknown => true)
30
+ a_put(request_path).
31
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN}).
32
+ should have_been_made
33
+ end
34
+ end
35
+
36
+ context 'in a repository' do
37
+ let(:user) { 'peter-murach' }
38
+ let(:repo) { 'github' }
39
+ let(:request_path) { "/repos/#{user}/#{repo}/notifications" }
40
+
41
+ before {
42
+ stub_put(request_path).
43
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN }).
44
+ to_return(:body => body, :status => status,
45
+ :headers => {:content_type => "application/json; charset=utf-8"})
46
+ }
47
+
48
+ it 'should get the resource' do
49
+ subject.mark inputs.merge(:user => user, :repo => repo)
50
+ a_put(request_path).
51
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN}).
52
+ should have_been_made
53
+ end
54
+ end
55
+
56
+ context 'a thread' do
57
+ let(:thread_id) { 1 }
58
+ let(:request_path) { "/notifications/threads/#{thread_id}" }
59
+
60
+ before {
61
+ stub_patch(request_path).
62
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN }).
63
+ to_return(:body => body, :status => status,
64
+ :headers => {:content_type => "application/json; charset=utf-8"})
65
+ }
66
+
67
+ it 'should get the resource' do
68
+ subject.mark inputs.merge(:thread_id => thread_id)
69
+ a_patch(request_path).
70
+ with(:body => inputs, :query => {:access_token => OAUTH_TOKEN}).
71
+ should have_been_made
72
+ end
73
+ end
74
+ end # mark
@@ -0,0 +1,48 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Notifications, '#subscribed?' do
6
+ let(:thread_id) { 1 }
7
+ let(:request_path) { "/notifications/threads/#{thread_id}/subscription" }
8
+
9
+ before {
10
+ subject.oauth_token = OAUTH_TOKEN
11
+ stub_get(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
+ context 'resource found for authenticated user' do
19
+ let(:body) { fixture('activity/subscribed.json') }
20
+ let(:status) { 200 }
21
+
22
+ it 'asserts thread id presence' do
23
+ expect { subject.subscribed? nil }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it 'gets the resource' do
27
+ subject.subscribed? thread_id
28
+ a_get(request_path).with(:query => {:access_token => OAUTH_TOKEN }).
29
+ should have_been_made
30
+ end
31
+
32
+ it 'gets resource information' do
33
+ subscribed = subject.subscribed? thread_id
34
+ subscribed.subscribed.should be_true
35
+ end
36
+ end
37
+
38
+ context "resource not found for a user" do
39
+ let(:body) { '' }
40
+ let(:status) { [404, "Not Found"] }
41
+
42
+ it "should return 404 with a message 'Not Found'" do
43
+ expect {
44
+ subject.subscribed? thread_id
45
+ }.to raise_error(Github::Error::NotFound)
46
+ end
47
+ end
48
+ end # subscribed
@@ -0,0 +1,64 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Starring, '#list' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/stargazers" }
9
+
10
+ after { reset_authentication_for subject }
11
+
12
+ before {
13
+ stub_get(request_path).
14
+ to_return(:body => body, :status => status, :headers => {})
15
+ }
16
+
17
+ context 'resource found' do
18
+ let(:body) { fixture("repos/stargazers.json") }
19
+ let(:status) { 200 }
20
+
21
+ it { should respond_to :all }
22
+
23
+ it "should fail to get resource without username" do
24
+ expect { subject.list }.to raise_error(ArgumentError)
25
+ end
26
+
27
+ it "should yield iterator if block given" do
28
+ subject.should_receive(:list).with(user, repo).and_yield('github')
29
+ subject.list(user, repo) { |param| 'github' }
30
+ end
31
+
32
+ it "should get the resources" do
33
+ subject.list user, repo
34
+ a_get(request_path).should have_been_made
35
+ end
36
+
37
+ it "should return array of resources" do
38
+ stargazers = subject.list user, repo
39
+ stargazers.should be_an Array
40
+ stargazers.should have(1).items
41
+ end
42
+
43
+ it "should return result of mash type" do
44
+ stargazers = subject.list user, repo
45
+ stargazers.first.should be_a Hashie::Mash
46
+ end
47
+
48
+ it "should get watcher information" do
49
+ stargazers = subject.list user, repo
50
+ stargazers.first.login.should == 'octocat'
51
+ end
52
+
53
+ context "fail to find resource" do
54
+ let(:body) { '' }
55
+ let(:status) { 404 }
56
+
57
+ it "should return 404 not found message" do
58
+ expect {
59
+ subject.list user, repo
60
+ }.to raise_error(Github::Error::NotFound)
61
+ end
62
+ end
63
+ end
64
+ end # list
@@ -0,0 +1,36 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Starring, '#star' 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_put(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
17
+ to_return(:body => "", :status => 204, :headers => {})
18
+ end
19
+
20
+ it "should successfully star a repo" do
21
+ subject.star user, repo
22
+ a_put(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_put(request_path).to_return(:body => "", :status => 401, :headers => {})
31
+ expect {
32
+ subject.star user, repo
33
+ }.to raise_error(Github::Error::Unauthorized)
34
+ end
35
+ end
36
+ end # star
@@ -0,0 +1,53 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Starring, '#starred' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+
9
+ after { reset_authentication_for subject }
10
+
11
+ context "if user unauthenticated" do
12
+ it "should fail to get resource without username " do
13
+ stub_get("/user/starred").
14
+ to_return(:body => '', :status => 401, :headers => {})
15
+ expect { subject.starred }.to raise_error(Github::Error::Unauthorized)
16
+ end
17
+
18
+ it "should get the resource with username" do
19
+ stub_get("/users/#{user}/starred").
20
+ to_return(:body => fixture("repos/starred.json"), :status => 200, :headers => {})
21
+ subject.starred :user => user
22
+ a_get("/users/#{user}/starred").should have_been_made
23
+ end
24
+ end
25
+
26
+ context "if user authenticated" do
27
+ before do
28
+ subject.oauth_token = OAUTH_TOKEN
29
+ stub_get("/user/starred").
30
+ with(:query => {:access_token => OAUTH_TOKEN}).
31
+ to_return(:body => fixture("repos/starred.json"),
32
+ :status => 200, :headers => {})
33
+ end
34
+
35
+ it "should get the resources" do
36
+ subject.starred
37
+ a_get("/user/starred").with(:query => {:access_token => OAUTH_TOKEN}).
38
+ should have_been_made
39
+ end
40
+
41
+ it "should return array of resources" do
42
+ starred = subject.starred
43
+ starred.should be_an Array
44
+ starred.should have(1).items
45
+ end
46
+
47
+ it "should get starred information" do
48
+ starred = subject.starred
49
+ starred.first.name.should == 'Hello-World'
50
+ starred.first.owner.login.should == 'octocat'
51
+ end
52
+ end
53
+ end # starred
@@ -0,0 +1,38 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Starring, '#list' 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 "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
+ starring = subject.starring? user, repo
22
+ starring.should be_false
23
+ end
24
+
25
+ it "should return true if resoure found" do
26
+ stub_get(request_path).to_return(:body => "", :status => 200,
27
+ :headers => {:user_agent => subject.user_agent})
28
+ starring = subject.starring? user, repo
29
+ starring.should be_true
30
+ end
31
+ end
32
+
33
+ context "without username and reponame passed" do
34
+ it "should fail validation " do
35
+ expect { subject.starring? nil, nil }.to raise_error(ArgumentError)
36
+ end
37
+ end
38
+ end # starring?