Skip to content

Commit 796eb3f

Browse files
committed
Merge pull request piotrmurach#257 from MaximAbramchuck/add-activity-feeds-api
Add Client::Activity::Feeds
2 parents 0859a68 + 4a1b2f8 commit 796eb3f

5 files changed

Lines changed: 151 additions & 0 deletions

File tree

.travis.yml

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,14 @@ rvm:
77
- 2.1
88
- 2.2
99
- ruby-head
10+
before_install:
11+
- gem update --system
12+
- gem install bundler
13+
install: bundle install
14+
script: bundle exec rake build
15+
env:
16+
global:
17+
secure: 0dc92adb26454f7a8fcf0639f9f85150fd82b08cabfe8a66e0c5dc85a9cdddbc83b38468f863048af3e7dec3dd3e354e0a50c1b327a1a9f556357897e13e8bc6
1018
matrix:
1119
include:
1220
- rvm: jruby-19mode

lib/github_api/client/activity.rb

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ class Client::Activity < API
66
require_all 'github_api/client/activity',
77
'events',
88
'notifications',
9+
'feeds',
910
'starring',
1011
'watching'
1112

@@ -15,6 +16,9 @@ class Client::Activity < API
1516
# Access to Activity::Notifications API
1617
namespace :notifications
1718

19+
# Access to Activity::Feeds API
20+
namespace :feeds
21+
1822
# Access to Activity::Starring API
1923
namespace :starring
2024

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
# encoding: utf-8
2+
3+
module Github
4+
class Client::Activity::Feeds < API
5+
6+
# List all the feeds available to the authenticated user.
7+
#
8+
# @see https://developer.github.com/v3/activity/feeds/#list-feeds
9+
#
10+
# @example
11+
# github = Github.new
12+
# github.activity.feeds.list
13+
#
14+
# @api public
15+
def list(*args)
16+
arguments(args)
17+
18+
response = get_request("/feeds", arguments.params)
19+
return response unless block_given?
20+
response.each { |el| yield el }
21+
end
22+
alias :all :list
23+
end
24+
end # Github

spec/fixtures/activity/feeds.json

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,43 @@
1+
{
2+
"timeline_url": "https://github.com/timeline",
3+
"user_url": "https://github.com/{user}",
4+
"current_user_public_url": "https://github.com/defunkt",
5+
"current_user_url": "https://github.com/defunkt.private?token=abc123",
6+
"current_user_actor_url": "https://github.com/defunkt.private.actor?token=abc123",
7+
"current_user_organization_url": "",
8+
"current_user_organization_urls": [
9+
"https://github.com/organizations/github/defunkt.private.atom?token=abc123"
10+
],
11+
"_links": {
12+
"timeline": {
13+
"href": "https://github.com/timeline",
14+
"type": "application/atom+xml"
15+
},
16+
"user": {
17+
"href": "https://github.com/{user}",
18+
"type": "application/atom+xml"
19+
},
20+
"current_user_public": {
21+
"href": "https://github.com/defunkt",
22+
"type": "application/atom+xml"
23+
},
24+
"current_user": {
25+
"href": "https://github.com/defunkt.private?token=abc123",
26+
"type": "application/atom+xml"
27+
},
28+
"current_user_actor": {
29+
"href": "https://github.com/defunkt.private.actor?token=abc123",
30+
"type": "application/atom+xml"
31+
},
32+
"current_user_organization": {
33+
"href": "",
34+
"type": ""
35+
},
36+
"current_user_organizations": [
37+
{
38+
"href": "https://github.com/organizations/github/defunkt.private.atom?token=abc123",
39+
"type": "application/atom+xml"
40+
}
41+
]
42+
}
43+
}
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
# encoding: utf-8
2+
3+
require 'spec_helper'
4+
5+
describe Github::Client::Activity::Feeds, '#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) { "/feeds" }
15+
let(:body) { fixture('activity/feeds.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 'should get the resource' do
27+
subject.list
28+
a_get(request_path).with(:query => {:access_token => OAUTH_TOKEN}).
29+
should have_been_made
30+
end
31+
32+
it "should get timeline url" do
33+
feeds = subject.list
34+
feeds.timeline_url.should == 'https://github.com/timeline'
35+
end
36+
37+
it "should get user url" do
38+
feeds = subject.list
39+
feeds.user_url.should == 'https://github.com/{user}'
40+
end
41+
42+
it "should get current user public url" do
43+
feeds = subject.list
44+
feeds.current_user_public_url.should == 'https://github.com/defunkt'
45+
end
46+
47+
it "should get current user url" do
48+
feeds = subject.list
49+
feeds.current_user_url.should == 'https://github.com/defunkt.private?token=abc123'
50+
end
51+
52+
it "should get current user actor url" do
53+
feeds = subject.list
54+
feeds.current_user_actor_url.should == 'https://github.com/defunkt.private.actor?token=abc123'
55+
end
56+
57+
it "should get current user organization url" do
58+
feeds = subject.list
59+
feeds.current_user_organization_url.should == ''
60+
end
61+
62+
it "should get current user public url" do
63+
feeds = subject.list
64+
feeds.current_user_organization_urls.first.should == 'https://github.com/organizations/github/defunkt.private.atom?token=abc123'
65+
end
66+
67+
it_should_behave_like 'request failure' do
68+
let(:requestable) { subject.list }
69+
end
70+
end
71+
72+
end

0 commit comments

Comments
 (0)