github_api 0.7.2 → 0.8.0

Sign up to get free protection for your applications and to get access to all the features.
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
@@ -3,14 +3,14 @@
3
3
  module Github
4
4
  # Repository Starring is a feature that lets users bookmark repositories.
5
5
  # Stars are shown next to repositories to show an approximate level of interest. # Stars have no effect on notifications or the activity feed.
6
- class Repos::Starring < API
6
+ class Activity::Starring < API
7
7
 
8
8
  # List stargazers
9
9
  #
10
10
  # = Examples
11
11
  # github = Github.new :user => 'user-name', :repo => 'repo-name'
12
- # github.repos.starring.list
13
- # github.repos.starring.list { |star| ... }
12
+ # github.activity.starring.list
13
+ # github.activity.starring.list { |star| ... }
14
14
  #
15
15
  def list(user_name, repo_name, params={})
16
16
  set :user => user_name, :repo => repo_name
@@ -27,13 +27,13 @@ module Github
27
27
  #
28
28
  # = Examples
29
29
  # github = Github.new
30
- # github.repos.starring.starred :user => 'user-name'
30
+ # github.activity.starring.starred :user => 'user-name'
31
31
  #
32
32
  # List repos being starred by the authenticated user
33
33
  #
34
34
  # = Examples
35
35
  # github = Github.new :oauth_token => '...'
36
- # github.repos.starring.starred
36
+ # github.activity.starring.starred
37
37
  #
38
38
  def starred(*args)
39
39
  params = args.extract_options!
@@ -54,7 +54,7 @@ module Github
54
54
  #
55
55
  # = Examples
56
56
  # github = Github.new
57
- # github.repos.starring.starring? 'user-name', 'repo-name'
57
+ # github.activity.starring.starring? 'user-name', 'repo-name'
58
58
  #
59
59
  def starring?(user_name, repo_name, params={})
60
60
  assert_presence_of user_name, repo_name
@@ -71,7 +71,7 @@ module Github
71
71
  #
72
72
  # = Examples
73
73
  # github = Github.new
74
- # github.repos.starring.star 'user-name', 'repo-name'
74
+ # github.activity.starring.star 'user-name', 'repo-name'
75
75
  #
76
76
  def star(user_name, repo_name, params={})
77
77
  set :user => user_name, :repo => repo_name
@@ -86,7 +86,7 @@ module Github
86
86
  #
87
87
  # = Examples
88
88
  # github = Github.new
89
- # github.repos.starring.unstar 'user-name', 'repo-name'
89
+ # github.activity.starring.unstar 'user-name', 'repo-name'
90
90
  #
91
91
  def unstar(user_name, repo_name, params={})
92
92
  set :user => user_name, :repo => repo_name
@@ -95,5 +95,5 @@ module Github
95
95
  delete_request("/user/starred/#{user_name}/#{repo_name}", params)
96
96
  end
97
97
 
98
- end # Repos::Starring
98
+ end # Activity::Starring
99
99
  end # Github
@@ -3,14 +3,14 @@
3
3
  module Github
4
4
  # Watching a Repository registers the user to receive notificactions on new
5
5
  # discussions, as well as events in the user’s activity feed.
6
- class Repos::Watching < API
6
+ class Activity::Watching < API
7
7
 
8
8
  # List repo watchers
9
9
  #
10
10
  # = Examples
11
11
  # github = Github.new :user => 'user-name', :repo => 'repo-name'
12
- # github.repos.watching.list
13
- # github.repos.watching.list { |watcher| ... }
12
+ # github.activity.watching.list
13
+ # github.activity.watching.list { |watcher| ... }
14
14
  #
15
15
  def list(user_name, repo_name, params={})
16
16
  set :user => user_name, :repo => repo_name
@@ -27,13 +27,13 @@ module Github
27
27
  #
28
28
  # = Examples
29
29
  # github = Github.new
30
- # github.repos.watching.watched :user => 'user-name'
30
+ # github.activity.watching.watched :user => 'user-name'
31
31
  #
32
32
  # List repos being watched by the authenticated user
33
33
  #
34
34
  # = Examples
35
35
  # github = Github.new :oauth_token => '...'
36
- # github.repos.watching.watched
36
+ # github.activity.watching.watched
37
37
  #
38
38
  def watched(*args)
39
39
  params = args.extract_options!
@@ -53,7 +53,7 @@ module Github
53
53
  # Returns <tt>true</tt> if this repo is watched by you, <tt>false</tt> otherwise
54
54
  # = Examples
55
55
  # github = Github.new
56
- # github.repos.watching.watching? 'user-name', 'repo-name'
56
+ # github.activity.watching.watching? 'user-name', 'repo-name'
57
57
  #
58
58
  def watching?(user_name, repo_name, params={})
59
59
  assert_presence_of user_name, repo_name
@@ -70,7 +70,7 @@ module Github
70
70
  #
71
71
  # = Examples
72
72
  # github = Github.new
73
- # github.repos.watching.watch 'user-name', 'repo-name'
73
+ # github.activity.watching.watch 'user-name', 'repo-name'
74
74
  #
75
75
  def watch(user_name, repo_name, params={})
76
76
  assert_presence_of user_name, repo_name
@@ -83,7 +83,7 @@ module Github
83
83
  # You need to be authenticated to stop watching a repository.
84
84
  # = Examples
85
85
  # github = Github.new
86
- # github.repos.watching.unwatch 'user-name', 'repo-name'
86
+ # github.activity.watching.unwatch 'user-name', 'repo-name'
87
87
  #
88
88
  def unwatch(user_name, repo_name, params={})
89
89
  assert_presence_of user_name, repo_name
@@ -91,5 +91,5 @@ module Github
91
91
  delete_request("/user/subscriptions/#{user_name}/#{repo_name}", params)
92
92
  end
93
93
 
94
- end # Repos::Watching
94
+ end # Activity::Watching
95
95
  end # Github
@@ -3,10 +3,11 @@
3
3
  module Github
4
4
  class Client < API
5
5
 
6
- # This is a read-only API to the GitHub events.
7
- # These events power the various activity streams on the site.
8
- def events(options = {})
9
- @events ||= ApiFactory.new 'Events', options
6
+ # Serving up the ‘social’ in Social Coding™, the Activity APIs
7
+ # provide access to notifications, subscriptions, and timelines.
8
+ #
9
+ def activity(options = {})
10
+ @activity ||= ApiFactory.new 'Activity', options
10
11
  end
11
12
 
12
13
  def emojis(options = {})
@@ -60,6 +61,7 @@ module Github
60
61
 
61
62
  # Many of the resources on the users API provide a shortcut for getting
62
63
  # information about the currently authenticated user.
64
+ #
63
65
  def users(options = {})
64
66
  @users ||= ApiFactory.new 'Users', options
65
67
  end
@@ -16,9 +16,7 @@ module Github
16
16
  :Keys => 'keys',
17
17
  :Merging => 'merging',
18
18
  :PubSubHubbub => 'pub_sub_hubbub',
19
- :Starring => 'starring',
20
- :Statuses => 'statuses',
21
- :Watching => 'watching'
19
+ :Statuses => 'statuses'
22
20
 
23
21
  DEFAULT_REPO_OPTIONS = {
24
22
  "homepage" => "https://github.com",
@@ -96,21 +94,11 @@ module Github
96
94
  @pubsubhubbub ||= ApiFactory.new 'Repos::PubSubHubbub'
97
95
  end
98
96
 
99
- # Access to Repos::Starring API
100
- def starring
101
- @starring ||= ApiFactory.new 'Repos::Starring'
102
- end
103
-
104
97
  # Access to Repos::Statuses API
105
98
  def statuses
106
99
  @statuses ||= ApiFactory.new 'Repos::Statuses'
107
100
  end
108
101
 
109
- # Access to Repos::Watching API
110
- def watching
111
- @watching ||= ApiFactory.new 'Repos::Watching'
112
- end
113
-
114
102
  # List branches
115
103
  #
116
104
  # = Examples
@@ -162,7 +150,7 @@ module Github
162
150
  #
163
151
  # = Examples
164
152
  # github = Github.new
165
- # github.repos.create "name" => 'repo-name'
153
+ # github.repos.create "name": 'repo-name'
166
154
  # "description": "This is your first repo",
167
155
  # "homepage": "https://github.com",
168
156
  # "private": false,
@@ -6,7 +6,6 @@ module Github
6
6
  # Contains methods and attributes that act on the response returned from the
7
7
  # request
8
8
  class Response < Faraday::Response::Middleware
9
-
10
9
  CONTENT_TYPE = 'Content-Type'.freeze
11
10
 
12
11
  class << self
@@ -3,8 +3,8 @@
3
3
  module Github
4
4
  module VERSION
5
5
  MAJOR = 0
6
- MINOR = 7
7
- PATCH = 2
6
+ MINOR = 8
7
+ PATCH = 0
8
8
  BUILD = nil
9
9
 
10
10
  STRING = [MAJOR, MINOR, PATCH, BUILD].compact.join('.');
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "repository": {
5
+ "id": 1296269,
6
+ "owner": {
7
+ "login": "octocat",
8
+ "id": 1,
9
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
10
+ "gravatar_id": "somehexcode",
11
+ "url": "https://api.github.com/users/octocat"
12
+ },
13
+ "name": "Hello-World",
14
+ "full_name": "octocat/Hello-World",
15
+ "description": "This your first repo!",
16
+ "private": false,
17
+ "fork": false,
18
+ "url": "https://api.github.com/repos/octocat/Hello-World",
19
+ "html_url": "https://github.com/octocat/Hello-World"
20
+ },
21
+ "subject": {
22
+ "title": "Greetings",
23
+ "url": "https://api.github.com/repos/pengwynn/octokit/issues/123",
24
+ "latest_comment_url": "https://api.github.com/repos/pengwynn/octokit/issues/comments/123"
25
+ },
26
+ "reason": "subscribed",
27
+ "unread": true,
28
+ "updated_at": "2012-09-25T07:54:41-07:00",
29
+ "last_read_at": "2012-09-25T07:54:41-07:00",
30
+ "url": "https://api.github.com/notifications/threads/1"
31
+ }
32
+ ]
@@ -0,0 +1,8 @@
1
+ {
2
+ "subscribed": true,
3
+ "ignored": false,
4
+ "reason": null,
5
+ "created_at": "2012-10-06T21:34:12Z",
6
+ "url": "https://api.github.com/notifications/threads/1/subscription",
7
+ "thread_url": "https://api.github.com/notifications/threads/1"
8
+ }
@@ -0,0 +1,32 @@
1
+ [
2
+ {
3
+ "id": 1,
4
+ "repository": {
5
+ "id": 1296269,
6
+ "owner": {
7
+ "login": "octocat",
8
+ "id": 1,
9
+ "avatar_url": "https://github.com/images/error/octocat_happy.gif",
10
+ "gravatar_id": "somehexcode",
11
+ "url": "https://api.github.com/users/octocat"
12
+ },
13
+ "name": "Hello-World",
14
+ "full_name": "octocat/Hello-World",
15
+ "description": "This your first repo!",
16
+ "private": false,
17
+ "fork": false,
18
+ "url": "https://api.github.com/repos/octocat/Hello-World",
19
+ "html_url": "https://github.com/octocat/Hello-World"
20
+ },
21
+ "subject": {
22
+ "title": "Greetings",
23
+ "url": "https://api.github.com/repos/pengwynn/octokit/issues/123",
24
+ "latest_comment_url": "https://api.github.com/repos/pengwynn/octokit/issues/comments/123"
25
+ },
26
+ "reason": "subscribed",
27
+ "unread": true,
28
+ "updated_at": "2012-09-25T07:54:41-07:00",
29
+ "last_read_at": "2012-09-25T07:54:41-07:00",
30
+ "url": "https://api.github.com/notifications/threads/1"
31
+ }
32
+ ]
@@ -0,0 +1,16 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity, 'integration' do
6
+
7
+ after { reset_authentication_for subject }
8
+
9
+ its(:events) { should be_a Github::Activity::Events }
10
+
11
+ its(:notifications) { should be_a Github::Activity::Notifications }
12
+
13
+ its(:starring) { should be_a Github::Activity::Starring }
14
+
15
+ its(:watching) { should be_a Github::Activity::Watching }
16
+ end
@@ -0,0 +1,63 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Events, '#issue' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/repos/#{user}/#{repo}/issues/events" }
9
+ let(:body) { fixture('events/events.json') }
10
+ let(:status) { 200 }
11
+
12
+ before {
13
+ stub_get(request_path).to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for subject }
18
+
19
+ context "resource found" do
20
+ it { should respond_to :issue_events }
21
+
22
+ it "should fail to get resource without username" do
23
+ expect { subject.issue nil, repo }.to raise_error(ArgumentError)
24
+ end
25
+
26
+ it "should get the resources" do
27
+ subject.issue user, repo
28
+ a_get(request_path).should have_been_made
29
+ end
30
+
31
+ it "should return array of resources" do
32
+ events = subject.issue user, repo
33
+ events.should be_an Array
34
+ events.should have(1).items
35
+ end
36
+
37
+ it "should be a mash type" do
38
+ events = subject.issue user, repo
39
+ events.first.should be_a Hashie::Mash
40
+ end
41
+
42
+ it "should get event information" do
43
+ events = subject.issue user, repo
44
+ events.first.type.should == 'Event'
45
+ end
46
+
47
+ it "should yield to a block" do
48
+ subject.should_receive(:issue).with(user, repo).and_yield('web')
49
+ subject.issue(user, repo) { |param| 'web' }
50
+ end
51
+ end
52
+
53
+ context "resource not found" do
54
+ let(:body) { '' }
55
+ let(:status) { [404, "Not Found"] }
56
+
57
+ it "should return 404 with a message 'Not Found'" do
58
+ expect {
59
+ subject.issue user, repo
60
+ }.to raise_error(Github::Error::NotFound)
61
+ end
62
+ end
63
+ end # issue
@@ -0,0 +1,61 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Events, '#network' do
6
+ let(:user) { 'peter-murach' }
7
+ let(:repo) { 'github' }
8
+ let(:request_path) { "/networks/#{user}/#{repo}/events" }
9
+ let(:body) { fixture('events/events.json') }
10
+ let(:status) { 200 }
11
+
12
+ before {
13
+ stub_get(request_path).to_return(:body => body, :status => status,
14
+ :headers => {:content_type => "application/json; charset=utf-8"})
15
+ }
16
+
17
+ after { reset_authentication_for subject }
18
+
19
+ context "resource found" do
20
+ it "should fail to get resource without username" do
21
+ expect { subject.network nil, repo }.to raise_error(ArgumentError)
22
+ end
23
+
24
+ it "should get the resources" do
25
+ subject.network user, repo
26
+ a_get(request_path).should have_been_made
27
+ end
28
+
29
+ it "should return array of resources" do
30
+ events = subject.network user, repo
31
+ events.should be_an Array
32
+ events.should have(1).items
33
+ end
34
+
35
+ it "should be a mash type" do
36
+ events = subject.network user, repo
37
+ events.first.should be_a Hashie::Mash
38
+ end
39
+
40
+ it "should get event information" do
41
+ events = subject.network user, repo
42
+ events.first.type.should == 'Event'
43
+ end
44
+
45
+ it "should yield to a block" do
46
+ subject.should_receive(:network).with(user, repo).and_yield('web')
47
+ subject.network(user, repo) { |param| 'web' }
48
+ end
49
+ end
50
+
51
+ context "resource not found" do
52
+ let(:body) { '' }
53
+ let(:status) { [404, "Not Found"] }
54
+
55
+ it "should return 404 with a message 'Not Found'" do
56
+ expect {
57
+ subject.network user, repo
58
+ }.to raise_error(Github::Error::NotFound)
59
+ end
60
+ end
61
+ end # network
@@ -0,0 +1,60 @@
1
+ # encoding: utf-8
2
+
3
+ require 'spec_helper'
4
+
5
+ describe Github::Activity::Events, '#org' do
6
+ let(:org) { 'github' }
7
+ let(:request_path) { "/orgs/#{org}/events" }
8
+ let(:body) { fixture('events/events.json') }
9
+ let(:status) { 200 }
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
+ it { should respond_to :organization }
20
+
21
+ it "should fail to get resource without orgname" do
22
+ expect { subject.org nil }.to raise_error(ArgumentError)
23
+ end
24
+
25
+ it "should get the resources" do
26
+ subject.org org
27
+ a_get(request_path).should have_been_made
28
+ end
29
+
30
+ it "should return array of resources" do
31
+ events = subject.org org
32
+ events.should be_an Array
33
+ events.should have(1).items
34
+ end
35
+
36
+ it "should be a mash type" do
37
+ events = subject.org org
38
+ events.first.should be_a Hashie::Mash
39
+ end
40
+
41
+ it "should get event information" do
42
+ events = subject.org org
43
+ events.first.type.should == 'Event'
44
+ end
45
+
46
+ it "should yield to a block" do
47
+ subject.should_receive(:org).with(org).and_yield('web')
48
+ subject.org(org) { |param| 'web' }
49
+ end
50
+ end
51
+
52
+ context "resource not found" do
53
+ let(:body) { '' }
54
+ let(:status) { [404, "Not Found"] }
55
+
56
+ it "should return 404 with a message 'Not Found'" do
57
+ expect { subject.org org }.to raise_error(Github::Error::NotFound)
58
+ end
59
+ end
60
+ end # org