Skip to content

Commit 9dd5d50

Browse files
committed
Add notifications api single thread retrieval.
1 parent eb3df09 commit 9dd5d50

3 files changed

Lines changed: 106 additions & 0 deletions

File tree

lib/github_api/activity/notifications.rb

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,5 +48,21 @@ def list(*args)
4848
end
4949
alias :all :list
5050

51+
# View a single thread
52+
#
53+
# = Examples
54+
# github = Github.new oauth_token: 'token'
55+
# github.activity.notifications.get 'thread_id'
56+
# github.activity.notifications.get 'thread_id' { |thread| ... }
57+
#
58+
def get(thread_id, params={})
59+
assert_presence_of thread_id
60+
normalize! params
61+
response = get_request("/notifications/threads/#{thread_id}", params)
62+
return response unless block_given?
63+
response.each { |el| yield el }
64+
end
65+
alias :find :get
66+
5167
end # Activity::Notifications
5268
end # Github
Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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+
]
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -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 commit comments

Comments
 (0)