github_api 0.12.1 → 0.12.2
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/github_api.rb +1 -0
- data/lib/github_api/client/issues/milestones.rb +1 -1
- data/lib/github_api/client/pull_requests.rb +1 -1
- data/lib/github_api/core_ext/hash.rb +2 -3
- data/lib/github_api/core_ext/ordered_hash.rb +1 -1
- data/lib/github_api/error/client_error.rb +6 -3
- data/lib/github_api/page_iterator.rb +41 -61
- data/lib/github_api/page_links.rb +34 -20
- data/lib/github_api/pagination.rb +2 -2
- data/lib/github_api/request/oauth2.rb +1 -1
- data/lib/github_api/version.rb +1 -1
- data/spec/github/core_ext/hash_spec.rb +3 -0
- data/spec/github/error/client_error_spec.rb +22 -0
- data/spec/github/pagination/iterator/number_spec.rb +50 -45
- data/spec/github/pagination/iterator/sha_spec.rb +20 -21
- data/spec/github/request/oauth2_spec.rb +3 -3
- data/spec/spec_helper.rb +0 -8
- metadata +19 -19
data/lib/github_api.rb
CHANGED
@@ -11,9 +11,8 @@ class Hash # :nodoc:
|
|
11
11
|
# Similar to except but modifies self
|
12
12
|
#
|
13
13
|
def except!(*keys)
|
14
|
-
|
15
|
-
|
16
|
-
copy
|
14
|
+
keys.each { |key| delete(key) }
|
15
|
+
self
|
17
16
|
end unless method_defined? :except!
|
18
17
|
|
19
18
|
# Returns a new hash with all the keys converted to symbols
|
@@ -11,9 +11,12 @@ module Github #:nodoc
|
|
11
11
|
end
|
12
12
|
|
13
13
|
def generate_message(attributes)
|
14
|
-
|
15
|
-
|
16
|
-
|
14
|
+
@problem = attributes[:problem]
|
15
|
+
@summary = attributes[:summary]
|
16
|
+
@resolution = attributes[:resolution]
|
17
|
+
"\nProblem:\n #{@problem}"+
|
18
|
+
"\nSummary:\n #{@summary}"+
|
19
|
+
"\nResolution:\n #{@resolution}"
|
17
20
|
end
|
18
21
|
end
|
19
22
|
end # Error
|
@@ -4,13 +4,18 @@ require 'github_api/utils/url'
|
|
4
4
|
require 'uri'
|
5
5
|
|
6
6
|
module Github
|
7
|
+
# A class responsible for requesting resources through page links
|
8
|
+
#
|
9
|
+
# @api private
|
7
10
|
class PageIterator
|
8
11
|
include Github::Constants
|
9
12
|
include Github::Utils::Url
|
10
13
|
include Github::PagedRequest
|
11
14
|
|
12
15
|
# Setup attribute accesor for all the link types
|
13
|
-
ATTRIBUTES = [
|
16
|
+
ATTRIBUTES = [META_FIRST, META_NEXT, META_PREV, META_LAST]
|
17
|
+
|
18
|
+
DEFAULT_SHA = 'master'
|
14
19
|
|
15
20
|
ATTRIBUTES.each do |attr|
|
16
21
|
attr_accessor :"#{attr}_page_uri", :"#{attr}_page"
|
@@ -21,82 +26,39 @@ module Github
|
|
21
26
|
def initialize(links, current_api)
|
22
27
|
@links = links
|
23
28
|
@current_api = current_api
|
24
|
-
update_page_links
|
29
|
+
update_page_links(@links)
|
25
30
|
end
|
26
31
|
|
27
|
-
def
|
32
|
+
def next?
|
28
33
|
next_page == 0 || !next_page_uri.nil?
|
29
34
|
end
|
30
35
|
|
31
36
|
def count
|
32
|
-
|
33
|
-
parse_query(URI(last_page_uri).query)['page']
|
37
|
+
parse_query(URI(last_page_uri).query)['page'] if last_page_uri
|
34
38
|
end
|
35
39
|
|
36
40
|
# Perform http get request for the first resource
|
37
41
|
#
|
38
42
|
def first
|
39
|
-
|
40
|
-
page_uri = URI(first_page_uri)
|
41
|
-
params = parse_query(page_uri.query)
|
42
|
-
if next_page < 1
|
43
|
-
params['sha'] = 'master' if params.keys.include?('sha')
|
44
|
-
params['per_page'] = parse_per_page_number(first_page_uri)
|
45
|
-
else
|
46
|
-
params['page'] = parse_page_number(first_page_uri)
|
47
|
-
params['per_page'] = parse_per_page_number(first_page_uri)
|
48
|
-
end
|
49
|
-
|
50
|
-
response = page_request(page_uri.path, params)
|
51
|
-
update_page_links response.links
|
52
|
-
response
|
43
|
+
perform_request(first_page_uri) if first_page_uri
|
53
44
|
end
|
54
45
|
|
55
46
|
# Perform http get request for the next resource
|
56
47
|
#
|
57
48
|
def next
|
58
|
-
|
59
|
-
page_uri = URI(next_page_uri)
|
60
|
-
params = parse_query(page_uri.query)
|
61
|
-
if next_page < 1
|
62
|
-
params['sha'] = params['last_sha'] if params.keys.include?('last_sha')
|
63
|
-
params['per_page'] = parse_per_page_number(next_page_uri)
|
64
|
-
else
|
65
|
-
params['page'] = parse_page_number(next_page_uri)
|
66
|
-
params['per_page'] = parse_per_page_number(next_page_uri)
|
67
|
-
end
|
68
|
-
|
69
|
-
response = page_request(page_uri.path, params)
|
70
|
-
update_page_links response.links
|
71
|
-
response
|
49
|
+
perform_request(next_page_uri) if next?
|
72
50
|
end
|
73
51
|
|
74
52
|
# Perform http get request for the previous resource
|
75
53
|
#
|
76
54
|
def prev
|
77
|
-
|
78
|
-
page_uri = URI(prev_page_uri)
|
79
|
-
params = parse_query(page_uri.query)
|
80
|
-
params['page'] = parse_page_number(prev_page_uri)
|
81
|
-
params['per_page'] = parse_per_page_number(prev_page_uri)
|
82
|
-
|
83
|
-
response = page_request(page_uri.path, params)
|
84
|
-
update_page_links response.links
|
85
|
-
response
|
55
|
+
perform_request(prev_page_uri) if prev_page_uri
|
86
56
|
end
|
87
57
|
|
88
58
|
# Perform http get request for the last resource
|
89
59
|
#
|
90
60
|
def last
|
91
|
-
|
92
|
-
page_uri = URI(last_page_uri)
|
93
|
-
params = parse_query(page_uri.query)
|
94
|
-
params['page'] = parse_page_number(last_page_uri)
|
95
|
-
params['per_page'] = parse_per_page_number(last_page_uri)
|
96
|
-
|
97
|
-
response = page_request(page_uri.path, params)
|
98
|
-
update_page_links response.links
|
99
|
-
response
|
61
|
+
perform_request(last_page_uri) if last_page_uri
|
100
62
|
end
|
101
63
|
|
102
64
|
# Returns the result for a specific page.
|
@@ -106,16 +68,35 @@ module Github
|
|
106
68
|
# last page URI then there is only one page.
|
107
69
|
page_uri = first_page_uri || last_page_uri
|
108
70
|
return nil unless page_uri
|
109
|
-
params = parse_query URI(page_uri).query
|
110
|
-
params['page'] = page_number
|
111
|
-
params['per_page'] = parse_per_page_number(page_uri)
|
112
71
|
|
113
|
-
|
72
|
+
perform_request(page_uri, page_number)
|
73
|
+
end
|
74
|
+
|
75
|
+
private
|
76
|
+
|
77
|
+
def perform_request(page_uri_path, page_number = nil)
|
78
|
+
page_uri = URI(page_uri_path)
|
79
|
+
params = parse_query(page_uri.query)
|
80
|
+
|
81
|
+
if page_number
|
82
|
+
params['page'] = page_number
|
83
|
+
elsif next_page < 1
|
84
|
+
sha = sha(params)
|
85
|
+
params['sha'] = sha if sha
|
86
|
+
else
|
87
|
+
params['page'] = parse_page_number(page_uri_path)
|
88
|
+
end
|
89
|
+
params['per_page'] = parse_per_page_number(page_uri_path)
|
90
|
+
|
91
|
+
response = page_request(page_uri.path, params)
|
114
92
|
update_page_links response.links
|
115
93
|
response
|
116
94
|
end
|
117
95
|
|
118
|
-
|
96
|
+
def sha(params)
|
97
|
+
return params['last_sha'] if params.keys.include?('last_sha')
|
98
|
+
return DEFAULT_SHA if params.keys.include?('sha')
|
99
|
+
end
|
119
100
|
|
120
101
|
def parse_per_page_number(uri) # :nodoc:
|
121
102
|
parse_page_params(uri, PARAM_PER_PAGE)
|
@@ -131,14 +112,14 @@ module Github
|
|
131
112
|
parsed = nil
|
132
113
|
begin
|
133
114
|
parsed = URI.parse(uri)
|
134
|
-
rescue URI::Error
|
115
|
+
rescue URI::Error
|
135
116
|
return -1
|
136
117
|
end
|
137
118
|
param = parse_query_for_param(parsed.query, attr)
|
138
119
|
return -1 if param.nil? || param.empty?
|
139
120
|
begin
|
140
121
|
return param.to_i
|
141
|
-
rescue ArgumentError
|
122
|
+
rescue ArgumentError
|
142
123
|
return -1
|
143
124
|
end
|
144
125
|
end
|
@@ -146,10 +127,9 @@ module Github
|
|
146
127
|
# Wholesale update of all link attributes
|
147
128
|
def update_page_links(links) # :nodoc:
|
148
129
|
ATTRIBUTES.each do |attr|
|
149
|
-
|
150
|
-
|
130
|
+
send(:"#{attr}_page_uri=", links.send(:"#{attr}"))
|
131
|
+
send(:"#{attr}_page=", parse_page_number(links.send(:"#{attr}")))
|
151
132
|
end
|
152
133
|
end
|
153
|
-
|
154
134
|
end # PageIterator
|
155
135
|
end # Github
|
@@ -2,38 +2,28 @@ module Github
|
|
2
2
|
# Determines the links in the current response link header to be used
|
3
3
|
# to find the links to other pages of request responses. These will
|
4
4
|
# only be present if the result set size exceeds the per page limit.
|
5
|
+
#
|
6
|
+
# @api private
|
5
7
|
class PageLinks
|
6
8
|
include Github::Constants
|
7
9
|
|
8
|
-
DELIM_LINKS =
|
10
|
+
DELIM_LINKS = ','.freeze # :nodoc:
|
9
11
|
|
10
12
|
# Hold the extracted values for URI from the Link header
|
11
13
|
# for the first, last, next and previous page.
|
12
14
|
attr_accessor :first, :last, :next, :prev
|
13
15
|
|
16
|
+
LINK_REGEX = /<([^>]+)>; rel=\"([^\"]+)\"/
|
17
|
+
|
14
18
|
# Parses links from executed request
|
15
19
|
#
|
20
|
+
# @param [Hash] response_headers
|
21
|
+
#
|
22
|
+
# @api private
|
16
23
|
def initialize(response_headers)
|
17
24
|
link_header = response_headers[HEADER_LINK]
|
18
|
-
if link_header
|
19
|
-
|
20
|
-
|
21
|
-
link_header.split(DELIM_LINKS).each do |link|
|
22
|
-
if link.strip =~ /<([^>]+)>; rel=\"([^\"]+)\"/
|
23
|
-
url_part, meta_part = $1, $2
|
24
|
-
next if !url_part || !meta_part
|
25
|
-
case meta_part
|
26
|
-
when META_FIRST
|
27
|
-
self.first = url_part
|
28
|
-
when META_LAST
|
29
|
-
self.last = url_part
|
30
|
-
when META_NEXT
|
31
|
-
self.next = url_part
|
32
|
-
when META_PREV
|
33
|
-
self.prev = url_part
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
25
|
+
if link_header && link_header =~ /(next|first|last|prev)/
|
26
|
+
extract_links(link_header)
|
37
27
|
else
|
38
28
|
# When on the first page
|
39
29
|
self.next = response_headers[HEADER_NEXT]
|
@@ -41,5 +31,29 @@ module Github
|
|
41
31
|
end
|
42
32
|
end
|
43
33
|
|
34
|
+
private
|
35
|
+
|
36
|
+
def extract_links(link_header)
|
37
|
+
link_header.split(DELIM_LINKS).each do |link|
|
38
|
+
LINK_REGEX.match(link.strip) do |match|
|
39
|
+
url_part, meta_part = match[1], match[2]
|
40
|
+
next if !url_part || !meta_part
|
41
|
+
assign_url_part(meta_part, url_part)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
def assign_url_part(meta_part, url_part)
|
47
|
+
case meta_part
|
48
|
+
when META_FIRST
|
49
|
+
self.first = url_part
|
50
|
+
when META_LAST
|
51
|
+
self.last = url_part
|
52
|
+
when META_NEXT
|
53
|
+
self.next = url_part
|
54
|
+
when META_PREV
|
55
|
+
self.prev = url_part
|
56
|
+
end
|
57
|
+
end
|
44
58
|
end # PageLinks
|
45
59
|
end # Github
|
@@ -35,7 +35,7 @@ module Github
|
|
35
35
|
# iterate over this method will return current page.
|
36
36
|
def each_page
|
37
37
|
yield self
|
38
|
-
while page_iterator.
|
38
|
+
while page_iterator.next?
|
39
39
|
yield next_page
|
40
40
|
end
|
41
41
|
end
|
@@ -88,7 +88,7 @@ module Github
|
|
88
88
|
# Returns <tt>true</tt> if there is another page in the result set,
|
89
89
|
# otherwise <tt>false</tt>
|
90
90
|
def has_next_page?
|
91
|
-
page_iterator.
|
91
|
+
page_iterator.next?
|
92
92
|
end
|
93
93
|
|
94
94
|
private
|
@@ -18,7 +18,7 @@ module Github
|
|
18
18
|
|
19
19
|
if token = params[ACCESS_TOKEN] and !token.empty?
|
20
20
|
env[:url].query = build_query params
|
21
|
-
env[:request_headers].merge!(AUTH_HEADER => "
|
21
|
+
env[:request_headers].merge!(AUTH_HEADER => "token #{token}")
|
22
22
|
end
|
23
23
|
|
24
24
|
@app.call env
|
data/lib/github_api/version.rb
CHANGED
@@ -24,5 +24,27 @@ describe Github::Error::ClientError do
|
|
24
24
|
it 'generates resolution line' do
|
25
25
|
error.generate_message(attributes).should include "Resolution:\n Glue it!"
|
26
26
|
end
|
27
|
+
|
28
|
+
before do
|
29
|
+
error.generate_message(attributes)
|
30
|
+
end
|
31
|
+
|
32
|
+
describe '#problem' do
|
33
|
+
it 'returns problem' do
|
34
|
+
error.problem.should eq attributes[:problem]
|
35
|
+
end
|
36
|
+
end
|
37
|
+
|
38
|
+
describe '#summary' do
|
39
|
+
it 'returns summary' do
|
40
|
+
error.summary.should eq attributes[:summary]
|
41
|
+
end
|
42
|
+
end
|
43
|
+
|
44
|
+
describe '#resolution' do
|
45
|
+
it 'returns resolution' do
|
46
|
+
error.resolution.should eq attributes[:resolution]
|
47
|
+
end
|
48
|
+
end
|
27
49
|
end
|
28
50
|
end # Github::Error::ClientError
|
@@ -3,116 +3,121 @@
|
|
3
3
|
require 'spec_helper'
|
4
4
|
|
5
5
|
describe Github::PageIterator, 'when number' do
|
6
|
-
let(:header) { {
|
7
|
-
|
8
|
-
|
6
|
+
let(:header) { {
|
7
|
+
"Link" => "<https://api.github.com/users/wycats/repos?page=4&per_page=20>; rel=\"next\", <https://api.github.com/users/wycats/repos?page=6&per_page=20>; rel=\"last\", <https://api.github.com/users/wycats/repos?page=1&per_page=20>; rel=\"first\", <https://api.github.com/users/wycats/repos?page=2&per_page=20>; rel=\"prev\""
|
8
|
+
} }
|
9
9
|
|
10
10
|
let(:first_link) { "https://api.github.com/users/wycats/repos?page=1&per_page=20" }
|
11
11
|
let(:next_link) { "https://api.github.com/users/wycats/repos?page=4&per_page=20" }
|
12
12
|
let(:prev_link) { "https://api.github.com/users/wycats/repos?page=2&per_page=20" }
|
13
13
|
let(:last_link) { "https://api.github.com/users/wycats/repos?page=6&per_page=20" }
|
14
14
|
|
15
|
+
let(:links) { Github::PageLinks.new(header) }
|
15
16
|
let(:current_api) { Github::Client::Repos.new }
|
16
|
-
let(:user)
|
17
|
-
let(:response)
|
17
|
+
let(:user) { 'wycats' }
|
18
|
+
let(:response) { double(:response).as_null_object }
|
18
19
|
|
19
|
-
subject(:
|
20
|
+
subject(:iterator) { described_class.new(links, current_api) }
|
20
21
|
|
21
22
|
before {
|
22
|
-
|
23
|
+
allow(iterator).to receive(:next?).and_return(true)
|
23
24
|
stub_get("/users/#{user}/repos").
|
24
|
-
with(:
|
25
|
+
with(query: { 'page' => '4', 'per_page' => '20'}).
|
25
26
|
to_return(:body => '', :status => 200, :headers => header)
|
26
27
|
}
|
27
28
|
|
28
29
|
it { described_class::ATTRIBUTES.should_not be_nil }
|
29
30
|
|
30
|
-
|
31
|
+
it { expect(iterator.first_page).to eq(1) }
|
31
32
|
|
32
|
-
|
33
|
+
it { expect(iterator.first_page_uri).to eq(first_link) }
|
33
34
|
|
34
|
-
|
35
|
+
it { expect(iterator.next_page).to eq(4)}
|
35
36
|
|
36
|
-
|
37
|
+
it { expect(iterator.next_page_uri).to eq(next_link) }
|
37
38
|
|
38
|
-
|
39
|
+
it { expect(iterator.prev_page).to eq(2)}
|
39
40
|
|
40
|
-
|
41
|
+
it { expect(iterator.prev_page_uri).to eq(prev_link) }
|
41
42
|
|
42
|
-
|
43
|
+
it { expect(iterator.last_page).to eq(6)}
|
43
44
|
|
44
|
-
|
45
|
+
it { expect(iterator.last_page_uri).to eq(last_link) }
|
45
46
|
|
46
|
-
context '
|
47
|
-
it "
|
48
|
-
expect(
|
47
|
+
context 'next?' do
|
48
|
+
it "returns true when next_page_uri is present" do
|
49
|
+
expect(iterator.next?).to eq(true)
|
49
50
|
end
|
50
51
|
end
|
51
52
|
|
52
53
|
context 'first page request' do
|
53
54
|
it 'returns nil if there are no more pages' do
|
54
|
-
|
55
|
-
expect(
|
55
|
+
allow(iterator).to receive(:first_page_uri).and_return(false)
|
56
|
+
expect(iterator.first).to be_nil
|
56
57
|
end
|
57
58
|
|
58
59
|
it 'performs request' do
|
59
|
-
|
60
|
+
expect(iterator).to receive(:page_request).
|
60
61
|
with("/users/#{user}/repos", 'per_page' => 20, 'page' => 1).
|
61
|
-
and_return
|
62
|
-
|
62
|
+
and_return(response)
|
63
|
+
iterator.first
|
63
64
|
end
|
64
65
|
end
|
65
66
|
|
66
67
|
context 'next page request' do
|
67
68
|
it 'returns nil if there are no more pages' do
|
68
|
-
|
69
|
-
expect(
|
69
|
+
allow(iterator).to receive(:next?).and_return(false)
|
70
|
+
expect(iterator.next).to be_nil
|
70
71
|
end
|
71
72
|
|
72
73
|
it 'performs request' do
|
73
|
-
|
74
|
-
|
75
|
-
|
74
|
+
expect(iterator).to receive(:page_request).
|
75
|
+
with("/users/#{user}/repos", 'page' => 4,'per_page' => 20).
|
76
|
+
and_return(response)
|
77
|
+
iterator.next
|
76
78
|
end
|
77
79
|
end
|
78
80
|
|
79
81
|
context 'prev page request' do
|
80
82
|
it 'returns nil if there are no more pages' do
|
81
|
-
|
82
|
-
expect(
|
83
|
+
allow(iterator).to receive(:prev_page_uri).and_return(false)
|
84
|
+
expect(iterator.prev).to be_nil
|
83
85
|
end
|
84
86
|
|
85
87
|
it 'performs request' do
|
86
|
-
|
87
|
-
|
88
|
-
|
88
|
+
expect(iterator).to receive(:page_request).
|
89
|
+
with("/users/#{user}/repos", 'page' => 2,'per_page' => 20).
|
90
|
+
and_return(response)
|
91
|
+
iterator.prev
|
89
92
|
end
|
90
93
|
end
|
91
94
|
|
92
95
|
context 'last page request' do
|
93
96
|
it 'returns nil if there are no more pages' do
|
94
|
-
|
95
|
-
expect(
|
97
|
+
allow(iterator).to receive(:last_page_uri).and_return(false)
|
98
|
+
expect(iterator.last).to be_nil
|
96
99
|
end
|
97
100
|
|
98
101
|
it 'performs request' do
|
99
|
-
|
100
|
-
|
101
|
-
|
102
|
+
expect(iterator).to receive(:page_request).
|
103
|
+
with("/users/#{user}/repos", 'page' => 6,'per_page' => 20).
|
104
|
+
and_return(response)
|
105
|
+
iterator.last
|
102
106
|
end
|
103
107
|
end
|
104
108
|
|
105
109
|
context 'get_page request' do
|
106
110
|
it 'returns nil if there are no more pages' do
|
107
|
-
|
108
|
-
|
109
|
-
expect(
|
111
|
+
allow(iterator).to receive(:first_page_uri).and_return(nil)
|
112
|
+
allow(iterator).to receive(:last_page_uri).and_return(nil)
|
113
|
+
expect(iterator.get_page(5)).to be_nil
|
110
114
|
end
|
111
115
|
|
112
116
|
it 'performs request' do
|
113
|
-
|
114
|
-
|
115
|
-
|
117
|
+
expect(iterator).to receive(:page_request).
|
118
|
+
with("/users/#{user}/repos", 'page' => 2,'per_page' => 20).
|
119
|
+
and_return(response)
|
120
|
+
iterator.get_page(2)
|
116
121
|
end
|
117
122
|
end
|
118
123
|
end
|
@@ -5,7 +5,6 @@ require 'spec_helper'
|
|
5
5
|
describe Github::PageIterator, 'when sha' do
|
6
6
|
let(:header) { {"Link" => "<https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"next\", <https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd>; rel=\"first\"" }
|
7
7
|
}
|
8
|
-
let(:links) { Github::PageLinks.new(header) }
|
9
8
|
|
10
9
|
let(:first_link) { "https://api.github.com/repos/peter-murach/github/commits?per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
|
11
10
|
let(:next_link) { "https://api.github.com/repos/peter-murach/github/commits?last_sha=d1e503c02fa770859895dd0d12aedefa28b95723&per_page=30&sha=801d80dfd59bf1d2cb30a243799953ab683a3abd&top=801d80dfd59bf1d2cb30a243799953ab683a3abd" }
|
@@ -14,54 +13,54 @@ describe Github::PageIterator, 'when sha' do
|
|
14
13
|
let(:sha) { '801d80dfd59bf1d2cb30a243799953ab683a3abd' }
|
15
14
|
let(:last_sha) { "d1e503c02fa770859895dd0d12aedefa28b95723"}
|
16
15
|
|
16
|
+
let(:links) { Github::PageLinks.new(header) }
|
17
17
|
let(:current_api) { Github::Client::Repos.new }
|
18
18
|
let(:user) { 'wycats' }
|
19
19
|
let(:response) { double(:response).as_null_object }
|
20
20
|
|
21
|
-
subject(:
|
21
|
+
subject(:iterator) { described_class.new(links, current_api) }
|
22
22
|
|
23
23
|
before {
|
24
|
-
|
25
|
-
|
24
|
+
allow(iterator).to receive(:next?).and_return(true)
|
25
|
+
allow(iterator).to receive(:next_page).and_return(-1)
|
26
26
|
stub_get("/repos/peter-murach/github/commits").
|
27
|
-
to_return(:
|
27
|
+
to_return(body: '', status: 200, headers: header)
|
28
28
|
}
|
29
29
|
|
30
|
-
it { described_class::ATTRIBUTES.
|
30
|
+
it { expect(described_class::ATTRIBUTES).to_not be_nil }
|
31
31
|
|
32
|
-
|
32
|
+
it { expect(iterator.first_page).to eq(-1) }
|
33
33
|
|
34
|
-
|
34
|
+
it { expect(iterator.first_page_uri).to eq(first_link) }
|
35
35
|
|
36
|
-
|
36
|
+
it { expect(iterator.next_page).to eq(-1) }
|
37
37
|
|
38
|
-
|
38
|
+
it { expect(iterator.next_page_uri).to eq(next_link) }
|
39
39
|
|
40
|
-
|
40
|
+
it { expect(iterator.prev_page).to eq(-1) }
|
41
41
|
|
42
|
-
|
42
|
+
it { expect(iterator.prev_page_uri).to be_nil }
|
43
43
|
|
44
|
-
|
44
|
+
it { expect(iterator.last_page).to eq(-1) }
|
45
45
|
|
46
|
-
|
46
|
+
it { expect(iterator.last_page_uri).to be_nil }
|
47
47
|
|
48
48
|
context 'first page request' do
|
49
49
|
it 'performs request' do
|
50
|
-
|
50
|
+
expect(iterator).to receive(:page_request).
|
51
51
|
with("/repos/peter-murach/github/commits",
|
52
|
-
'sha' => 'master', 'per_page' => 30).and_return
|
53
|
-
|
52
|
+
'sha' => 'master', 'per_page' => 30).and_return(response)
|
53
|
+
iterator.first
|
54
54
|
end
|
55
55
|
end
|
56
56
|
|
57
57
|
context 'next page request' do
|
58
58
|
it 'performs request' do
|
59
|
-
|
59
|
+
expect(iterator).to receive(:page_request).
|
60
60
|
with("/repos/peter-murach/github/commits", 'last_sha' => last_sha,
|
61
61
|
'sha' => last_sha, 'per_page' => 30, 'top' => top_sha).
|
62
|
-
and_return
|
63
|
-
|
62
|
+
and_return(response)
|
63
|
+
iterator.next
|
64
64
|
end
|
65
65
|
end
|
66
|
-
|
67
66
|
end
|
@@ -40,7 +40,7 @@ describe Github::Request::OAuth2 do
|
|
40
40
|
|
41
41
|
it "creates header for ad hoc access token" do
|
42
42
|
result = process(:q => 'query', :access_token => 'abc123')
|
43
|
-
auth_header(result).should eql '
|
43
|
+
auth_header(result).should eql 'token abc123'
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
@@ -53,13 +53,13 @@ describe Github::Request::OAuth2 do
|
|
53
53
|
end
|
54
54
|
|
55
55
|
it "creates header for access token" do
|
56
|
-
auth_header(process).should eql '
|
56
|
+
auth_header(process).should eql 'token ABC'
|
57
57
|
end
|
58
58
|
|
59
59
|
it "overrides default with explicit token" do
|
60
60
|
result = process(:q => 'query', :access_token => 'abc123')
|
61
61
|
result[:url].query.should eql 'access_token=abc123&q=query'
|
62
|
-
auth_header(result).should eql '
|
62
|
+
auth_header(result).should eql 'token abc123'
|
63
63
|
end
|
64
64
|
|
65
65
|
it "clears default token with explicit one" do
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: github_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-
|
12
|
+
date: 2014-10-25 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: addressable
|
16
|
-
requirement: &
|
16
|
+
requirement: &2152983460 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ~>
|
@@ -21,21 +21,21 @@ dependencies:
|
|
21
21
|
version: '2.3'
|
22
22
|
type: :runtime
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2152983460
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: hashie
|
27
|
-
requirement: &
|
27
|
+
requirement: &2152956600 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
31
31
|
- !ruby/object:Gem::Version
|
32
|
-
version: '3.
|
32
|
+
version: '3.3'
|
33
33
|
type: :runtime
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2152956600
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: faraday
|
38
|
-
requirement: &
|
38
|
+
requirement: &2152951920 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ~>
|
@@ -46,10 +46,10 @@ dependencies:
|
|
46
46
|
version: '0.10'
|
47
47
|
type: :runtime
|
48
48
|
prerelease: false
|
49
|
-
version_requirements: *
|
49
|
+
version_requirements: *2152951920
|
50
50
|
- !ruby/object:Gem::Dependency
|
51
51
|
name: multi_json
|
52
|
-
requirement: &
|
52
|
+
requirement: &2152948760 !ruby/object:Gem::Requirement
|
53
53
|
none: false
|
54
54
|
requirements:
|
55
55
|
- - ! '>='
|
@@ -60,10 +60,10 @@ dependencies:
|
|
60
60
|
version: '2.0'
|
61
61
|
type: :runtime
|
62
62
|
prerelease: false
|
63
|
-
version_requirements: *
|
63
|
+
version_requirements: *2152948760
|
64
64
|
- !ruby/object:Gem::Dependency
|
65
65
|
name: oauth2
|
66
|
-
requirement: &
|
66
|
+
requirement: &2152947000 !ruby/object:Gem::Requirement
|
67
67
|
none: false
|
68
68
|
requirements:
|
69
69
|
- - ! '>='
|
@@ -71,10 +71,10 @@ dependencies:
|
|
71
71
|
version: '0'
|
72
72
|
type: :runtime
|
73
73
|
prerelease: false
|
74
|
-
version_requirements: *
|
74
|
+
version_requirements: *2152947000
|
75
75
|
- !ruby/object:Gem::Dependency
|
76
76
|
name: nokogiri
|
77
|
-
requirement: &
|
77
|
+
requirement: &2152945040 !ruby/object:Gem::Requirement
|
78
78
|
none: false
|
79
79
|
requirements:
|
80
80
|
- - ~>
|
@@ -82,10 +82,10 @@ dependencies:
|
|
82
82
|
version: 1.6.3
|
83
83
|
type: :runtime
|
84
84
|
prerelease: false
|
85
|
-
version_requirements: *
|
85
|
+
version_requirements: *2152945040
|
86
86
|
- !ruby/object:Gem::Dependency
|
87
87
|
name: descendants_tracker
|
88
|
-
requirement: &
|
88
|
+
requirement: &2152942960 !ruby/object:Gem::Requirement
|
89
89
|
none: false
|
90
90
|
requirements:
|
91
91
|
- - ~>
|
@@ -93,10 +93,10 @@ dependencies:
|
|
93
93
|
version: 0.0.4
|
94
94
|
type: :runtime
|
95
95
|
prerelease: false
|
96
|
-
version_requirements: *
|
96
|
+
version_requirements: *2152942960
|
97
97
|
- !ruby/object:Gem::Dependency
|
98
98
|
name: bundler
|
99
|
-
requirement: &
|
99
|
+
requirement: &2152934400 !ruby/object:Gem::Requirement
|
100
100
|
none: false
|
101
101
|
requirements:
|
102
102
|
- - ~>
|
@@ -104,7 +104,7 @@ dependencies:
|
|
104
104
|
version: '1.5'
|
105
105
|
type: :development
|
106
106
|
prerelease: false
|
107
|
-
version_requirements: *
|
107
|
+
version_requirements: *2152934400
|
108
108
|
description: ! ' Ruby client that supports all of the GitHub API methods. It''s build
|
109
109
|
in a modular way, that is, you can either instantiate the whole api wrapper Github.new
|
110
110
|
or use parts of it e.i. Github::Client::Repos.new if working solely with repositories
|