github_api 0.9.7 → 0.10.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README.md +24 -14
- data/features/cassettes/media/get_default.yml +84 -0
- data/features/cassettes/media/get_full_json.yml +83 -0
- data/features/cassettes/media/get_html_json.yml +81 -0
- data/features/cassettes/media/get_raw_json.yml +80 -0
- data/features/cassettes/media/get_text_json.yml +80 -0
- data/features/cassettes/repos/stats/commits.yml +80 -0
- data/features/cassettes/repos/stats/contribs.yml +221 -0
- data/features/cassettes/repos/stats/frequency.yml +54 -0
- data/features/cassettes/repos/stats/participation.yml +68 -0
- data/features/cassettes/repos/stats/punch.yml +76 -0
- data/features/cassettes/search/users_keyword.yml +70 -0
- data/features/gitignore.feature +1 -1
- data/features/media_type.feature +76 -0
- data/features/repos/statistics.feature +60 -0
- data/features/search.feature +11 -0
- data/features/step_definitions/github_api_steps.rb +4 -0
- data/lib/github_api.rb +2 -0
- data/lib/github_api/arguments.rb +1 -1
- data/lib/github_api/authorization.rb +1 -1
- data/lib/github_api/connection.rb +5 -7
- data/lib/github_api/core_ext/deep_merge.rb +13 -0
- data/lib/github_api/git_data/trees.rb +1 -1
- data/lib/github_api/gitignore.rb +5 -4
- data/lib/github_api/markdown.rb +7 -5
- data/lib/github_api/mime_type.rb +19 -41
- data/lib/github_api/paged_request.rb +1 -1
- data/lib/github_api/parameter_filter.rb +1 -1
- data/lib/github_api/params_hash.rb +59 -22
- data/lib/github_api/repos.rb +9 -3
- data/lib/github_api/repos/pub_sub_hubbub.rb +4 -2
- data/lib/github_api/repos/statistics.rb +94 -0
- data/lib/github_api/request.rb +17 -28
- data/lib/github_api/response_wrapper.rb +8 -0
- data/lib/github_api/say.rb +2 -1
- data/lib/github_api/scopes.rb +3 -2
- data/lib/github_api/search.rb +3 -3
- data/lib/github_api/utils/url.rb +5 -2
- data/lib/github_api/version.rb +2 -2
- data/spec/fixtures/repos/commit_activity.json +15 -0
- data/spec/fixtures/repos/contribs.json +20 -0
- data/spec/fixtures/repos/frequency.json +7 -0
- data/spec/fixtures/repos/participation.json +110 -0
- data/spec/fixtures/repos/punch_card.json +17 -0
- data/spec/github/arguments/parse_spec.rb +2 -2
- data/spec/github/core_ext/deep_merge_spec.rb +23 -0
- data/spec/github/git_data/trees/create_spec.rb +6 -0
- data/spec/github/gitignore/get_spec.rb +1 -1
- data/spec/github/mime_type_spec.rb +24 -55
- data/spec/github/params_hash_spec.rb +64 -0
- data/spec/github/pull_requests/list_spec.rb +1 -1
- data/spec/github/repos/statistics/code_frequency_spec.rb +25 -0
- data/spec/github/repos/statistics/commit_activity_spec.rb +29 -0
- data/spec/github/repos/statistics/contributors_spec.rb +29 -0
- data/spec/github/repos/statistics/participation_spec.rb +25 -0
- data/spec/github/repos/statistics/punch_card_spec.rb +25 -0
- data/spec/github/request_spec.rb +10 -11
- data/spec/github/response_wrapper/overwrites_spec.rb +19 -0
- data/spec/github/users/keys/update_spec.rb +1 -1
- metadata +73 -34
@@ -0,0 +1,20 @@
|
|
1
|
+
[
|
2
|
+
{
|
3
|
+
"author": {
|
4
|
+
"login": "octocat",
|
5
|
+
"id": 1,
|
6
|
+
"avatar_url": "https://github.com/images/error/octocat_happy.gif",
|
7
|
+
"gravatar_id": "somehexcode",
|
8
|
+
"url": "https://api.github.com/users/octocat"
|
9
|
+
},
|
10
|
+
"total": 135,
|
11
|
+
"weeks": [
|
12
|
+
{
|
13
|
+
"w": "1367712000",
|
14
|
+
"a": 6898,
|
15
|
+
"d": 77,
|
16
|
+
"c": 10
|
17
|
+
}
|
18
|
+
]
|
19
|
+
}
|
20
|
+
]
|
@@ -0,0 +1,110 @@
|
|
1
|
+
{
|
2
|
+
"all": [
|
3
|
+
11,
|
4
|
+
21,
|
5
|
+
15,
|
6
|
+
2,
|
7
|
+
8,
|
8
|
+
1,
|
9
|
+
8,
|
10
|
+
23,
|
11
|
+
17,
|
12
|
+
21,
|
13
|
+
11,
|
14
|
+
10,
|
15
|
+
33,
|
16
|
+
91,
|
17
|
+
38,
|
18
|
+
34,
|
19
|
+
22,
|
20
|
+
23,
|
21
|
+
32,
|
22
|
+
3,
|
23
|
+
43,
|
24
|
+
87,
|
25
|
+
71,
|
26
|
+
18,
|
27
|
+
13,
|
28
|
+
5,
|
29
|
+
13,
|
30
|
+
16,
|
31
|
+
66,
|
32
|
+
27,
|
33
|
+
12,
|
34
|
+
45,
|
35
|
+
110,
|
36
|
+
117,
|
37
|
+
13,
|
38
|
+
8,
|
39
|
+
18,
|
40
|
+
9,
|
41
|
+
19,
|
42
|
+
26,
|
43
|
+
39,
|
44
|
+
12,
|
45
|
+
20,
|
46
|
+
31,
|
47
|
+
46,
|
48
|
+
91,
|
49
|
+
45,
|
50
|
+
10,
|
51
|
+
24,
|
52
|
+
9,
|
53
|
+
29,
|
54
|
+
7
|
55
|
+
],
|
56
|
+
"owner": [
|
57
|
+
3,
|
58
|
+
2,
|
59
|
+
3,
|
60
|
+
0,
|
61
|
+
2,
|
62
|
+
0,
|
63
|
+
5,
|
64
|
+
14,
|
65
|
+
7,
|
66
|
+
9,
|
67
|
+
1,
|
68
|
+
5,
|
69
|
+
0,
|
70
|
+
48,
|
71
|
+
19,
|
72
|
+
2,
|
73
|
+
0,
|
74
|
+
1,
|
75
|
+
10,
|
76
|
+
2,
|
77
|
+
23,
|
78
|
+
40,
|
79
|
+
35,
|
80
|
+
8,
|
81
|
+
8,
|
82
|
+
2,
|
83
|
+
10,
|
84
|
+
6,
|
85
|
+
30,
|
86
|
+
0,
|
87
|
+
2,
|
88
|
+
9,
|
89
|
+
53,
|
90
|
+
104,
|
91
|
+
3,
|
92
|
+
3,
|
93
|
+
10,
|
94
|
+
4,
|
95
|
+
7,
|
96
|
+
11,
|
97
|
+
21,
|
98
|
+
4,
|
99
|
+
4,
|
100
|
+
22,
|
101
|
+
26,
|
102
|
+
63,
|
103
|
+
11,
|
104
|
+
2,
|
105
|
+
14,
|
106
|
+
1,
|
107
|
+
10,
|
108
|
+
3
|
109
|
+
]
|
110
|
+
}
|
@@ -17,7 +17,7 @@ describe Github::Arguments, '#parse' do
|
|
17
17
|
|
18
18
|
it { should == object }
|
19
19
|
|
20
|
-
its(:params) { should ==
|
20
|
+
its(:params) { should == {"page" => 23} }
|
21
21
|
|
22
22
|
context 'sets parameters' do
|
23
23
|
it { subject.api.user.should == 'peter-murach' }
|
@@ -63,6 +63,6 @@ describe Github::Arguments, '#parse' do
|
|
63
63
|
let(:required) { [] }
|
64
64
|
let(:arguments) { [params] }
|
65
65
|
|
66
|
-
its(:params) { should ==
|
66
|
+
its(:params) { should == {"page" => 23} }
|
67
67
|
end
|
68
68
|
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Hash, 'deep_merge' do
|
6
|
+
|
7
|
+
let(:hash) { { :a => 'a', :b => "b", :c => {:c1 => "c1", :c2 => "c2", :c3 => {:d1 => "d1"} } } }
|
8
|
+
let(:other_hash) { { :a => 1, :b => "b", :c => {:c1 => 2, :c2 => "c2", :c3 => {:d1 => "d1", :d2 => "d2"} } } }
|
9
|
+
|
10
|
+
subject { hash.deep_merge(other_hash) }
|
11
|
+
|
12
|
+
it { expect(subject[:a]).to eql(1) }
|
13
|
+
|
14
|
+
it { expect(subject[:b]).to eql("b") }
|
15
|
+
|
16
|
+
it { expect(subject[:c][:c1]).to eql(2) }
|
17
|
+
|
18
|
+
it { expect(subject[:c][:c2]).to eql("c2") }
|
19
|
+
|
20
|
+
it { expect(subject[:c][:c3][:d1]).to eql("d1") }
|
21
|
+
|
22
|
+
it { expect(subject[:c][:c3][:d2]).to eql("d2") }
|
23
|
+
end
|
@@ -49,6 +49,12 @@ describe Github::GitData::Trees, '#create' do
|
|
49
49
|
tree_sha.should be_a Github::ResponseWrapper
|
50
50
|
end
|
51
51
|
|
52
|
+
it "should not erase the tree data while evaluating params" do
|
53
|
+
original_tree = inputs['tree'].dup
|
54
|
+
tree_sha = subject.create user, repo, inputs
|
55
|
+
inputs['tree'].should == original_tree
|
56
|
+
end
|
57
|
+
|
52
58
|
it "should get the tree information" do
|
53
59
|
tree_sha = subject.create user, repo, inputs
|
54
60
|
tree_sha.sha.should == sha
|
@@ -42,7 +42,7 @@ describe Github::Gitignore, '#get' do
|
|
42
42
|
let(:accept) { 'application/vnd.github.raw' }
|
43
43
|
|
44
44
|
it "should get the resource" do
|
45
|
-
subject.get template, '
|
45
|
+
subject.get template, 'accept' => 'application/vnd.github.raw'
|
46
46
|
a_get(request_path).should have_been_made
|
47
47
|
end
|
48
48
|
end
|
@@ -2,69 +2,38 @@ require 'spec_helper'
|
|
2
2
|
|
3
3
|
describe Github::MimeType do
|
4
4
|
|
5
|
-
let(:
|
5
|
+
let(:object) { Class.new.extend(described_class) }
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
it "should lookup mime type for :html" do
|
12
|
-
github.lookup_mime(:html).should == 'html+json'
|
13
|
-
end
|
14
|
-
|
15
|
-
it "should lookup mime type for :html" do
|
16
|
-
github.lookup_mime(:text).should == 'text+json'
|
17
|
-
end
|
7
|
+
context 'lookup' do
|
8
|
+
it 'retrieves media type' do
|
9
|
+
expect(object.lookup_media('text')).to eql('text+json')
|
10
|
+
end
|
18
11
|
|
19
|
-
|
20
|
-
|
12
|
+
it 'raises error on unkonwn media type' do
|
13
|
+
expect { object.lookup_media('unknown') }.to raise_error(ArgumentError)
|
14
|
+
end
|
21
15
|
end
|
22
16
|
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
17
|
+
context 'parse' do
|
18
|
+
it 'accepts text' do
|
19
|
+
expect(object.parse('text')).to eql('application/vnd.github.v3.text+json')
|
20
|
+
end
|
27
21
|
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
Github.parse(:issue, :full).should == 'application/vnd.github-issue.full+json'
|
32
|
-
end
|
22
|
+
it 'accepts text+json' do
|
23
|
+
expect(object.parse('text+json')).to eql('application/vnd.github.v3.text+json')
|
24
|
+
end
|
33
25
|
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
Github.parse(:issue_comment, :full).should == 'application/vnd.github-issuecomment.full+json'
|
38
|
-
end
|
26
|
+
it 'accepts v3.text' do
|
27
|
+
expect(object.parse('v3.text')).to eql('application/vnd.github.v3.text+json')
|
28
|
+
end
|
39
29
|
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
Github.parse(:commit_comment, :full).should == 'application/vnd.github-commitcomment.full+json'
|
44
|
-
end
|
45
|
-
|
46
|
-
it "should accept header for 'pull requst' request" do
|
47
|
-
Github.should_receive(:parse).with(:pull_request, :full).
|
48
|
-
and_return 'application/vnd.github-pull.full+json'
|
49
|
-
Github.parse(:pull_request, :full).should == 'application/vnd.github-pull.full+json'
|
50
|
-
end
|
51
|
-
|
52
|
-
it "should accept header for 'pull comment' request" do
|
53
|
-
Github.should_receive(:parse).with(:pull_comment, :full).
|
54
|
-
and_return 'application/vnd.github-pullcomment.full+json'
|
55
|
-
Github.parse(:pull_comment, :full).should == 'application/vnd.github-pullcomment.full+json'
|
56
|
-
end
|
57
|
-
|
58
|
-
it "should accept header for 'gist comment' request" do
|
59
|
-
Github.should_receive(:parse).with(:gist_comment, :full).
|
60
|
-
and_return 'application/vnd.github-gistcomment.full+json'
|
61
|
-
Github.parse(:gist_comment, :full).should == 'application/vnd.github-gistcomment.full+json'
|
62
|
-
end
|
30
|
+
it 'accepts v3.text+json' do
|
31
|
+
expect(object.parse('v3.text+json')).to eql('application/vnd.github.v3.text+json')
|
32
|
+
end
|
63
33
|
|
64
|
-
|
65
|
-
|
66
|
-
|
67
|
-
Github.parse(:blob, :blob).should == 'application/vnd.github-blob.raw'
|
34
|
+
it 'accpets .v3.text' do
|
35
|
+
expect(object.parse('.v3.text')).to eql('application/vnd.github.v3.text+json')
|
36
|
+
end
|
68
37
|
end
|
69
38
|
|
70
39
|
end # Github::MimeType
|
@@ -0,0 +1,64 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::ParamsHash do
|
6
|
+
let(:object) { described_class }
|
7
|
+
|
8
|
+
subject { object.new(hash) }
|
9
|
+
|
10
|
+
context 'converts key to string' do
|
11
|
+
let(:hash) { {:foo => 123 }}
|
12
|
+
|
13
|
+
it { expect(subject).to be_a(Github::ParamsHash)}
|
14
|
+
|
15
|
+
it { expect(subject['foo']).to eql(123) }
|
16
|
+
|
17
|
+
it { expect(subject.data).to eql({"foo" => 123}) }
|
18
|
+
end
|
19
|
+
|
20
|
+
context 'media' do
|
21
|
+
let(:hash) { {:media => "raw"} }
|
22
|
+
|
23
|
+
it 'parses media key' do
|
24
|
+
expect(subject.media).to eql('application/vnd.github.v3.raw+json')
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
context 'with accept' do
|
29
|
+
let(:hash) { {:accept => "application/json"} }
|
30
|
+
|
31
|
+
it 'overwrites media key' do
|
32
|
+
expect(subject.accept).to eql('application/json')
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
context 'without accept' do
|
37
|
+
let(:hash) { {} }
|
38
|
+
|
39
|
+
it 'overwrites media key' do
|
40
|
+
expect(subject.accept).to be_nil
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
context 'extract data' do
|
45
|
+
let(:hash) { {:data => 'foobar'} }
|
46
|
+
|
47
|
+
it { expect(subject.data).to eql('foobar') }
|
48
|
+
end
|
49
|
+
|
50
|
+
context 'merges defaults' do
|
51
|
+
let(:hash) { { :homepage => "https://tty.github.io" }}
|
52
|
+
let(:defaults) {
|
53
|
+
{ "homepage" => "https://github.com",
|
54
|
+
"private" => false}
|
55
|
+
}
|
56
|
+
|
57
|
+
it 'correctly updates values' do
|
58
|
+
subject.merge_default(defaults)
|
59
|
+
expect(subject['homepage']).to eql("https://tty.github.io")
|
60
|
+
expect(subject['private']).to be_false
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
end
|
@@ -28,7 +28,7 @@ describe Github::PullRequests, '#list' do
|
|
28
28
|
|
29
29
|
it "should get the resources" do
|
30
30
|
subject.list user, repo, inputs
|
31
|
-
a_get(request_path).with(:query => inputs).should have_been_made
|
31
|
+
a_get(request_path).with(:query => inputs.except('unrelated')).should have_been_made
|
32
32
|
end
|
33
33
|
|
34
34
|
it_should_behave_like 'an array of resources' do
|
@@ -0,0 +1,25 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Statistics, '#code_frequency' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/stats/code_frequency" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).to_return(:body => body)
|
12
|
+
}
|
13
|
+
|
14
|
+
context "resource found" do
|
15
|
+
let(:body) { fixture('repos/frequency.json') }
|
16
|
+
let(:status) { 200 }
|
17
|
+
|
18
|
+
it { expect { subject.code_frequency }.to raise_error(ArgumentError) }
|
19
|
+
|
20
|
+
it "should get the resources" do
|
21
|
+
subject.code_frequency user, repo
|
22
|
+
a_get(request_path).should have_been_made
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
@@ -0,0 +1,29 @@
|
|
1
|
+
# encoding: utf-8
|
2
|
+
|
3
|
+
require 'spec_helper'
|
4
|
+
|
5
|
+
describe Github::Repos::Statistics, '#commit_activity' do
|
6
|
+
let(:user) { 'peter-murach' }
|
7
|
+
let(:repo) { 'github' }
|
8
|
+
let(:request_path) { "/repos/#{user}/#{repo}/stats/commit_activity" }
|
9
|
+
|
10
|
+
before {
|
11
|
+
stub_get(request_path).to_return(:body => body)
|
12
|
+
}
|
13
|
+
|
14
|
+
context "resource found" do
|
15
|
+
let(:body) { fixture('repos/commit_activity.json') }
|
16
|
+
let(:status) { 200 }
|
17
|
+
|
18
|
+
it { expect { subject.commit_activity }.to raise_error(ArgumentError) }
|
19
|
+
|
20
|
+
it "should get the resources" do
|
21
|
+
subject.commit_activity user, repo
|
22
|
+
a_get(request_path).should have_been_made
|
23
|
+
end
|
24
|
+
|
25
|
+
it_should_behave_like 'an array of resources' do
|
26
|
+
let(:requestable) { subject.commit_activity user, repo }
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|