github_api 0.3.1 → 0.3.2
Sign up to get free protection for your applications and to get access to all the features.
- data/README.rdoc +2 -1
- data/lib/github_api.rb +2 -1
- data/lib/github_api/client.rb +6 -0
- data/lib/github_api/events.rb +202 -0
- data/lib/github_api/gists.rb +1 -0
- data/lib/github_api/version.rb +1 -1
- data/spec/fixtures/events/events.json +29 -0
- data/spec/github/events_spec.rb +491 -0
- metadata +6 -3
data/README.rdoc
CHANGED
@@ -12,7 +12,7 @@ Grab the gem by issuing
|
|
12
12
|
|
13
13
|
or in your Gemfile
|
14
14
|
|
15
|
-
gem "github_api", "~> 0.3.
|
15
|
+
gem "github_api", "~> 0.3.2"
|
16
16
|
|
17
17
|
== Usage
|
18
18
|
|
@@ -67,6 +67,7 @@ Main API methods are grouped into the following classes that can be instantiated
|
|
67
67
|
Github::PullRequests
|
68
68
|
Github::Repos
|
69
69
|
Github::Users
|
70
|
+
Github::Events
|
70
71
|
Github::Authorizations
|
71
72
|
|
72
73
|
Some parts of GitHub API v3 require you to be autheticated, for instance the following are examples of APIs only for the authenticated user
|
data/lib/github_api.rb
CHANGED
@@ -23,7 +23,7 @@ module Github
|
|
23
23
|
end
|
24
24
|
|
25
25
|
def respond_to?(method, include_private = false)
|
26
|
-
new.respond_to?(method, include_private) || super(method, include_private)
|
26
|
+
new.respond_to?(method, include_private) || super(method, include_private)
|
27
27
|
end
|
28
28
|
end
|
29
29
|
|
@@ -51,6 +51,7 @@ module Github
|
|
51
51
|
:Orgs => 'orgs',
|
52
52
|
:PullRequests => 'pull_requests',
|
53
53
|
:Users => 'users',
|
54
|
+
:Events => 'events',
|
54
55
|
:CoreExt => 'core_ext',
|
55
56
|
:MimeType => 'mime_type',
|
56
57
|
:Authorization => 'authorization',
|
data/lib/github_api/client.rb
CHANGED
@@ -39,6 +39,12 @@ module Github
|
|
39
39
|
@users ||= _create_instance Github::Users, options
|
40
40
|
end
|
41
41
|
|
42
|
+
# This is a read-only API to the GitHub events.
|
43
|
+
# These events power the various activity streams on the site.
|
44
|
+
def events(options = {})
|
45
|
+
@events ||= _create_instance Github::Events, options
|
46
|
+
end
|
47
|
+
|
42
48
|
# An API for users to manage their own tokens. You can only access your own
|
43
49
|
# tokens, and only through Basic Authentication.
|
44
50
|
def oauth(options = {})
|
@@ -0,0 +1,202 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
module Github
|
4
|
+
class Events < API
|
5
|
+
|
6
|
+
# Creates new Gists API
|
7
|
+
def initialize(options = {})
|
8
|
+
super(options)
|
9
|
+
end
|
10
|
+
|
11
|
+
# List all public events
|
12
|
+
#
|
13
|
+
# = Examples
|
14
|
+
# @github = Github.new
|
15
|
+
# @github.events.public
|
16
|
+
# @github.events.public { |event| ... }
|
17
|
+
#
|
18
|
+
def public(params={})
|
19
|
+
_normalize_params_keys(params)
|
20
|
+
|
21
|
+
response = get("/events", params)
|
22
|
+
return response unless block_given?
|
23
|
+
response.each { |el| yield el }
|
24
|
+
end
|
25
|
+
alias :public_events :public
|
26
|
+
alias :list_public :public
|
27
|
+
alias :list_public_events :public
|
28
|
+
|
29
|
+
# List all repository events for a given user
|
30
|
+
#
|
31
|
+
# = Examples
|
32
|
+
# @github = Github.new
|
33
|
+
# @github.events.repository_events 'user-name', 'repo-name'
|
34
|
+
# @github.events.repository_events 'user-name', 'repo-name' { |event| ... }
|
35
|
+
#
|
36
|
+
def repository(user_name=nil, repo_name=nil, params={})
|
37
|
+
_update_user_repo_params(user_name, repo_name)
|
38
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
39
|
+
_normalize_params_keys(params)
|
40
|
+
|
41
|
+
response = get("/repos/#{user}/#{repo}/events", params)
|
42
|
+
return response unless block_given?
|
43
|
+
response.each { |el| yield el }
|
44
|
+
end
|
45
|
+
alias :repos :repository
|
46
|
+
alias :repo_events :repository
|
47
|
+
alias :repository_events :repository
|
48
|
+
alias :list_repository_events :repository
|
49
|
+
|
50
|
+
# List all issue events for a given repository
|
51
|
+
#
|
52
|
+
# = Examples
|
53
|
+
# @github = Github.new
|
54
|
+
# @github.events.issue 'user-name', 'repo-name'
|
55
|
+
# @github.events.issue 'user-name', 'repo-name' { |event| ... }
|
56
|
+
#
|
57
|
+
def issue(user_name=nil, repo_name=nil, params={})
|
58
|
+
_update_user_repo_params(user_name, repo_name)
|
59
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
60
|
+
_normalize_params_keys(params)
|
61
|
+
|
62
|
+
response = get("/repos/#{user}/#{repo}/issues/events", params)
|
63
|
+
return response unless block_given?
|
64
|
+
response.each { |el| yield el }
|
65
|
+
end
|
66
|
+
alias :issues :issue
|
67
|
+
alias :issue_events :issue
|
68
|
+
alias :list_issue_events :issue
|
69
|
+
|
70
|
+
# List all public events for a network of repositories
|
71
|
+
#
|
72
|
+
# = Examples
|
73
|
+
# @github = Github.new
|
74
|
+
# @github.events.network 'user-name', 'repo-name'
|
75
|
+
# @github.events.network 'user-name', 'repo-name' { |event| ... }
|
76
|
+
#
|
77
|
+
def network(user_name=nil, repo_name=nil, params={})
|
78
|
+
_update_user_repo_params(user_name, repo_name)
|
79
|
+
_validate_user_repo_params(user, repo) unless user? && repo?
|
80
|
+
_normalize_params_keys(params)
|
81
|
+
|
82
|
+
response = get("/networks/#{user}/#{repo}/events", params)
|
83
|
+
return response unless block_given?
|
84
|
+
response.each { |el| yield el }
|
85
|
+
end
|
86
|
+
alias :repo_network :network
|
87
|
+
alias :repository_network :network
|
88
|
+
alias :list_repo_network_events :network
|
89
|
+
alias :list_repository_network_events :network
|
90
|
+
|
91
|
+
# List all public events for an organization
|
92
|
+
#
|
93
|
+
# = Examples
|
94
|
+
# @github = Github.new
|
95
|
+
# @github.events.org 'org-name'
|
96
|
+
# @github.events.org 'org-name' { |event| ... }
|
97
|
+
#
|
98
|
+
def org(org_name, params={})
|
99
|
+
_validate_presence_of org_name
|
100
|
+
_normalize_params_keys(params)
|
101
|
+
|
102
|
+
response = get("/orgs/#{org_name}/events", params)
|
103
|
+
return response unless block_given?
|
104
|
+
response.each { |el| yield el }
|
105
|
+
end
|
106
|
+
alias :organization :org
|
107
|
+
alias :list_orgs :org
|
108
|
+
alias :list_org_events :org
|
109
|
+
alias :list_organization_events :org
|
110
|
+
|
111
|
+
# List all events that a user has received
|
112
|
+
#
|
113
|
+
# These are events that you’ve received by watching repos and following users.
|
114
|
+
# If you are authenticated as the given user, you will see private events.
|
115
|
+
# Otherwise, you’ll only see public events.
|
116
|
+
#
|
117
|
+
# = Examples
|
118
|
+
# @github = Github.new
|
119
|
+
# @github.events.received 'user-name'
|
120
|
+
# @github.events.received 'user-name' { |event| ... }
|
121
|
+
#
|
122
|
+
# List all public events that a user has received
|
123
|
+
#
|
124
|
+
# = Examples
|
125
|
+
# @github = Github.new
|
126
|
+
# @github.events.received 'user-name', :public => true
|
127
|
+
# @github.events.received 'user-name', :public => true { |event| ... }
|
128
|
+
#
|
129
|
+
def received(user_name, params={})
|
130
|
+
_validate_presence_of user_name
|
131
|
+
_normalize_params_keys(params)
|
132
|
+
|
133
|
+
public_events = if params['public']
|
134
|
+
params.delete('public')
|
135
|
+
'/public'
|
136
|
+
end
|
137
|
+
|
138
|
+
response = get("/users/#{user_name}/received_events#{public_events}", params)
|
139
|
+
return response unless block_given?
|
140
|
+
response.each { |el| yield el }
|
141
|
+
end
|
142
|
+
alias :user_received :received
|
143
|
+
alias :list_user_received :received
|
144
|
+
|
145
|
+
# List all events that a user has performed
|
146
|
+
#
|
147
|
+
# If you are authenticated as the given user, you will see your private
|
148
|
+
# events. Otherwise, you’ll only see public events.
|
149
|
+
#
|
150
|
+
# = Examples
|
151
|
+
# @github = Github.new
|
152
|
+
# @github.events.performed 'user-name'
|
153
|
+
# @github.events.performed 'user-name' { |event| ... }
|
154
|
+
#
|
155
|
+
# List all public events that a user has performed
|
156
|
+
#
|
157
|
+
# = Examples
|
158
|
+
# @github = Github.new
|
159
|
+
# @github.events.performed 'user-name', :public => true
|
160
|
+
# @github.events.performed 'user-name', :public => true { |event| ... }
|
161
|
+
#
|
162
|
+
def performed(user_name, params={})
|
163
|
+
_validate_presence_of user_name
|
164
|
+
_normalize_params_keys(params)
|
165
|
+
|
166
|
+
public_events = if params['public']
|
167
|
+
params.delete('public')
|
168
|
+
'/public'
|
169
|
+
end
|
170
|
+
|
171
|
+
response = get("/users/#{user_name}/events#{public_events}", params)
|
172
|
+
return response unless block_given?
|
173
|
+
response.each { |el| yield el }
|
174
|
+
end
|
175
|
+
alias :user_performed :performed
|
176
|
+
alias :list_user_performed :performed
|
177
|
+
|
178
|
+
# List all events for an organization
|
179
|
+
#
|
180
|
+
# This is the user’s organization dashboard. You must be authenticated
|
181
|
+
# as the user to view this.
|
182
|
+
#
|
183
|
+
# = Examples
|
184
|
+
# @github = Github.new
|
185
|
+
# @github.events.user_org 'user-name', 'org-name'
|
186
|
+
# @github.events.user_org 'user-name', 'org-name' { |event| ... }
|
187
|
+
#
|
188
|
+
def user_org(user_name, org_name, params={})
|
189
|
+
_validate_presence_of user_name, org_name
|
190
|
+
_normalize_params_keys(params)
|
191
|
+
|
192
|
+
response = get("/users/#{user_name}/events/orgs/#{org_name}", params)
|
193
|
+
return response unless block_given?
|
194
|
+
response.each { |el| yield el }
|
195
|
+
end
|
196
|
+
alias :user_organization :user_org
|
197
|
+
alias :list_user_org :user_org
|
198
|
+
alias :list_user_org_events :user_org
|
199
|
+
alias :list_user_organization_events :user_org
|
200
|
+
|
201
|
+
end # Events
|
202
|
+
end # Github
|
data/lib/github_api/gists.rb
CHANGED
data/lib/github_api/version.rb
CHANGED
@@ -0,0 +1,29 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"type": "Event",
|
4
|
+
"public": true,
|
5
|
+
"payload": {
|
6
|
+
|
7
|
+
},
|
8
|
+
"repo": {
|
9
|
+
"id": 3,
|
10
|
+
"name": "octocat/Hello-World",
|
11
|
+
"url": "https://api.github.com/repos/octocat/Hello-World"
|
12
|
+
},
|
13
|
+
"actor": {
|
14
|
+
"login": "octocat",
|
15
|
+
"id": 1,
|
16
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
17
|
+
"gravatar_id": "somehexcode",
|
18
|
+
"url": "https://api.github.com/users/octocat"
|
19
|
+
},
|
20
|
+
"org": {
|
21
|
+
"login": "octocat",
|
22
|
+
"id": 1,
|
23
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
24
|
+
"gravatar_id": "somehexcode",
|
25
|
+
"url": "https://api.github.com/users/octocat"
|
26
|
+
},
|
27
|
+
"created_at": "2011-09-06T17:26:27Z"
|
28
|
+
}
|
29
|
+
]
|
@@ -0,0 +1,491 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Github::Events do
|
4
|
+
|
5
|
+
let(:github) { Github.new }
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
|
9
|
+
describe "public" do
|
10
|
+
context "resource found" do
|
11
|
+
before do
|
12
|
+
stub_get("/events").
|
13
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
14
|
+
end
|
15
|
+
|
16
|
+
it "should get the resources" do
|
17
|
+
github.events.public
|
18
|
+
a_get("/events").should have_been_made
|
19
|
+
end
|
20
|
+
|
21
|
+
it "should return array of resources" do
|
22
|
+
events = github.events.public
|
23
|
+
events.should be_an Array
|
24
|
+
events.should have(1).items
|
25
|
+
end
|
26
|
+
|
27
|
+
it "should be a mash type" do
|
28
|
+
events = github.events.public
|
29
|
+
events.first.should be_a Hashie::Mash
|
30
|
+
end
|
31
|
+
|
32
|
+
it "should get event information" do
|
33
|
+
events = github.events.public
|
34
|
+
events.first.type.should == 'Event'
|
35
|
+
end
|
36
|
+
|
37
|
+
it "should yield to a block" do
|
38
|
+
github.events.should_receive(:public).and_yield('web')
|
39
|
+
github.events.public { |param| 'web' }
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
context "resource not found" do
|
44
|
+
before do
|
45
|
+
stub_get("/events").to_return(:body => "", :status => [404, "Not Found"])
|
46
|
+
end
|
47
|
+
|
48
|
+
it "should return 404 with a message 'Not Found'" do
|
49
|
+
expect {
|
50
|
+
github.events.public
|
51
|
+
}.to raise_error(Github::ResourceNotFound)
|
52
|
+
end
|
53
|
+
end
|
54
|
+
end # public_events
|
55
|
+
|
56
|
+
describe "repository" do
|
57
|
+
context "resource found" do
|
58
|
+
before do
|
59
|
+
stub_get("/repos/#{user}/#{repo}/events").
|
60
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
61
|
+
end
|
62
|
+
|
63
|
+
it "should fail to get resource without username" do
|
64
|
+
github.user, github.repo = nil, nil
|
65
|
+
expect { github.events.repository nil, repo }.to raise_error(ArgumentError)
|
66
|
+
end
|
67
|
+
|
68
|
+
it "should get the resources" do
|
69
|
+
github.events.repository user, repo
|
70
|
+
a_get("/repos/#{user}/#{repo}/events").should have_been_made
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should return array of resources" do
|
74
|
+
events = github.events.repository user, repo
|
75
|
+
events.should be_an Array
|
76
|
+
events.should have(1).items
|
77
|
+
end
|
78
|
+
|
79
|
+
it "should be a mash type" do
|
80
|
+
events = github.events.repository user, repo
|
81
|
+
events.first.should be_a Hashie::Mash
|
82
|
+
end
|
83
|
+
|
84
|
+
it "should get event information" do
|
85
|
+
events = github.events.repository user, repo
|
86
|
+
events.first.type.should == 'Event'
|
87
|
+
end
|
88
|
+
|
89
|
+
it "should yield to a block" do
|
90
|
+
github.events.should_receive(:repository).with(user, repo).and_yield('web')
|
91
|
+
github.events.repository(user, repo) { |param| 'web' }
|
92
|
+
end
|
93
|
+
end
|
94
|
+
|
95
|
+
context "resource not found" do
|
96
|
+
before do
|
97
|
+
stub_get("/repos/#{user}/#{repo}/events").
|
98
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
99
|
+
end
|
100
|
+
|
101
|
+
it "should return 404 with a message 'Not Found'" do
|
102
|
+
expect {
|
103
|
+
github.events.repository user, repo
|
104
|
+
}.to raise_error(Github::ResourceNotFound)
|
105
|
+
end
|
106
|
+
end
|
107
|
+
end # repository
|
108
|
+
|
109
|
+
describe "issue" do
|
110
|
+
context "resource found" do
|
111
|
+
before do
|
112
|
+
stub_get("/repos/#{user}/#{repo}/issues/events").
|
113
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
114
|
+
end
|
115
|
+
|
116
|
+
it "should fail to get resource without username" do
|
117
|
+
github.user, github.repo = nil, nil
|
118
|
+
expect { github.events.issue nil, repo }.to raise_error(ArgumentError)
|
119
|
+
end
|
120
|
+
|
121
|
+
it "should get the resources" do
|
122
|
+
github.events.issue user, repo
|
123
|
+
a_get("/repos/#{user}/#{repo}/issues/events").should have_been_made
|
124
|
+
end
|
125
|
+
|
126
|
+
it "should return array of resources" do
|
127
|
+
events = github.events.issue user, repo
|
128
|
+
events.should be_an Array
|
129
|
+
events.should have(1).items
|
130
|
+
end
|
131
|
+
|
132
|
+
it "should be a mash type" do
|
133
|
+
events = github.events.issue user, repo
|
134
|
+
events.first.should be_a Hashie::Mash
|
135
|
+
end
|
136
|
+
|
137
|
+
it "should get event information" do
|
138
|
+
events = github.events.issue user, repo
|
139
|
+
events.first.type.should == 'Event'
|
140
|
+
end
|
141
|
+
|
142
|
+
it "should yield to a block" do
|
143
|
+
github.events.should_receive(:issue).with(user, repo).and_yield('web')
|
144
|
+
github.events.issue(user, repo) { |param| 'web' }
|
145
|
+
end
|
146
|
+
end
|
147
|
+
|
148
|
+
context "resource not found" do
|
149
|
+
before do
|
150
|
+
stub_get("/repos/#{user}/#{repo}/issues/events").
|
151
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
152
|
+
end
|
153
|
+
|
154
|
+
it "should return 404 with a message 'Not Found'" do
|
155
|
+
expect {
|
156
|
+
github.events.issue user, repo
|
157
|
+
}.to raise_error(Github::ResourceNotFound)
|
158
|
+
end
|
159
|
+
end
|
160
|
+
end # repository
|
161
|
+
|
162
|
+
describe "network" do
|
163
|
+
context "resource found" do
|
164
|
+
before do
|
165
|
+
stub_get("/networks/#{user}/#{repo}/events").
|
166
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
167
|
+
end
|
168
|
+
|
169
|
+
it "should fail to get resource without username" do
|
170
|
+
github.user, github.repo = nil, nil
|
171
|
+
expect { github.events.network nil, repo }.to raise_error(ArgumentError)
|
172
|
+
end
|
173
|
+
|
174
|
+
it "should get the resources" do
|
175
|
+
github.events.network user, repo
|
176
|
+
a_get("/networks/#{user}/#{repo}/events").should have_been_made
|
177
|
+
end
|
178
|
+
|
179
|
+
it "should return array of resources" do
|
180
|
+
events = github.events.network user, repo
|
181
|
+
events.should be_an Array
|
182
|
+
events.should have(1).items
|
183
|
+
end
|
184
|
+
|
185
|
+
it "should be a mash type" do
|
186
|
+
events = github.events.network user, repo
|
187
|
+
events.first.should be_a Hashie::Mash
|
188
|
+
end
|
189
|
+
|
190
|
+
it "should get event information" do
|
191
|
+
events = github.events.network user, repo
|
192
|
+
events.first.type.should == 'Event'
|
193
|
+
end
|
194
|
+
|
195
|
+
it "should yield to a block" do
|
196
|
+
github.events.should_receive(:network).with(user, repo).and_yield('web')
|
197
|
+
github.events.network(user, repo) { |param| 'web' }
|
198
|
+
end
|
199
|
+
end
|
200
|
+
|
201
|
+
context "resource not found" do
|
202
|
+
before do
|
203
|
+
stub_get("/networks/#{user}/#{repo}/events").
|
204
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
205
|
+
end
|
206
|
+
|
207
|
+
it "should return 404 with a message 'Not Found'" do
|
208
|
+
expect {
|
209
|
+
github.events.network user, repo
|
210
|
+
}.to raise_error(Github::ResourceNotFound)
|
211
|
+
end
|
212
|
+
end
|
213
|
+
end # network
|
214
|
+
|
215
|
+
describe "org" do
|
216
|
+
let(:org) { 'github' }
|
217
|
+
context "resource found" do
|
218
|
+
before do
|
219
|
+
stub_get("/orgs/#{org}/events").
|
220
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
221
|
+
end
|
222
|
+
|
223
|
+
it "should fail to get resource without orgname" do
|
224
|
+
expect { github.events.org nil }.to raise_error(ArgumentError)
|
225
|
+
end
|
226
|
+
|
227
|
+
it "should get the resources" do
|
228
|
+
github.events.org org
|
229
|
+
a_get("/orgs/#{org}/events").should have_been_made
|
230
|
+
end
|
231
|
+
|
232
|
+
it "should return array of resources" do
|
233
|
+
events = github.events.org org
|
234
|
+
events.should be_an Array
|
235
|
+
events.should have(1).items
|
236
|
+
end
|
237
|
+
|
238
|
+
it "should be a mash type" do
|
239
|
+
events = github.events.org org
|
240
|
+
events.first.should be_a Hashie::Mash
|
241
|
+
end
|
242
|
+
|
243
|
+
it "should get event information" do
|
244
|
+
events = github.events.org org
|
245
|
+
events.first.type.should == 'Event'
|
246
|
+
end
|
247
|
+
|
248
|
+
it "should yield to a block" do
|
249
|
+
github.events.should_receive(:org).with(org).and_yield('web')
|
250
|
+
github.events.org(org) { |param| 'web' }
|
251
|
+
end
|
252
|
+
end
|
253
|
+
|
254
|
+
context "resource not found" do
|
255
|
+
before do
|
256
|
+
stub_get("/orgs/#{org}/events").
|
257
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
258
|
+
end
|
259
|
+
|
260
|
+
it "should return 404 with a message 'Not Found'" do
|
261
|
+
expect {
|
262
|
+
github.events.org org
|
263
|
+
}.to raise_error(Github::ResourceNotFound)
|
264
|
+
end
|
265
|
+
end
|
266
|
+
end # org
|
267
|
+
|
268
|
+
describe "received" do
|
269
|
+
context "resource found" do
|
270
|
+
before do
|
271
|
+
stub_get("/users/#{user}/received_events").
|
272
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
273
|
+
end
|
274
|
+
|
275
|
+
it "should fail to get resource without username" do
|
276
|
+
expect { github.events.received nil }.to raise_error(ArgumentError)
|
277
|
+
end
|
278
|
+
|
279
|
+
it "should get the resources" do
|
280
|
+
github.events.received user
|
281
|
+
a_get("/users/#{user}/received_events").should have_been_made
|
282
|
+
end
|
283
|
+
|
284
|
+
it "should return array of resources" do
|
285
|
+
events = github.events.received user
|
286
|
+
events.should be_an Array
|
287
|
+
events.should have(1).items
|
288
|
+
end
|
289
|
+
|
290
|
+
it "should be a mash type" do
|
291
|
+
events = github.events.received user
|
292
|
+
events.first.should be_a Hashie::Mash
|
293
|
+
end
|
294
|
+
|
295
|
+
it "should get event information" do
|
296
|
+
events = github.events.received user
|
297
|
+
events.first.type.should == 'Event'
|
298
|
+
end
|
299
|
+
|
300
|
+
it "should yield to a block" do
|
301
|
+
github.events.should_receive(:received).with(user).and_yield('web')
|
302
|
+
github.events.received(user) { |param| 'web' }
|
303
|
+
end
|
304
|
+
end
|
305
|
+
|
306
|
+
context "all public resources found" do
|
307
|
+
before do
|
308
|
+
stub_get("/users/#{user}/received_events/public").
|
309
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
310
|
+
end
|
311
|
+
|
312
|
+
it "should get the resources" do
|
313
|
+
github.events.received user, :public => true
|
314
|
+
a_get("/users/#{user}/received_events/public").should have_been_made
|
315
|
+
end
|
316
|
+
|
317
|
+
it "should return array of resources" do
|
318
|
+
events = github.events.received user, :public => true
|
319
|
+
events.should be_an Array
|
320
|
+
events.should have(1).items
|
321
|
+
end
|
322
|
+
|
323
|
+
it "should be a mash type" do
|
324
|
+
events = github.events.received user, :public => true
|
325
|
+
events.first.should be_a Hashie::Mash
|
326
|
+
end
|
327
|
+
|
328
|
+
it "should get event information" do
|
329
|
+
events = github.events.received user, :public => true
|
330
|
+
events.first.type.should == 'Event'
|
331
|
+
end
|
332
|
+
|
333
|
+
it "should yield to a block" do
|
334
|
+
github.events.should_receive(:received).with(user).and_yield('web')
|
335
|
+
github.events.received(user) { |param| 'web' }
|
336
|
+
end
|
337
|
+
end
|
338
|
+
|
339
|
+
context "resource not found" do
|
340
|
+
before do
|
341
|
+
stub_get("/users/#{user}/received_events").
|
342
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
343
|
+
end
|
344
|
+
|
345
|
+
it "should return 404 with a message 'Not Found'" do
|
346
|
+
expect {
|
347
|
+
github.events.received user
|
348
|
+
}.to raise_error(Github::ResourceNotFound)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
end # received
|
352
|
+
|
353
|
+
describe "performed" do
|
354
|
+
context "resource found" do
|
355
|
+
before do
|
356
|
+
stub_get("/users/#{user}/events").
|
357
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
358
|
+
end
|
359
|
+
|
360
|
+
it "should fail to get resource without username" do
|
361
|
+
expect { github.events.performed nil }.to raise_error(ArgumentError)
|
362
|
+
end
|
363
|
+
|
364
|
+
it "should get the resources" do
|
365
|
+
github.events.performed user
|
366
|
+
a_get("/users/#{user}/events").should have_been_made
|
367
|
+
end
|
368
|
+
|
369
|
+
it "should return array of resources" do
|
370
|
+
events = github.events.performed user
|
371
|
+
events.should be_an Array
|
372
|
+
events.should have(1).items
|
373
|
+
end
|
374
|
+
|
375
|
+
it "should be a mash type" do
|
376
|
+
events = github.events.performed user
|
377
|
+
events.first.should be_a Hashie::Mash
|
378
|
+
end
|
379
|
+
|
380
|
+
it "should get event information" do
|
381
|
+
events = github.events.performed user
|
382
|
+
events.first.type.should == 'Event'
|
383
|
+
end
|
384
|
+
|
385
|
+
it "should yield to a block" do
|
386
|
+
github.events.should_receive(:performed).with(user).and_yield('web')
|
387
|
+
github.events.performed(user) { |param| 'web' }
|
388
|
+
end
|
389
|
+
end
|
390
|
+
|
391
|
+
context "all public resources found" do
|
392
|
+
before do
|
393
|
+
stub_get("/users/#{user}/events/public").
|
394
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
395
|
+
end
|
396
|
+
|
397
|
+
it "should get the resources" do
|
398
|
+
github.events.performed user, :public => true
|
399
|
+
a_get("/users/#{user}/events/public").should have_been_made
|
400
|
+
end
|
401
|
+
|
402
|
+
it "should return array of resources" do
|
403
|
+
events = github.events.performed user, :public => true
|
404
|
+
events.should be_an Array
|
405
|
+
events.should have(1).items
|
406
|
+
end
|
407
|
+
|
408
|
+
it "should be a mash type" do
|
409
|
+
events = github.events.performed user, :public => true
|
410
|
+
events.first.should be_a Hashie::Mash
|
411
|
+
end
|
412
|
+
|
413
|
+
it "should get event information" do
|
414
|
+
events = github.events.performed user, :public => true
|
415
|
+
events.first.type.should == 'Event'
|
416
|
+
end
|
417
|
+
|
418
|
+
it "should yield to a block" do
|
419
|
+
github.events.should_receive(:performed).with(user).and_yield('web')
|
420
|
+
github.events.performed(user) { |param| 'web' }
|
421
|
+
end
|
422
|
+
end
|
423
|
+
|
424
|
+
context "resource not found" do
|
425
|
+
before do
|
426
|
+
stub_get("/users/#{user}/events").
|
427
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
428
|
+
end
|
429
|
+
|
430
|
+
it "should return 404 with a message 'Not Found'" do
|
431
|
+
expect {
|
432
|
+
github.events.performed user
|
433
|
+
}.to raise_error(Github::ResourceNotFound)
|
434
|
+
end
|
435
|
+
end
|
436
|
+
end # performed
|
437
|
+
|
438
|
+
describe "user_org" do
|
439
|
+
let(:org) { 'github' }
|
440
|
+
context "resource found" do
|
441
|
+
before do
|
442
|
+
stub_get("/users/#{user}/events/orgs/#{org}").
|
443
|
+
to_return(:body => fixture('events/events.json'), :status => 200, :headers => {:content_type => "application/json; charset=utf-8"})
|
444
|
+
end
|
445
|
+
|
446
|
+
it "should fail to get resource without orgname" do
|
447
|
+
expect { github.events.user_org user, nil }.to raise_error(ArgumentError)
|
448
|
+
end
|
449
|
+
|
450
|
+
it "should get the resources" do
|
451
|
+
github.events.user_org user, org
|
452
|
+
a_get("/users/#{user}/events/orgs/#{org}").should have_been_made
|
453
|
+
end
|
454
|
+
|
455
|
+
it "should return array of resources" do
|
456
|
+
events = github.events.user_org user, org
|
457
|
+
events.should be_an Array
|
458
|
+
events.should have(1).items
|
459
|
+
end
|
460
|
+
|
461
|
+
it "should be a mash type" do
|
462
|
+
events = github.events.user_org user, org
|
463
|
+
events.first.should be_a Hashie::Mash
|
464
|
+
end
|
465
|
+
|
466
|
+
it "should get event information" do
|
467
|
+
events = github.events.user_org user, org
|
468
|
+
events.first.type.should == 'Event'
|
469
|
+
end
|
470
|
+
|
471
|
+
it "should yield to a block" do
|
472
|
+
github.events.should_receive(:user_org).with(user, org).and_yield('web')
|
473
|
+
github.events.user_org(user, org) { |param| 'web' }
|
474
|
+
end
|
475
|
+
end
|
476
|
+
|
477
|
+
context "resource not found" do
|
478
|
+
before do
|
479
|
+
stub_get("/users/#{user}/events/orgs/#{org}").
|
480
|
+
to_return(:body => "", :status => [404, "Not Found"])
|
481
|
+
end
|
482
|
+
|
483
|
+
it "should return 404 with a message 'Not Found'" do
|
484
|
+
expect {
|
485
|
+
github.events.user_org user, org
|
486
|
+
}.to raise_error(Github::ResourceNotFound)
|
487
|
+
end
|
488
|
+
end
|
489
|
+
end # user_org
|
490
|
+
|
491
|
+
end # Github::Events
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 3
|
8
|
-
-
|
9
|
-
version: 0.3.
|
8
|
+
- 2
|
9
|
+
version: 0.3.2
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Piotr Murach
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-
|
17
|
+
date: 2011-12-03 00:00:00 +00:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -205,6 +205,7 @@ files:
|
|
205
205
|
- lib/github_api/core_ext/array.rb
|
206
206
|
- lib/github_api/core_ext/hash.rb
|
207
207
|
- lib/github_api/error.rb
|
208
|
+
- lib/github_api/events.rb
|
208
209
|
- lib/github_api/gists/comments.rb
|
209
210
|
- lib/github_api/gists.rb
|
210
211
|
- lib/github_api/git_data/blobs.rb
|
@@ -249,6 +250,7 @@ files:
|
|
249
250
|
- lib/github_api.rb
|
250
251
|
- spec/fixtures/auths/authorization.json
|
251
252
|
- spec/fixtures/auths/authorizations.json
|
253
|
+
- spec/fixtures/events/events.json
|
252
254
|
- spec/fixtures/orgs/members.json
|
253
255
|
- spec/fixtures/orgs/org.json
|
254
256
|
- spec/fixtures/orgs/orgs.json
|
@@ -284,6 +286,7 @@ files:
|
|
284
286
|
- spec/github/authorizations_spec.rb
|
285
287
|
- spec/github/client_spec.rb
|
286
288
|
- spec/github/core_ext/hash_spec.rb
|
289
|
+
- spec/github/events_spec.rb
|
287
290
|
- spec/github/gists/comments_spec.rb
|
288
291
|
- spec/github/gists_spec.rb
|
289
292
|
- spec/github/git_data/blobs_spec.rb
|