footrest 0.4.1 → 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/footrest.gemspec +0 -5
- data/lib/footrest/pagination.rb +16 -2
- data/lib/footrest/version.rb +2 -2
- data/spec/footrest/pagination_spec.rb +28 -11
- data/spec/spec_helper.rb +2 -3
- metadata +24 -59
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 2d9f5d760ae83f164678724a9ecfd76f4df5336e
|
4
|
+
data.tar.gz: ed689789278afacb33efde02088ee327a10eb67f
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 45bec9c171db1ada2ae5705b75a17cf1631aaba8b06649213d1b385fbcbf30e46f4975fd0ff4721f86beea111e5e887dc8e357c6ec50162e6d6f6db2102953b9
|
7
|
+
data.tar.gz: cd1533a1211613833447f82887c859cfcff40aeb9c3fcaf61456258ecc3027734d7793c2ef317ce5388c89634f1c0108dde98ad559af8ec17565e50813413356
|
data/footrest.gemspec
CHANGED
@@ -24,11 +24,6 @@ Gem::Specification.new do |gem|
|
|
24
24
|
gem.add_development_dependency "rspec", "~> 2.6"
|
25
25
|
gem.add_development_dependency "webmock"
|
26
26
|
gem.add_development_dependency "pry"
|
27
|
-
if RUBY_VERSION < '2.0'
|
28
|
-
gem.add_development_dependency "debugger"
|
29
|
-
else
|
30
|
-
gem.add_development_dependency "byebug"
|
31
|
-
end
|
32
27
|
|
33
28
|
gem.add_dependency "faraday", "~> 0.9.0"
|
34
29
|
gem.add_dependency "activesupport", ">= 3.0.0"
|
data/lib/footrest/pagination.rb
CHANGED
@@ -2,12 +2,26 @@ require 'link_header'
|
|
2
2
|
|
3
3
|
module Footrest
|
4
4
|
class Pagination < Faraday::Response::Middleware
|
5
|
+
Links = Struct.new(:first, :prev, :current, :next, :last) do
|
6
|
+
alias_method :previous, :prev
|
7
|
+
alias_method :prevous=, :prev=
|
8
|
+
|
9
|
+
def last_page?
|
10
|
+
return false unless self.current && self.last
|
11
|
+
self.current == self.last
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
5
15
|
def on_complete(response)
|
6
16
|
if response[:response_headers]
|
7
|
-
if
|
17
|
+
if link_header = response[:response_headers][:link]
|
18
|
+
links = Links.new
|
8
19
|
%w(prev next first last current).each do |page|
|
9
|
-
|
20
|
+
link = find_link(link_header, page)
|
21
|
+
response["#{page}_page".to_sym] = link
|
22
|
+
links.public_send("#{ page }=", link)
|
10
23
|
end
|
24
|
+
response[:pagination_links] = links
|
11
25
|
end
|
12
26
|
end
|
13
27
|
end
|
data/lib/footrest/version.rb
CHANGED
@@ -1,3 +1,3 @@
|
|
1
1
|
module Footrest
|
2
|
-
VERSION = '0.
|
3
|
-
end
|
2
|
+
VERSION = '0.5.0' unless defined?(Footrest::VERSION)
|
3
|
+
end
|
@@ -1,20 +1,37 @@
|
|
1
|
-
|
1
|
+
require 'spec_helper'
|
2
2
|
|
3
|
-
|
3
|
+
module Footrest
|
4
|
+
describe Pagination do
|
4
5
|
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
6
|
+
describe "#on_complete" do
|
7
|
+
let(:response) {
|
8
|
+
{
|
9
|
+
response_headers: {
|
10
|
+
link: "<current_link>; rel=\"current\",<next_link>; rel=\"next\",<prev_link>; rel=\"prev\",<first_link>; rel=\"first\",<last_link>; rel=\"last\""
|
11
|
+
}
|
10
12
|
}
|
11
13
|
}
|
12
14
|
|
13
|
-
|
15
|
+
before do
|
16
|
+
Pagination.new.on_complete(response)
|
17
|
+
end
|
18
|
+
|
19
|
+
it 'captures prev, next, first, last, and current page links as response headers' do
|
20
|
+
%w(prev next first last current).each do |page|
|
21
|
+
expect(response["#{page}_page".to_sym]).to eq("#{page}_link")
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'must capture the pagination links in an object at the pagination_links key' do
|
26
|
+
expect(response[:pagination_links]).to be_a Pagination::Links
|
27
|
+
end
|
14
28
|
|
15
|
-
|
16
|
-
|
29
|
+
it 'must capture all of the link types in the Links object' do
|
30
|
+
obj = response[:pagination_links]
|
31
|
+
%w(prev next first last current).each do |page|
|
32
|
+
expect(obj.public_send(page)).to eq("#{page}_link")
|
33
|
+
end
|
17
34
|
end
|
18
35
|
end
|
19
36
|
end
|
20
|
-
end
|
37
|
+
end
|
data/spec/spec_helper.rb
CHANGED
metadata
CHANGED
@@ -1,8 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: footrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
5
|
-
prerelease:
|
4
|
+
version: 0.5.0
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Duane Johnson
|
@@ -10,150 +9,118 @@ authors:
|
|
10
9
|
autorequire:
|
11
10
|
bindir: bin
|
12
11
|
cert_chain: []
|
13
|
-
date: 2014-12-
|
12
|
+
date: 2014-12-22 00:00:00.000000000 Z
|
14
13
|
dependencies:
|
15
14
|
- !ruby/object:Gem::Dependency
|
16
15
|
name: rake
|
17
16
|
requirement: !ruby/object:Gem::Requirement
|
18
|
-
none: false
|
19
17
|
requirements:
|
20
|
-
- -
|
18
|
+
- - ">="
|
21
19
|
- !ruby/object:Gem::Version
|
22
20
|
version: '0'
|
23
21
|
type: :development
|
24
22
|
prerelease: false
|
25
23
|
version_requirements: !ruby/object:Gem::Requirement
|
26
|
-
none: false
|
27
24
|
requirements:
|
28
|
-
- -
|
25
|
+
- - ">="
|
29
26
|
- !ruby/object:Gem::Version
|
30
27
|
version: '0'
|
31
28
|
- !ruby/object:Gem::Dependency
|
32
29
|
name: bundler
|
33
30
|
requirement: !ruby/object:Gem::Requirement
|
34
|
-
none: false
|
35
31
|
requirements:
|
36
|
-
- -
|
32
|
+
- - ">="
|
37
33
|
- !ruby/object:Gem::Version
|
38
34
|
version: 1.0.0
|
39
35
|
type: :development
|
40
36
|
prerelease: false
|
41
37
|
version_requirements: !ruby/object:Gem::Requirement
|
42
|
-
none: false
|
43
38
|
requirements:
|
44
|
-
- -
|
39
|
+
- - ">="
|
45
40
|
- !ruby/object:Gem::Version
|
46
41
|
version: 1.0.0
|
47
42
|
- !ruby/object:Gem::Dependency
|
48
43
|
name: rspec
|
49
44
|
requirement: !ruby/object:Gem::Requirement
|
50
|
-
none: false
|
51
45
|
requirements:
|
52
|
-
- - ~>
|
46
|
+
- - "~>"
|
53
47
|
- !ruby/object:Gem::Version
|
54
48
|
version: '2.6'
|
55
49
|
type: :development
|
56
50
|
prerelease: false
|
57
51
|
version_requirements: !ruby/object:Gem::Requirement
|
58
|
-
none: false
|
59
52
|
requirements:
|
60
|
-
- - ~>
|
53
|
+
- - "~>"
|
61
54
|
- !ruby/object:Gem::Version
|
62
55
|
version: '2.6'
|
63
56
|
- !ruby/object:Gem::Dependency
|
64
57
|
name: webmock
|
65
58
|
requirement: !ruby/object:Gem::Requirement
|
66
|
-
none: false
|
67
59
|
requirements:
|
68
|
-
- -
|
60
|
+
- - ">="
|
69
61
|
- !ruby/object:Gem::Version
|
70
62
|
version: '0'
|
71
63
|
type: :development
|
72
64
|
prerelease: false
|
73
65
|
version_requirements: !ruby/object:Gem::Requirement
|
74
|
-
none: false
|
75
66
|
requirements:
|
76
|
-
- -
|
67
|
+
- - ">="
|
77
68
|
- !ruby/object:Gem::Version
|
78
69
|
version: '0'
|
79
70
|
- !ruby/object:Gem::Dependency
|
80
71
|
name: pry
|
81
72
|
requirement: !ruby/object:Gem::Requirement
|
82
|
-
none: false
|
83
73
|
requirements:
|
84
|
-
- -
|
74
|
+
- - ">="
|
85
75
|
- !ruby/object:Gem::Version
|
86
76
|
version: '0'
|
87
77
|
type: :development
|
88
78
|
prerelease: false
|
89
79
|
version_requirements: !ruby/object:Gem::Requirement
|
90
|
-
none: false
|
91
80
|
requirements:
|
92
|
-
- -
|
93
|
-
- !ruby/object:Gem::Version
|
94
|
-
version: '0'
|
95
|
-
- !ruby/object:Gem::Dependency
|
96
|
-
name: debugger
|
97
|
-
requirement: !ruby/object:Gem::Requirement
|
98
|
-
none: false
|
99
|
-
requirements:
|
100
|
-
- - ! '>='
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: '0'
|
103
|
-
type: :development
|
104
|
-
prerelease: false
|
105
|
-
version_requirements: !ruby/object:Gem::Requirement
|
106
|
-
none: false
|
107
|
-
requirements:
|
108
|
-
- - ! '>='
|
81
|
+
- - ">="
|
109
82
|
- !ruby/object:Gem::Version
|
110
83
|
version: '0'
|
111
84
|
- !ruby/object:Gem::Dependency
|
112
85
|
name: faraday
|
113
86
|
requirement: !ruby/object:Gem::Requirement
|
114
|
-
none: false
|
115
87
|
requirements:
|
116
|
-
- - ~>
|
88
|
+
- - "~>"
|
117
89
|
- !ruby/object:Gem::Version
|
118
90
|
version: 0.9.0
|
119
91
|
type: :runtime
|
120
92
|
prerelease: false
|
121
93
|
version_requirements: !ruby/object:Gem::Requirement
|
122
|
-
none: false
|
123
94
|
requirements:
|
124
|
-
- - ~>
|
95
|
+
- - "~>"
|
125
96
|
- !ruby/object:Gem::Version
|
126
97
|
version: 0.9.0
|
127
98
|
- !ruby/object:Gem::Dependency
|
128
99
|
name: activesupport
|
129
100
|
requirement: !ruby/object:Gem::Requirement
|
130
|
-
none: false
|
131
101
|
requirements:
|
132
|
-
- -
|
102
|
+
- - ">="
|
133
103
|
- !ruby/object:Gem::Version
|
134
104
|
version: 3.0.0
|
135
105
|
type: :runtime
|
136
106
|
prerelease: false
|
137
107
|
version_requirements: !ruby/object:Gem::Requirement
|
138
|
-
none: false
|
139
108
|
requirements:
|
140
|
-
- -
|
109
|
+
- - ">="
|
141
110
|
- !ruby/object:Gem::Version
|
142
111
|
version: 3.0.0
|
143
112
|
- !ruby/object:Gem::Dependency
|
144
113
|
name: link_header
|
145
114
|
requirement: !ruby/object:Gem::Requirement
|
146
|
-
none: false
|
147
115
|
requirements:
|
148
|
-
- -
|
116
|
+
- - ">="
|
149
117
|
- !ruby/object:Gem::Version
|
150
118
|
version: 0.0.7
|
151
119
|
type: :runtime
|
152
120
|
prerelease: false
|
153
121
|
version_requirements: !ruby/object:Gem::Requirement
|
154
|
-
none: false
|
155
122
|
requirements:
|
156
|
-
- -
|
123
|
+
- - ">="
|
157
124
|
- !ruby/object:Gem::Version
|
158
125
|
version: 0.0.7
|
159
126
|
description: Ruby interface for restful APIs
|
@@ -166,6 +133,7 @@ extra_rdoc_files: []
|
|
166
133
|
files:
|
167
134
|
- Rakefile
|
168
135
|
- footrest.gemspec
|
136
|
+
- lib/footrest.rb
|
169
137
|
- lib/footrest/client.rb
|
170
138
|
- lib/footrest/connection.rb
|
171
139
|
- lib/footrest/follow_redirects.rb
|
@@ -175,7 +143,6 @@ files:
|
|
175
143
|
- lib/footrest/request.rb
|
176
144
|
- lib/footrest/response_middleware.rb
|
177
145
|
- lib/footrest/version.rb
|
178
|
-
- lib/footrest.rb
|
179
146
|
- spec/footrest/client_spec.rb
|
180
147
|
- spec/footrest/http_error_spec.rb
|
181
148
|
- spec/footrest/pagination_spec.rb
|
@@ -184,27 +151,26 @@ files:
|
|
184
151
|
homepage: https://github.com/instructure/footrest
|
185
152
|
licenses:
|
186
153
|
- MIT
|
154
|
+
metadata: {}
|
187
155
|
post_install_message:
|
188
156
|
rdoc_options: []
|
189
157
|
require_paths:
|
190
158
|
- lib
|
191
159
|
required_ruby_version: !ruby/object:Gem::Requirement
|
192
|
-
none: false
|
193
160
|
requirements:
|
194
|
-
- -
|
161
|
+
- - ">="
|
195
162
|
- !ruby/object:Gem::Version
|
196
163
|
version: '0'
|
197
164
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
198
|
-
none: false
|
199
165
|
requirements:
|
200
|
-
- -
|
166
|
+
- - ">="
|
201
167
|
- !ruby/object:Gem::Version
|
202
168
|
version: '0'
|
203
169
|
requirements: []
|
204
170
|
rubyforge_project:
|
205
|
-
rubygems_version:
|
171
|
+
rubygems_version: 2.2.2
|
206
172
|
signing_key:
|
207
|
-
specification_version:
|
173
|
+
specification_version: 4
|
208
174
|
summary: REST APIs
|
209
175
|
test_files:
|
210
176
|
- spec/footrest/client_spec.rb
|
@@ -212,4 +178,3 @@ test_files:
|
|
212
178
|
- spec/footrest/pagination_spec.rb
|
213
179
|
- spec/footrest/request_spec.rb
|
214
180
|
- spec/spec_helper.rb
|
215
|
-
has_rdoc:
|