github_api 0.10.2 → 0.11.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +78 -59
- data/features/cassettes/repos/assets/delete.yml +52 -0
- data/features/cassettes/repos/assets/edit.yml +65 -0
- data/features/cassettes/repos/assets/get.yml +74 -0
- data/features/cassettes/repos/assets/list.yml +73 -0
- data/features/cassettes/repos/assets/upload.yml +66 -0
- data/features/cassettes/repos/list_org.yml +167 -0
- data/features/cassettes/repos/list_org_instance.yml +300 -0
- data/features/cassettes/repos/releases/create.yml +64 -0
- data/features/cassettes/repos/releases/delete.yml +52 -0
- data/features/cassettes/repos/releases/edit.yml +63 -0
- data/features/cassettes/repos/releases/get.yml +78 -0
- data/features/cassettes/repos/releases/list.yml +81 -0
- data/features/cassettes/search/code.yml +252 -0
- data/features/cassettes/search/code_query.yml +65 -0
- data/features/cassettes/search/issues.yml +616 -170
- data/features/cassettes/search/legacy/email.yml +72 -0
- data/features/cassettes/search/legacy/issues.yml +119 -0
- data/features/cassettes/search/legacy/repos.yml +394 -0
- data/features/cassettes/search/legacy/users.yml +72 -0
- data/features/cassettes/search/legacy/users_keyword.yml +63 -0
- data/features/cassettes/search/repos.yml +375 -364
- data/features/cassettes/search/users.yml +40 -22
- data/features/cassettes/search/users_keyword.yml +51 -56
- data/features/repos.feature +22 -0
- data/features/repos/assets.feature +59 -0
- data/features/repos/releases.feature +58 -0
- data/features/search.feature +24 -13
- data/features/search/legacy.feature +59 -0
- data/features/settings.yml +2 -5
- data/features/step_definitions/github_api_steps.rb +12 -0
- data/lib/github_api/configuration.rb +3 -1
- data/lib/github_api/error.rb +6 -17
- data/lib/github_api/error/unknown_media.rb +18 -0
- data/lib/github_api/params_hash.rb +20 -10
- data/lib/github_api/repos.rb +26 -15
- data/lib/github_api/repos/releases.rb +146 -0
- data/lib/github_api/repos/releases/assets.rb +126 -0
- data/lib/github_api/request.rb +14 -9
- data/lib/github_api/resource.rb +8 -1
- data/lib/github_api/search.rb +68 -27
- data/lib/github_api/search/legacy.rb +94 -0
- data/lib/github_api/ssl_certs/cacert.pem +41 -0
- data/lib/github_api/ssl_certs/cacerts.pem +2183 -0
- data/lib/github_api/version.rb +2 -2
- data/spec/fixtures/repos/asset.json +12 -0
- data/spec/fixtures/repos/assets.json +14 -0
- data/spec/fixtures/repos/release.json +15 -0
- data/spec/fixtures/repos/releases.json +17 -0
- data/spec/fixtures/search/code.json +76 -0
- data/spec/fixtures/search/issues.json +47 -16
- data/spec/fixtures/search/issues_legacy.json +23 -0
- data/spec/fixtures/search/repos.json +39 -0
- data/spec/fixtures/search/{repositories.json → repos_legacy.json} +0 -0
- data/spec/fixtures/search/users.json +15 -19
- data/spec/fixtures/search/users_legacy.json +24 -0
- data/spec/github/configuration_spec.rb +2 -0
- data/spec/github/error/unknown_media_spec.rb +21 -0
- data/spec/github/git_data/references/create_spec.rb +1 -1
- data/spec/github/git_data/references/get_spec.rb +6 -4
- data/spec/github/git_data/references/list_spec.rb +6 -16
- data/spec/github/pagination/iterator/number_spec.rb +2 -2
- data/spec/github/pagination/iterator/sha_spec.rb +2 -2
- data/spec/github/params_hash_spec.rb +6 -0
- data/spec/github/repos/assets/delete_spec.rb +40 -0
- data/spec/github/repos/assets/edit_spec.rb +40 -0
- data/spec/github/repos/assets/get_spec.rb +45 -0
- data/spec/github/repos/assets/list_spec.rb +55 -0
- data/spec/github/repos/assets/upload_spec.rb +44 -0
- data/spec/github/repos/downloads/upload_spec.rb +5 -5
- data/spec/github/repos/releases/create_spec.rb +44 -0
- data/spec/github/repos/releases/delete_spec.rb +40 -0
- data/spec/github/repos/releases/edit_spec.rb +40 -0
- data/spec/github/repos/releases/get_spec.rb +45 -0
- data/spec/github/repos/releases/list_spec.rb +54 -0
- data/spec/github/request/endpoint_spec.rb +1 -3
- data/spec/github/request/request_spec.rb +4 -8
- data/spec/github/request_spec.rb +3 -3
- data/spec/github/response_wrapper_spec.rb +3 -3
- data/spec/github/s3_uploader_spec.rb +2 -3
- data/spec/github/search/code_spec.rb +38 -0
- data/spec/github/search/issues_spec.rb +38 -0
- data/spec/github/search/legacy/email_spec.rb +34 -0
- data/spec/github/search/legacy/issues_spec.rb +39 -0
- data/spec/github/search/legacy/repos_spec.rb +36 -0
- data/spec/github/search/legacy/users_spec.rb +36 -0
- data/spec/github/search/repos_spec.rb +38 -0
- data/spec/github/search/users_spec.rb +38 -0
- data/spec/github/users/get_spec.rb +1 -1
- data/spec/github/validations/presence_spec.rb +2 -5
- data/spec/integration/repos_spec.rb +4 -0
- data/spec/integration/search_spec.rb +12 -0
- metadata +122 -62
- data/features/cassettes/search/email.yml +0 -99
- data/spec/github/search_spec.rb +0 -102
@@ -0,0 +1,54 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Releases, '#list' do
|
6
|
+
let(:owner) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:path) { "/repos/#{owner}/#{repo}/releases" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(path).to_return(body: body, status: status,
|
12
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture("repos/releases.json") }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to :all }
|
22
|
+
|
23
|
+
it { expect { subject.list }.to raise_error(ArgumentError) }
|
24
|
+
|
25
|
+
it "should fail to get resource without repository" do
|
26
|
+
expect { subject.list owner }.to raise_error(ArgumentError)
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the resources" do
|
30
|
+
subject.list owner, repo
|
31
|
+
expect(a_get(path)).to have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it_should_behave_like 'an array of resources' do
|
35
|
+
let(:requestable) { subject.list owner, repo }
|
36
|
+
end
|
37
|
+
|
38
|
+
it "should get key information" do
|
39
|
+
keys = subject.list owner, repo
|
40
|
+
expect(keys.first.tag_name).to eq 'v1.0.0'
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should yield to a block" do
|
44
|
+
yielded = []
|
45
|
+
result = subject.list(owner, repo) { |obj| yielded << obj }
|
46
|
+
expect(yielded).to eq result
|
47
|
+
end
|
48
|
+
end
|
49
|
+
|
50
|
+
it_should_behave_like 'request failure' do
|
51
|
+
let(:requestable) { subject.list owner, repo }
|
52
|
+
end
|
53
|
+
|
54
|
+
end # list
|
@@ -17,8 +17,6 @@ describe Github::API, 'endpoint' do
|
|
17
17
|
its(:endpoint) { should == endpoint }
|
18
18
|
|
19
19
|
it "doesn't truncate endpoint" do
|
20
|
-
expect {
|
21
|
-
api.get_request(path)
|
22
|
-
}.not_to raise_error(WebMock::NetConnectNotAllowedError)
|
20
|
+
expect { api.get_request(path) }.not_to raise_error()
|
23
21
|
end
|
24
22
|
end
|
@@ -3,10 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Github::API, '#request' do
|
6
|
-
let(:token)
|
7
|
-
let(:per_page)
|
8
|
-
let(:path)
|
9
|
-
|
6
|
+
let(:token) { "2fdsfdo23fsdf3omkhen34n2jh" }
|
7
|
+
let(:per_page) { 100 }
|
8
|
+
let(:path) { "/api/v3/repos/GitHub/issues-dev/issues" }
|
10
9
|
let(:url_prefix) { "https://my-company/api/v3/repos/GitHub/issues-dev/issues?access_token=#{token}&page=2&per_page=#{per_page}" }
|
11
10
|
|
12
11
|
let(:conn) { Faraday::Connection.new }
|
@@ -30,9 +29,6 @@ describe Github::API, '#request' do
|
|
30
29
|
|
31
30
|
it 'handles enterprise uri correctly' do
|
32
31
|
subject.stub(:connection).and_return conn
|
33
|
-
|
34
|
-
expect {
|
35
|
-
subject.get_request(path)
|
36
|
-
}.not_to raise_error(WebMock::NetConnectNotAllowedError)
|
32
|
+
expect { subject.get_request(path) }.not_to raise_error()
|
37
33
|
end
|
38
34
|
end
|
data/spec/github/request_spec.rb
CHANGED
@@ -3,9 +3,9 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Github::Request do
|
6
|
-
let(:github)
|
7
|
-
let(:path)
|
8
|
-
let(:params)
|
6
|
+
let(:github) { Github::API.new }
|
7
|
+
let(:path) { 'github.api/repos/users' }
|
8
|
+
let(:params) { {} }
|
9
9
|
let(:response) { double('response').as_null_object }
|
10
10
|
|
11
11
|
it "knows how to make get request" do
|
@@ -53,9 +53,9 @@ describe Github::ResponseWrapper do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
context "pagination methods" do
|
56
|
-
let(:links)
|
57
|
-
let(:current_api) {
|
58
|
-
let(:iterator)
|
56
|
+
let(:links) { Github::PageLinks.new({}) }
|
57
|
+
let(:current_api) { double(:api).as_null_object }
|
58
|
+
let(:iterator) { Github::PageIterator.new(links, current_api) }
|
59
59
|
|
60
60
|
before do
|
61
61
|
described_class.stub(:page_iterator).and_return iterator
|
@@ -4,9 +4,8 @@ require 'spec_helper'
|
|
4
4
|
require 'github_api/s3_uploader'
|
5
5
|
|
6
6
|
describe Github::S3Uploader do
|
7
|
-
|
8
7
|
let(:result) {
|
9
|
-
|
8
|
+
double(:resource,
|
10
9
|
'path' => 'downloads/octokit/github/droid',
|
11
10
|
'acl' => 'public-read',
|
12
11
|
'name' => 'droid',
|
@@ -31,7 +30,7 @@ describe Github::S3Uploader do
|
|
31
30
|
end
|
32
31
|
|
33
32
|
it 'checks for missing parameters' do
|
34
|
-
resource =
|
33
|
+
resource = double(:resource)
|
35
34
|
uploader = Github::S3Uploader.new resource, filename
|
36
35
|
expect {
|
37
36
|
uploader.send
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search, '#code' do
|
6
|
+
let(:query) { 'tty' }
|
7
|
+
let(:request_path) { '/search/code' }
|
8
|
+
|
9
|
+
before {
|
10
|
+
stub_get(request_path).with(query: {q: query}).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('search/code.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to :code }
|
22
|
+
|
23
|
+
it "should get the resources" do
|
24
|
+
subject.code q: query
|
25
|
+
a_get(request_path).with(query: {q: query}).should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be a response wrapper" do
|
29
|
+
code = subject.code q: query
|
30
|
+
code.should be_a Github::ResponseWrapper
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get information" do
|
34
|
+
code = subject.code q: query
|
35
|
+
code.total_count.should == 104
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search, '#issues' do
|
6
|
+
let(:query) { 'tty' }
|
7
|
+
let(:request_path) { "/search/issues" }
|
8
|
+
|
9
|
+
before {
|
10
|
+
stub_get(request_path).with(query: {q: query}).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('search/issues.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to :issues }
|
22
|
+
|
23
|
+
it "should get the resources" do
|
24
|
+
subject.issues q: query
|
25
|
+
a_get(request_path).with(query: {q: query}).should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be a response wrapper" do
|
29
|
+
code = subject.issues q: query
|
30
|
+
code.should be_a Github::ResponseWrapper
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get information" do
|
34
|
+
code = subject.issues q: query
|
35
|
+
code.total_count.should == 280
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search::Legacy, '#email' do
|
6
|
+
let(:keyword) { 'api' }
|
7
|
+
let(:request_path) { "/legacy/user/email/#{keyword}" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_get(request_path).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
|
15
|
+
context "resource found" do
|
16
|
+
let(:body) { fixture('search/email.json') }
|
17
|
+
let(:status) { 200 }
|
18
|
+
|
19
|
+
it "should get the resources" do
|
20
|
+
subject.email keyword
|
21
|
+
a_get(request_path).should have_been_made
|
22
|
+
end
|
23
|
+
|
24
|
+
it "should get the resource through params hash" do
|
25
|
+
subject.email email: keyword
|
26
|
+
a_get(request_path).should have_been_made
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get user information" do
|
30
|
+
user = subject.email email: keyword
|
31
|
+
user.user.username.should == 'techno'
|
32
|
+
end
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,39 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search::Legacy, '#issues' do
|
6
|
+
let(:keyword) { 'api' }
|
7
|
+
let(:request_path) {"/legacy/issues/search/#{owner}/#{repo}/#{state}/#{keyword}"}
|
8
|
+
let(:owner) { 'peter-murach' }
|
9
|
+
let(:repo) { 'github' }
|
10
|
+
let(:state) { 'closed' }
|
11
|
+
|
12
|
+
before do
|
13
|
+
stub_get(request_path).
|
14
|
+
to_return(body: body, status: status,
|
15
|
+
headers: {content_type: "application/json; charset=utf-8"})
|
16
|
+
end
|
17
|
+
|
18
|
+
context "resource found" do
|
19
|
+
let(:body) { fixture('search/issues_legacy.json') }
|
20
|
+
let(:status) { 200 }
|
21
|
+
|
22
|
+
it { expect { subject.issues }.to raise_error(ArgumentError) }
|
23
|
+
|
24
|
+
it "should get the resources" do
|
25
|
+
subject.issues owner, repo, state, keyword
|
26
|
+
a_get(request_path).should have_been_made
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should get the resource through params hash" do
|
30
|
+
subject.issues owner: owner, repo: repo, state: state, keyword: keyword
|
31
|
+
a_get(request_path).should have_been_made
|
32
|
+
end
|
33
|
+
|
34
|
+
it "should get repository information" do
|
35
|
+
issues = subject.issues owner: owner, repo: repo, state: state, keyword: keyword
|
36
|
+
issues.issues.first.user.should == 'ckarbass'
|
37
|
+
end
|
38
|
+
end
|
39
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search::Legacy, '#repos' do
|
6
|
+
let(:keyword) { 'api' }
|
7
|
+
let(:request_path) { "/legacy/repos/search/#{keyword}" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_get(request_path).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
|
15
|
+
context "resource found" do
|
16
|
+
let(:body) { fixture('search/repos_legacy.json') }
|
17
|
+
let(:status) { 200 }
|
18
|
+
|
19
|
+
it { expect { subject.repos }.to raise_error(ArgumentError) }
|
20
|
+
|
21
|
+
it "should get the resources" do
|
22
|
+
subject.repos keyword
|
23
|
+
a_get(request_path).should have_been_made
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get the resource through params hash" do
|
27
|
+
subject.repos keyword: keyword
|
28
|
+
a_get(request_path).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get repository information" do
|
32
|
+
repos = subject.repos keyword: keyword
|
33
|
+
repos.repositories.first.username.should == 'mathiasbynens'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search::Legacy, '#users' do
|
6
|
+
let(:keyword) { 'api' }
|
7
|
+
let(:request_path) { "/legacy/user/search/#{keyword}" }
|
8
|
+
|
9
|
+
before do
|
10
|
+
stub_get(request_path).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: "application/json; charset=utf-8"})
|
13
|
+
end
|
14
|
+
|
15
|
+
context "resource found" do
|
16
|
+
let(:body) { fixture('search/users_legacy.json') }
|
17
|
+
let(:status) { 200 }
|
18
|
+
|
19
|
+
it { expect { subject.users }.to raise_error(ArgumentError) }
|
20
|
+
|
21
|
+
it "should get the resources" do
|
22
|
+
subject.users keyword
|
23
|
+
a_get(request_path).should have_been_made
|
24
|
+
end
|
25
|
+
|
26
|
+
it "should get the resource through params hash" do
|
27
|
+
subject.users keyword: keyword
|
28
|
+
a_get(request_path).should have_been_made
|
29
|
+
end
|
30
|
+
|
31
|
+
it "should get repository information" do
|
32
|
+
users = subject.users keyword: keyword
|
33
|
+
users.users.first.username.should == 'techno'
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search, '#repos' do
|
6
|
+
let(:query) { 'tty' }
|
7
|
+
let(:request_path) { "/search/repositories" }
|
8
|
+
|
9
|
+
before {
|
10
|
+
stub_get(request_path).with(query: {q: query}).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('search/repos.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to :repos }
|
22
|
+
|
23
|
+
it "should get the resources" do
|
24
|
+
subject.repos q: query
|
25
|
+
a_get(request_path).with(query: {q: query}).should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be a response wrapper" do
|
29
|
+
code = subject.repos q: query
|
30
|
+
code.should be_a Github::ResponseWrapper
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get information" do
|
34
|
+
code = subject.repos q: query
|
35
|
+
code.total_count.should == 40
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|
@@ -0,0 +1,38 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Search, '#users' do
|
6
|
+
let(:query) { 'tty' }
|
7
|
+
let(:request_path) { "/search/users" }
|
8
|
+
|
9
|
+
before {
|
10
|
+
stub_get(request_path).with(query: {q: query}).
|
11
|
+
to_return(body: body, status: status,
|
12
|
+
headers: {content_type: 'application/json; charset=utf-8'})
|
13
|
+
}
|
14
|
+
|
15
|
+
after { reset_authentication_for(subject) }
|
16
|
+
|
17
|
+
context "resource found" do
|
18
|
+
let(:body) { fixture('search/users.json') }
|
19
|
+
let(:status) { 200 }
|
20
|
+
|
21
|
+
it { should respond_to :users }
|
22
|
+
|
23
|
+
it "should get the resources" do
|
24
|
+
subject.users q: query
|
25
|
+
a_get(request_path).with(query: {q: query}).should have_been_made
|
26
|
+
end
|
27
|
+
|
28
|
+
it "should be a response wrapper" do
|
29
|
+
code = subject.users q: query
|
30
|
+
code.should be_a Github::ResponseWrapper
|
31
|
+
end
|
32
|
+
|
33
|
+
it "should get information" do
|
34
|
+
code = subject.users q: query
|
35
|
+
code.total_count.should == 12
|
36
|
+
end
|
37
|
+
end
|
38
|
+
end
|