github-v3-api 0.4.1 → 0.5.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.
- checksums.yaml +4 -4
- data/lib/github_v3_api.rb +15 -14
- data/lib/github_v3_api/repos_api.rb +7 -0
- data/lib/github_v3_api/users_api.rb +7 -1
- data/lib/github_v3_api/version.rb +1 -1
- data/spec/github_v3_api_spec.rb +28 -23
- data/spec/issue_spec.rb +1 -1
- data/spec/issues_api_spec.rb +8 -8
- data/spec/org_spec.rb +6 -6
- data/spec/orgs_api_spec.rb +5 -5
- data/spec/repo_spec.rb +7 -7
- data/spec/repos_api_spec.rb +6 -6
- data/spec/user_api_spec.rb +2 -2
- data/spec/user_spec.rb +3 -3
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ac5a14f8e48660b650280828fb50755370ed06ed
|
4
|
+
data.tar.gz: 2c36d07918f201c1af217d18960efd286a1d0237
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 790bb64597d4826870654f48a57246cb001be5040b8426a3c41cc2d6d7324fb45de09e55b8f3fc397b37797f9c3fb9ebb65fe93de15913c45a0e1f3043bf2b86
|
7
|
+
data.tar.gz: d1916ed66542c9029348558d6bdd232561368033f33a40f86a9c9a8b8387c3b432d8f2a6ecdb6f395a010ed550447f1f2157ed8c0fc2231af25a38b14e743a03
|
data/lib/github_v3_api.rb
CHANGED
@@ -34,8 +34,13 @@ class GitHubV3API
|
|
34
34
|
# +access_token+ owner's authorization.
|
35
35
|
#
|
36
36
|
# +access_token+:: an OAuth2 access token from GitHub
|
37
|
-
def initialize(access_token)
|
37
|
+
def initialize(access_token, api_url='https://api.github.com', header={})
|
38
38
|
@access_token = access_token
|
39
|
+
@api_url = api_url
|
40
|
+
@header = {:accept => :json,
|
41
|
+
:authorization => "token #{@access_token}",
|
42
|
+
:user_agent => "rubygem-github-v3-api"}
|
43
|
+
@header.merge!(header) if header.is_a?(Hash)
|
39
44
|
end
|
40
45
|
|
41
46
|
# Entry-point for access to the GitHub Users API
|
@@ -71,14 +76,13 @@ class GitHubV3API
|
|
71
76
|
end
|
72
77
|
|
73
78
|
def get(path, params={}) #:nodoc:
|
74
|
-
result = RestClient.get(
|
75
|
-
{:
|
76
|
-
:authorization => "token #{@access_token}"}.merge({:params => params}))
|
79
|
+
result = RestClient.get(@api_url + path,
|
80
|
+
@header.merge({:params => params}))
|
77
81
|
result_data = JSON.parse(result)
|
78
82
|
# check for pagination
|
79
83
|
link = result.headers[:link]
|
80
84
|
if link then
|
81
|
-
re_relnext =
|
85
|
+
re_relnext = %r!<#{@api_url}([^>]*)>; *rel="next"!
|
82
86
|
relnext_path = link.match re_relnext
|
83
87
|
if relnext_path && relnext_path[1] then
|
84
88
|
next_data = self.get(relnext_path[1], params)
|
@@ -91,27 +95,24 @@ class GitHubV3API
|
|
91
95
|
end
|
92
96
|
|
93
97
|
def post(path, params={}) #:nodoc:
|
94
|
-
result = RestClient.post(
|
95
|
-
|
96
|
-
:authorization => "token #{@access_token}"})
|
98
|
+
result = RestClient.post(@api_url + path, JSON.generate(params),
|
99
|
+
@header)
|
97
100
|
JSON.parse(result)
|
98
101
|
rescue RestClient::Unauthorized
|
99
102
|
raise Unauthorized, "The access token is invalid according to GitHub"
|
100
103
|
end
|
101
104
|
|
102
105
|
def patch(path, params={}) #:nodoc:
|
103
|
-
result = RestClient.post(
|
104
|
-
|
105
|
-
:authorization => "token #{@access_token}"})
|
106
|
+
result = RestClient.post(@api_url + path, JSON.generate(params),
|
107
|
+
@header)
|
106
108
|
JSON.parse(result)
|
107
109
|
rescue RestClient::Unauthorized
|
108
110
|
raise Unauthorized, "The access token is invalid according to GitHub"
|
109
111
|
end
|
110
112
|
|
111
113
|
def delete(path) #:nodoc:
|
112
|
-
result = RestClient.delete(
|
113
|
-
|
114
|
-
:authorization => "token #{@access_token}"})
|
114
|
+
result = RestClient.delete(@api_url + path,
|
115
|
+
@header)
|
115
116
|
JSON.parse(result)
|
116
117
|
rescue RestClient::Unauthorized
|
117
118
|
raise Unauthorized, "The access token is invalid according to GitHub"
|
@@ -24,6 +24,13 @@ class GitHubV3API
|
|
24
24
|
@connection = connection
|
25
25
|
end
|
26
26
|
|
27
|
+
def public_repos
|
28
|
+
@connection.get('/repositories').map do |repo_data|
|
29
|
+
GitHubV3API::Repo.new(self, repo_data)
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
|
27
34
|
# Returns an array of GitHubV3API::Repo instances representing the
|
28
35
|
# user's public and private repos
|
29
36
|
def list
|
@@ -35,6 +35,12 @@ class GitHubV3API
|
|
35
35
|
user_data = @connection.get("/users/#{username}")
|
36
36
|
GitHubV3API::User.new_with_all_data(self, user_data)
|
37
37
|
end
|
38
|
-
|
38
|
+
|
39
|
+
# Returns an array of all GitHubV3API::User instances in the server.
|
40
|
+
def all
|
41
|
+
@connection.get("/users").map do |user_data|
|
42
|
+
GitHubV3API::User.new_with_all_data(self, user_data)
|
43
|
+
end
|
44
|
+
end
|
39
45
|
end
|
40
46
|
end
|
data/spec/github_v3_api_spec.rb
CHANGED
@@ -1,27 +1,32 @@
|
|
1
1
|
require 'spec_helper'
|
2
2
|
|
3
3
|
describe GitHubV3API do
|
4
|
+
let(:auth_token) { 'abcde' }
|
5
|
+
let(:test_header) { {:accept => :json,
|
6
|
+
:authorization => "token #{auth_token}",
|
7
|
+
:user_agent => 'rubygem-github-v3-api'} }
|
8
|
+
|
4
9
|
it 'is initialized with an OAuth2 access token' do
|
5
|
-
lambda { GitHubV3API.new(
|
10
|
+
lambda { GitHubV3API.new(auth_token) }.should_not raise_error
|
6
11
|
end
|
7
12
|
|
8
13
|
describe '#orgs' do
|
9
14
|
it 'returns an instance of GitHubV3API::OrgsAPI' do
|
10
|
-
api = GitHubV3API.new(
|
15
|
+
api = GitHubV3API.new(auth_token)
|
11
16
|
api.orgs.should be_kind_of GitHubV3API::OrgsAPI
|
12
17
|
end
|
13
18
|
end
|
14
19
|
|
15
20
|
describe '#repos' do
|
16
21
|
it 'returns an instance of GitHubV3API::ReposAPI' do
|
17
|
-
api = GitHubV3API.new(
|
22
|
+
api = GitHubV3API.new(auth_token)
|
18
23
|
api.repos.should be_kind_of GitHubV3API::ReposAPI
|
19
24
|
end
|
20
25
|
end
|
21
26
|
|
22
27
|
describe "#issues" do
|
23
28
|
it "returns an instance of GitHubV3API::IssuesAPI" do
|
24
|
-
api = GitHubV3API.new(
|
29
|
+
api = GitHubV3API.new(auth_token)
|
25
30
|
api.issues.should be_kind_of GitHubV3API::IssuesAPI
|
26
31
|
end
|
27
32
|
end
|
@@ -29,19 +34,19 @@ describe GitHubV3API do
|
|
29
34
|
describe '#get' do
|
30
35
|
it 'does a get request to the specified path at the GitHub API server and adds the access token' do
|
31
36
|
rcs = String.new('[]')
|
32
|
-
rcs.
|
37
|
+
allow(rcs).to receive(:headers) { {} }
|
33
38
|
RestClient.should_receive(:get) \
|
34
|
-
.with('https://api.github.com/some/path', {:
|
39
|
+
.with('https://api.github.com/some/path', test_header.merge({:params => {}})) \
|
35
40
|
.and_return(rcs)
|
36
|
-
api = GitHubV3API.new(
|
41
|
+
api = GitHubV3API.new(auth_token)
|
37
42
|
api.get('/some/path')
|
38
43
|
end
|
39
44
|
|
40
45
|
it 'returns the result of parsing the result body as JSON' do
|
41
46
|
rcs = String.new('[{"foo": "bar"}]')
|
42
|
-
rcs.
|
43
|
-
RestClient.
|
44
|
-
api = GitHubV3API.new(
|
47
|
+
allow(rcs).to receive(:headers) { {} }
|
48
|
+
allow(RestClient).to receive(:get) { rcs }
|
49
|
+
api = GitHubV3API.new(auth_token)
|
45
50
|
api.get('/something').should == [{"foo" => "bar"}]
|
46
51
|
end
|
47
52
|
|
@@ -49,23 +54,23 @@ describe GitHubV3API do
|
|
49
54
|
headers_next = { :link => 'Link: <https://api.github.com/some/nextpath>; rel="next", <https://api.github.com/some/lastpath>; rel="last"' }
|
50
55
|
headers_last = { :link => 'Link: <https://api.github.com/some/prevpath>; rel="previous", <https://api.github.com/some/lastpath>; rel="last"' }
|
51
56
|
rcs_next = String.new('[]')
|
52
|
-
rcs_next.
|
57
|
+
allow(rcs_next).to receive(:headers) { headers_next }
|
53
58
|
rcs_last = String.new('[]')
|
54
|
-
rcs_last.
|
59
|
+
allow(rcs_last).to receive(:headers) { headers_last }
|
55
60
|
|
56
61
|
RestClient.should_receive(:get) \
|
57
|
-
.with('https://api.github.com/some/path',
|
62
|
+
.with('https://api.github.com/some/path', test_header.merge({:params => {}})) \
|
58
63
|
.and_return(rcs_next)
|
59
64
|
RestClient.should_receive(:get) \
|
60
|
-
.with('https://api.github.com/some/nextpath', {:
|
65
|
+
.with('https://api.github.com/some/nextpath', test_header.merge({:params => {}})) \
|
61
66
|
.and_return(rcs_last)
|
62
|
-
api = GitHubV3API.new(
|
67
|
+
api = GitHubV3API.new(auth_token)
|
63
68
|
api.get('/some/path')
|
64
69
|
end
|
65
70
|
|
66
71
|
it 'raises GitHubV3API::Unauthorized instead of RestClient::Unauthorized' do
|
67
|
-
RestClient.
|
68
|
-
api = GitHubV3API.new(
|
72
|
+
allow(RestClient).to receive(:get) { raise(RestClient::Unauthorized) }
|
73
|
+
api = GitHubV3API.new(auth_token)
|
69
74
|
lambda { api.get('/something') }.should raise_error(GitHubV3API::Unauthorized)
|
70
75
|
end
|
71
76
|
end
|
@@ -75,9 +80,9 @@ describe GitHubV3API do
|
|
75
80
|
data = {:title => 'omgbbq'}
|
76
81
|
json = JSON.generate(data)
|
77
82
|
RestClient.should_receive(:post) \
|
78
|
-
.with('https://api.github.com/some/path', json,
|
83
|
+
.with('https://api.github.com/some/path', json, test_header) \
|
79
84
|
.and_return('{}')
|
80
|
-
api = GitHubV3API.new(
|
85
|
+
api = GitHubV3API.new(auth_token)
|
81
86
|
api.post('/some/path', data)
|
82
87
|
end
|
83
88
|
end
|
@@ -87,9 +92,9 @@ describe GitHubV3API do
|
|
87
92
|
data = {:title => 'omgbbq'}
|
88
93
|
json = JSON.generate(data)
|
89
94
|
RestClient.should_receive(:post) \
|
90
|
-
.with('https://api.github.com/some/path', json,
|
95
|
+
.with('https://api.github.com/some/path', json, test_header) \
|
91
96
|
.and_return('{}')
|
92
|
-
api = GitHubV3API.new(
|
97
|
+
api = GitHubV3API.new(auth_token)
|
93
98
|
api.patch('/some/path', data)
|
94
99
|
end
|
95
100
|
end
|
@@ -97,9 +102,9 @@ describe GitHubV3API do
|
|
97
102
|
describe "#delete" do
|
98
103
|
it 'does a delete request to the specified path at the GitHub API server and adds the access token' do
|
99
104
|
RestClient.should_receive(:delete) \
|
100
|
-
.with('https://api.github.com/some/path',
|
105
|
+
.with('https://api.github.com/some/path', test_header) \
|
101
106
|
.and_return('{}')
|
102
|
-
api = GitHubV3API.new(
|
107
|
+
api = GitHubV3API.new(auth_token)
|
103
108
|
api.delete('/some/path')
|
104
109
|
end
|
105
110
|
end
|
data/spec/issue_spec.rb
CHANGED
@@ -6,7 +6,7 @@ describe GitHubV3API::Issue do
|
|
6
6
|
fields = %w(url html_url number state title body user labels assignee
|
7
7
|
milestone comments pull_request closed_at created_at updated_at)
|
8
8
|
fields.each do |f|
|
9
|
-
repo = GitHubV3API::Issue.new_with_all_data(
|
9
|
+
repo = GitHubV3API::Issue.new_with_all_data(double('api'), {f.to_s => 'foo'})
|
10
10
|
repo.methods.should include(f.to_sym)
|
11
11
|
repo.send(f).should == 'foo'
|
12
12
|
end
|
data/spec/issues_api_spec.rb
CHANGED
@@ -4,7 +4,7 @@ describe GitHubV3API::IssuesAPI do
|
|
4
4
|
describe "#list" do
|
5
5
|
context "options = nil" do
|
6
6
|
it "returns issues for a user" do
|
7
|
-
connection =
|
7
|
+
connection = double(GitHubV3API)
|
8
8
|
connection.should_receive(:get).with('/issues', {}).and_return([:issue_hash1, :issue_hash2])
|
9
9
|
api = GitHubV3API::IssuesAPI.new(connection)
|
10
10
|
GitHubV3API::Issue.should_receive(:new).with(api, :issue_hash1).and_return(:issue1)
|
@@ -16,7 +16,7 @@ describe GitHubV3API::IssuesAPI do
|
|
16
16
|
|
17
17
|
context "options = {:user => 'octocat', :repo => 'hello-world'}" do
|
18
18
|
it "returns issues for a repo" do
|
19
|
-
connection =
|
19
|
+
connection = double(GitHubV3API)
|
20
20
|
connection.should_receive(:get).with("/repos/octocat/hello-world/issues", {}).and_return([:issue_hash1, :issue_hash2])
|
21
21
|
api = GitHubV3API::IssuesAPI.new(connection)
|
22
22
|
GitHubV3API::Issue.should_receive(:new).with(api, :issue_hash1).and_return(:issue1)
|
@@ -29,7 +29,7 @@ describe GitHubV3API::IssuesAPI do
|
|
29
29
|
|
30
30
|
describe '#get' do
|
31
31
|
it 'returns a fully-hydrated Issue object for the specified user, repo, and issue id' do
|
32
|
-
connection =
|
32
|
+
connection = double(GitHubV3API)
|
33
33
|
connection.should_receive(:get).with('/repos/octocat/hello-world/issues/1234', {}).and_return(:issue_hash)
|
34
34
|
api = GitHubV3API::IssuesAPI.new(connection)
|
35
35
|
GitHubV3API::Issue.should_receive(:new_with_all_data).with(api, :issue_hash).and_return(:issue)
|
@@ -37,7 +37,7 @@ describe GitHubV3API::IssuesAPI do
|
|
37
37
|
end
|
38
38
|
|
39
39
|
it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
|
40
|
-
connection =
|
40
|
+
connection = double(GitHubV3API)
|
41
41
|
connection.should_receive(:get) \
|
42
42
|
.and_raise(RestClient::ResourceNotFound)
|
43
43
|
api = GitHubV3API::IssuesAPI.new(connection)
|
@@ -47,7 +47,7 @@ describe GitHubV3API::IssuesAPI do
|
|
47
47
|
|
48
48
|
describe "#create" do
|
49
49
|
it 'returns a fully-hydrated Issue object for the specified user, repo, and issue that was created' do
|
50
|
-
connection =
|
50
|
+
connection = double(GitHubV3API)
|
51
51
|
data = {:title => "omgbbq"}
|
52
52
|
connection.should_receive(:post).with('/repos/octocat/hello-world/issues', data).and_return(:issue_hash)
|
53
53
|
api = GitHubV3API::IssuesAPI.new(connection)
|
@@ -56,7 +56,7 @@ describe GitHubV3API::IssuesAPI do
|
|
56
56
|
end
|
57
57
|
|
58
58
|
it "raises GitHubV3API::MissingRequiredData when data[:title] is missing" do
|
59
|
-
connection =
|
59
|
+
connection = double(GitHubV3API)
|
60
60
|
connection.should_not_receive(:post)
|
61
61
|
api = GitHubV3API::IssuesAPI.new(connection)
|
62
62
|
lambda { api.create('octocat', 'hello-world', {}) }.should raise_error(GitHubV3API::MissingRequiredData)
|
@@ -65,7 +65,7 @@ describe GitHubV3API::IssuesAPI do
|
|
65
65
|
|
66
66
|
describe "#update" do
|
67
67
|
it 'returns a fully-hydrated Issue object for the specified user, repo, and issue that was updated' do
|
68
|
-
connection =
|
68
|
+
connection = double(GitHubV3API)
|
69
69
|
data = {:body => "lol, wtf"}
|
70
70
|
connection.should_receive(:patch).with('/repos/octocat/hello-world/issues/1234', data).and_return(:issue_hash)
|
71
71
|
api = GitHubV3API::IssuesAPI.new(connection)
|
@@ -73,4 +73,4 @@ describe GitHubV3API::IssuesAPI do
|
|
73
73
|
api.update('octocat', 'hello-world', 1234, data).should == :issue
|
74
74
|
end
|
75
75
|
end
|
76
|
-
end
|
76
|
+
end
|
data/spec/org_spec.rb
CHANGED
@@ -9,7 +9,7 @@ describe GitHubV3API::Org do
|
|
9
9
|
private_gists private_repos public_gists public_repos space
|
10
10
|
total_private_repos type url)
|
11
11
|
fields.each do |f|
|
12
|
-
org = GitHubV3API::Org.new_with_all_data(
|
12
|
+
org = GitHubV3API::Org.new_with_all_data(double('api'), {f.to_s => 'foo'})
|
13
13
|
org.methods.should include(f.to_sym)
|
14
14
|
org.send(f).should == 'foo'
|
15
15
|
end
|
@@ -18,7 +18,7 @@ describe GitHubV3API::Org do
|
|
18
18
|
|
19
19
|
describe '#[]' do
|
20
20
|
it 'returns the org data for the specified key' do
|
21
|
-
api =
|
21
|
+
api = double(GitHubV3API::OrgsAPI)
|
22
22
|
api.should_receive(:get).with('github') \
|
23
23
|
.and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
|
24
24
|
org = GitHubV3API::Org.new(api, 'login' => 'github')
|
@@ -26,7 +26,7 @@ describe GitHubV3API::Org do
|
|
26
26
|
end
|
27
27
|
|
28
28
|
it 'only fetches the data once' do
|
29
|
-
api =
|
29
|
+
api = double(GitHubV3API::OrgsAPI)
|
30
30
|
api.should_receive(:get).once.with('github') \
|
31
31
|
.and_return(GitHubV3API::Org.new(api, 'login' => 'github', 'company' => 'GitHub'))
|
32
32
|
org = GitHubV3API::Org.new(api, 'login' => 'github')
|
@@ -38,7 +38,7 @@ describe GitHubV3API::Org do
|
|
38
38
|
|
39
39
|
describe '#repos' do
|
40
40
|
it 'returns an array of Repo objects that belong to this org' do
|
41
|
-
api =
|
41
|
+
api = double(GitHubV3API::OrgsAPI)
|
42
42
|
api.should_receive(:list_repos).with('github').and_return([:repo1, :repo2])
|
43
43
|
org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
|
44
44
|
org.repos.should == [:repo1, :repo2]
|
@@ -47,7 +47,7 @@ describe GitHubV3API::Org do
|
|
47
47
|
|
48
48
|
describe '#members'do
|
49
49
|
it 'returns an array of User objects who are members of this org' do
|
50
|
-
api =
|
50
|
+
api = double(GitHubV3API::OrgsAPI)
|
51
51
|
api.should_receive(:list_members).with('github').and_return([:user1, :user2])
|
52
52
|
|
53
53
|
org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
|
@@ -57,7 +57,7 @@ describe GitHubV3API::Org do
|
|
57
57
|
|
58
58
|
describe '#public_members'do
|
59
59
|
it 'returns an array of User objects who are public members of this org' do
|
60
|
-
api =
|
60
|
+
api = double(GitHubV3API::OrgsAPI)
|
61
61
|
api.should_receive(:list_public_members).with('github').and_return([:user1, :user2])
|
62
62
|
|
63
63
|
org = GitHubV3API::Org.new_with_all_data(api, 'login' => 'github')
|
data/spec/orgs_api_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe GitHubV3API::OrgsAPI do
|
4
4
|
describe '#list' do
|
5
5
|
it 'returns the public and private orgs for the authenticated user' do
|
6
|
-
connection =
|
6
|
+
connection = double(GitHubV3API)
|
7
7
|
connection.should_receive(:get).with('/user/orgs').and_return([:org_hash1, :org_hash2])
|
8
8
|
api = GitHubV3API::OrgsAPI.new(connection)
|
9
9
|
GitHubV3API::Org.should_receive(:new).with(api, :org_hash1).and_return(:org1)
|
@@ -15,7 +15,7 @@ describe GitHubV3API::OrgsAPI do
|
|
15
15
|
|
16
16
|
describe '#get' do
|
17
17
|
it 'returns a fully-hydrated Org object for the specified org login' do
|
18
|
-
connection =
|
18
|
+
connection = double(GitHubV3API)
|
19
19
|
connection.should_receive(:get).with('/orgs/octocat').and_return(:org_hash)
|
20
20
|
api = GitHubV3API::OrgsAPI.new(connection)
|
21
21
|
GitHubV3API::Org.should_receive(:new_with_all_data).with(api, :org_hash).and_return(:org)
|
@@ -25,7 +25,7 @@ describe GitHubV3API::OrgsAPI do
|
|
25
25
|
|
26
26
|
describe '#list_repos' do
|
27
27
|
it 'returns the public and private repos for the specified org' do
|
28
|
-
connection =
|
28
|
+
connection = double(GitHubV3API, :repos => :repos_api)
|
29
29
|
connection.should_receive(:get) \
|
30
30
|
.with('/orgs/github/repos') \
|
31
31
|
.and_return([:repo1_hash, :repo2_hash])
|
@@ -42,7 +42,7 @@ describe GitHubV3API::OrgsAPI do
|
|
42
42
|
|
43
43
|
describe '#list_members' do
|
44
44
|
it 'returns the list of members for the specified org' do
|
45
|
-
connection =
|
45
|
+
connection = double(GitHubV3API, :users => :users_api)
|
46
46
|
connection.should_receive(:get).once.with('/orgs/github/members') \
|
47
47
|
.and_return([:user_hash1, :user_hash2])
|
48
48
|
|
@@ -59,7 +59,7 @@ describe GitHubV3API::OrgsAPI do
|
|
59
59
|
|
60
60
|
describe '#list_public_members' do
|
61
61
|
it 'returns the list of public members for the specified org' do
|
62
|
-
connection =
|
62
|
+
connection = double(GitHubV3API, :users => :users_api)
|
63
63
|
connection.should_receive(:get).once.with('/orgs/github/public_members') \
|
64
64
|
.and_return([:user_hash1, :user_hash2])
|
65
65
|
|
data/spec/repo_spec.rb
CHANGED
@@ -7,7 +7,7 @@ describe GitHubV3API::Repo do
|
|
7
7
|
has_wiki homepage html_url language master_branch name open_issues
|
8
8
|
organization owner parent private pushed_at size source url watchers)
|
9
9
|
fields.each do |f|
|
10
|
-
repo = GitHubV3API::Repo.new_with_all_data(
|
10
|
+
repo = GitHubV3API::Repo.new_with_all_data(double('api'), {f.to_s => 'foo'})
|
11
11
|
repo.methods.should include(f.to_sym)
|
12
12
|
repo.send(f).should == 'foo'
|
13
13
|
end
|
@@ -16,14 +16,14 @@ describe GitHubV3API::Repo do
|
|
16
16
|
|
17
17
|
describe '#[]' do
|
18
18
|
it 'returns the repo data for the specified key' do
|
19
|
-
api =
|
19
|
+
api = double(GitHubV3API::ReposAPI)
|
20
20
|
repo = GitHubV3API::Repo \
|
21
21
|
.new_with_all_data(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'})
|
22
22
|
repo['name'].should == 'hello-world'
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'only fetches the data once' do
|
26
|
-
api =
|
26
|
+
api = double(GitHubV3API::ReposAPI)
|
27
27
|
api.should_receive(:get).once.with('octocat', 'hello-world') \
|
28
28
|
.and_return(GitHubV3API::Repo.new(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'}, 'private' => true))
|
29
29
|
repo = GitHubV3API::Repo.new(api, 'name' => 'hello-world', 'owner' => {'login' => 'octocat'})
|
@@ -35,7 +35,7 @@ describe GitHubV3API::Repo do
|
|
35
35
|
|
36
36
|
describe '#owner_login' do
|
37
37
|
it 'returns the login name of the repo owner' do
|
38
|
-
api =
|
38
|
+
api = double(GitHubV3API::ReposAPI)
|
39
39
|
repo = GitHubV3API::Repo.new_with_all_data(api, 'owner' => {'login' => 'octocat'})
|
40
40
|
repo.owner_login.should == 'octocat'
|
41
41
|
end
|
@@ -43,7 +43,7 @@ describe GitHubV3API::Repo do
|
|
43
43
|
|
44
44
|
describe '#list_collaborators' do
|
45
45
|
it 'returns an array of User objects who are collaborating on this repo' do
|
46
|
-
api =
|
46
|
+
api = double(GitHubV3API::ReposAPI)
|
47
47
|
api.should_receive(:list_collaborators).once.with(
|
48
48
|
'octocat', 'hello-world').and_return([:user1, :user2, :user3])
|
49
49
|
|
@@ -55,7 +55,7 @@ describe GitHubV3API::Repo do
|
|
55
55
|
|
56
56
|
describe '#list_watchers' do
|
57
57
|
it 'returns an array of User objects who are watching this repo' do
|
58
|
-
api =
|
58
|
+
api = double(GitHubV3API::ReposAPI)
|
59
59
|
api.should_receive(:list_watchers).once.with(
|
60
60
|
'octocat', 'hello-world').and_return([:user1, :user2, :user3])
|
61
61
|
|
@@ -67,7 +67,7 @@ describe GitHubV3API::Repo do
|
|
67
67
|
|
68
68
|
describe '#list_forks' do
|
69
69
|
it 'returns an array of Repo objects which were forked from this repo' do
|
70
|
-
api =
|
70
|
+
api = double(GitHubV3API::ReposAPI)
|
71
71
|
api.should_receive(:list_forks).once.with(
|
72
72
|
'octocat', 'hello-world').and_return([:repo1, :repo2, :repo3])
|
73
73
|
|
data/spec/repos_api_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe GitHubV3API::ReposAPI do
|
4
4
|
describe '#list' do
|
5
5
|
it 'returns the public and private repos for the authenticated user' do
|
6
|
-
connection =
|
6
|
+
connection = double(GitHubV3API)
|
7
7
|
connection.should_receive(:get).with('/user/repos').and_return([:repo_hash1, :repo_hash2])
|
8
8
|
api = GitHubV3API::ReposAPI.new(connection)
|
9
9
|
GitHubV3API::Repo.should_receive(:new).with(api, :repo_hash1).and_return(:repo1)
|
@@ -15,7 +15,7 @@ describe GitHubV3API::ReposAPI do
|
|
15
15
|
|
16
16
|
describe '#get' do
|
17
17
|
it 'returns a fully-hydrated Repo object for the specified user and repo name' do
|
18
|
-
connection =
|
18
|
+
connection = double(GitHubV3API)
|
19
19
|
connection.should_receive(:get).with('/repos/octocat/hello-world').and_return(:repo_hash)
|
20
20
|
api = GitHubV3API::ReposAPI.new(connection)
|
21
21
|
GitHubV3API::Repo.should_receive(:new_with_all_data).with(api, :repo_hash).and_return(:repo)
|
@@ -23,7 +23,7 @@ describe GitHubV3API::ReposAPI do
|
|
23
23
|
end
|
24
24
|
|
25
25
|
it 'raises GitHubV3API::NotFound instead of a RestClient::ResourceNotFound' do
|
26
|
-
connection =
|
26
|
+
connection = double(GitHubV3API)
|
27
27
|
connection.should_receive(:get) \
|
28
28
|
.and_raise(RestClient::ResourceNotFound)
|
29
29
|
api = GitHubV3API::ReposAPI.new(connection)
|
@@ -33,7 +33,7 @@ describe GitHubV3API::ReposAPI do
|
|
33
33
|
|
34
34
|
describe "#list_collaborators" do
|
35
35
|
it 'returns a list of Users who are collaborating on the specified repo' do
|
36
|
-
connection =
|
36
|
+
connection = double(GitHubV3API)
|
37
37
|
connection.should_receive(:get).with(
|
38
38
|
'/repos/octocat/hello-world/collaborators').and_return([:user_hash1, :user_hash2])
|
39
39
|
connection.should_receive(:users).twice.and_return(:users_api)
|
@@ -49,7 +49,7 @@ describe GitHubV3API::ReposAPI do
|
|
49
49
|
|
50
50
|
describe "#list_watchers" do
|
51
51
|
it 'returns a list of Users who are watching the specified repo' do
|
52
|
-
connection =
|
52
|
+
connection = double(GitHubV3API)
|
53
53
|
connection.should_receive(:get).with(
|
54
54
|
'/repos/octocat/hello-world/watchers').and_return([:user_hash1, :user_hash2])
|
55
55
|
connection.should_receive(:users).twice.and_return(:users_api)
|
@@ -65,7 +65,7 @@ describe GitHubV3API::ReposAPI do
|
|
65
65
|
|
66
66
|
describe "#list_forks" do
|
67
67
|
it 'returns a list of Repos which were forked from the specified repo' do
|
68
|
-
connection =
|
68
|
+
connection = double(GitHubV3API)
|
69
69
|
connection.should_receive(:get).with(
|
70
70
|
'/repos/octocat/hello-world/forks').and_return([:repo_hash1, :repo_hash2])
|
71
71
|
api = GitHubV3API::ReposAPI.new(connection)
|
data/spec/user_api_spec.rb
CHANGED
@@ -3,7 +3,7 @@ require 'spec_helper'
|
|
3
3
|
describe GitHubV3API::UsersAPI do
|
4
4
|
describe '#current' do
|
5
5
|
it 'returns the user data for the authenticated user' do
|
6
|
-
connection =
|
6
|
+
connection = double(GitHubV3API)
|
7
7
|
connection.should_receive(:get).with('/user').and_return(:user_hash1)
|
8
8
|
api = GitHubV3API::UsersAPI.new(connection)
|
9
9
|
GitHubV3API::User.should_receive(:new).with(api, :user_hash1).and_return(:user1)
|
@@ -14,7 +14,7 @@ describe GitHubV3API::UsersAPI do
|
|
14
14
|
|
15
15
|
describe '#get' do
|
16
16
|
it 'returns a fully-hydrated User object for the specified user login' do
|
17
|
-
connection =
|
17
|
+
connection = double(GitHubV3API)
|
18
18
|
connection.should_receive(:get).with('/users/octocat').and_return(:user_hash)
|
19
19
|
api = GitHubV3API::UsersAPI.new(connection)
|
20
20
|
GitHubV3API::User.should_receive(:new_with_all_data).with(api, :user_hash).and_return(:user)
|
data/spec/user_spec.rb
CHANGED
@@ -8,7 +8,7 @@ describe GitHubV3API::User do
|
|
8
8
|
html_url created_at type total_private_repos owned_private_repos
|
9
9
|
private_gists disk_usage collaborators)
|
10
10
|
fields.each do |f|
|
11
|
-
user = GitHubV3API::User.new_with_all_data(
|
11
|
+
user = GitHubV3API::User.new_with_all_data(double('api'), {f.to_s => 'foo'})
|
12
12
|
user.methods.should include(f.to_sym)
|
13
13
|
user.send(f).should == 'foo'
|
14
14
|
end
|
@@ -17,7 +17,7 @@ describe GitHubV3API::User do
|
|
17
17
|
|
18
18
|
describe '#[]' do
|
19
19
|
it 'returns the user data for the specified key' do
|
20
|
-
api =
|
20
|
+
api = double(GitHubV3API::UsersAPI)
|
21
21
|
api.should_receive(:get).with('github') \
|
22
22
|
.and_return(GitHubV3API::User.new(api, 'login' => 'github', 'name' => 'GitHub'))
|
23
23
|
user = GitHubV3API::User.new(api, 'login' => 'github')
|
@@ -25,7 +25,7 @@ describe GitHubV3API::User do
|
|
25
25
|
end
|
26
26
|
|
27
27
|
it 'only fetches the data once' do
|
28
|
-
api =
|
28
|
+
api = double(GitHubV3API::UsersAPI)
|
29
29
|
api.should_receive(:get).once.with('github') \
|
30
30
|
.and_return(GitHubV3API::User.new(api, 'login' => 'github', 'name' => 'GitHub'))
|
31
31
|
user = GitHubV3API::User.new(api, 'login' => 'github')
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github-v3-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Wilger
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2014-10-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -166,7 +166,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
166
|
version: '0'
|
167
167
|
requirements: []
|
168
168
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.0.
|
169
|
+
rubygems_version: 2.0.14
|
170
170
|
signing_key:
|
171
171
|
specification_version: 4
|
172
172
|
summary: Ruby Client for the GitHub v3 API
|