footrest 0.3.1 → 0.4.1
Sign up to get free protection for your applications and to get access to all the features.
- data/footrest.gemspec +5 -1
- data/lib/footrest.rb +16 -1
- data/lib/footrest/connection.rb +6 -1
- data/lib/footrest/http_error.rb +22 -1
- data/lib/footrest/pagination.rb +3 -2
- data/lib/footrest/response_middleware.rb +8 -3
- data/lib/footrest/version.rb +1 -1
- data/spec/footrest/client_spec.rb +1 -1
- data/spec/footrest/http_error_spec.rb +1 -1
- data/spec/footrest/pagination_spec.rb +20 -0
- data/spec/footrest/request_spec.rb +1 -1
- data/spec/{helper.rb → spec_helper.rb} +0 -0
- metadata +8 -6
data/footrest.gemspec
CHANGED
@@ -23,8 +23,12 @@ Gem::Specification.new do |gem|
|
|
23
23
|
gem.add_development_dependency "bundler", ">= 1.0.0"
|
24
24
|
gem.add_development_dependency "rspec", "~> 2.6"
|
25
25
|
gem.add_development_dependency "webmock"
|
26
|
-
gem.add_development_dependency "debugger"
|
27
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
|
28
32
|
|
29
33
|
gem.add_dependency "faraday", "~> 0.9.0"
|
30
34
|
gem.add_dependency "activesupport", ">= 3.0.0"
|
data/lib/footrest.rb
CHANGED
@@ -3,4 +3,19 @@ require 'footrest/client'
|
|
3
3
|
require 'footrest/version'
|
4
4
|
|
5
5
|
module Footrest
|
6
|
-
end
|
6
|
+
end
|
7
|
+
|
8
|
+
module Faraday
|
9
|
+
class Response::Logger < Response::Middleware
|
10
|
+
private
|
11
|
+
|
12
|
+
SENSITIVE_HEADERS = %w{Authorization}
|
13
|
+
def dump_headers(headers)
|
14
|
+
return "empty headers" unless headers
|
15
|
+
headers.map { |k, v|
|
16
|
+
message = "#{k}: "
|
17
|
+
message << (SENSITIVE_HEADERS.include?(k) ? "[filtered]" : v.inspect)
|
18
|
+
}.join("\n")
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
data/lib/footrest/connection.rb
CHANGED
@@ -10,10 +10,15 @@ module Footrest
|
|
10
10
|
attr_reader :connection
|
11
11
|
|
12
12
|
def set_connection(config)
|
13
|
+
config[:logger] = config[:logging] if config[:logging]
|
13
14
|
@connection = Faraday.new(url: config[:prefix]) do |faraday|
|
14
15
|
faraday.request :multipart
|
15
16
|
faraday.request :url_encoded
|
16
|
-
|
17
|
+
if config[:logger] == true
|
18
|
+
faraday.response :logger
|
19
|
+
elsif config[:logger]
|
20
|
+
faraday.use Faraday::Response::Logger, config[:logger]
|
21
|
+
end
|
17
22
|
faraday.adapter Faraday.default_adapter
|
18
23
|
faraday.use Footrest::FollowRedirects
|
19
24
|
faraday.use Footrest::ParseJson, :content_type => /\bjson$/
|
data/lib/footrest/http_error.rb
CHANGED
@@ -13,7 +13,28 @@ module Footrest
|
|
13
13
|
@body = @response[:body]
|
14
14
|
@method = @response[:method]
|
15
15
|
|
16
|
-
super("HTTP ERROR: #{@status} #{errors}")
|
16
|
+
super("HTTP ERROR: #{@status} #{method} #{url}\n#{errors}\n#{headers}")
|
17
|
+
end
|
18
|
+
|
19
|
+
def method
|
20
|
+
@method.to_s.upcase
|
21
|
+
rescue => e
|
22
|
+
"[Unable to show HTTP method: #{e}]"
|
23
|
+
end
|
24
|
+
|
25
|
+
def url
|
26
|
+
@response.url.to_s
|
27
|
+
rescue => e
|
28
|
+
"[Unable to show URL: #{e}]"
|
29
|
+
end
|
30
|
+
|
31
|
+
def headers
|
32
|
+
JSON::pretty_generate(
|
33
|
+
request: @response.request_headers,
|
34
|
+
response: @response.response_headers
|
35
|
+
)
|
36
|
+
rescue => e
|
37
|
+
"[Unable to show headers: #{e}]"
|
17
38
|
end
|
18
39
|
|
19
40
|
def errors
|
data/lib/footrest/pagination.rb
CHANGED
@@ -5,8 +5,9 @@ module Footrest
|
|
5
5
|
def on_complete(response)
|
6
6
|
if response[:response_headers]
|
7
7
|
if link = response[:response_headers][:link]
|
8
|
-
|
9
|
-
|
8
|
+
%w(prev next first last current).each do |page|
|
9
|
+
response["#{page}_page".to_sym] = find_link(link, page)
|
10
|
+
end
|
10
11
|
end
|
11
12
|
end
|
12
13
|
end
|
@@ -55,9 +55,14 @@ module Footrest
|
|
55
55
|
end
|
56
56
|
|
57
57
|
def response_type(env)
|
58
|
-
|
59
|
-
|
60
|
-
|
58
|
+
if env[:response_headers]
|
59
|
+
type = env[:response_headers][CONTENT_TYPE].to_s
|
60
|
+
type = type.split(';', 2).first if type.index(';')
|
61
|
+
type
|
62
|
+
else
|
63
|
+
warn("response_headers are nil. Did you use http when you meant https?")
|
64
|
+
nil
|
65
|
+
end
|
61
66
|
end
|
62
67
|
|
63
68
|
def process_response_type?(type)
|
data/lib/footrest/version.rb
CHANGED
@@ -0,0 +1,20 @@
|
|
1
|
+
require_relative '../spec_helper'
|
2
|
+
|
3
|
+
describe Footrest::Pagination do
|
4
|
+
|
5
|
+
context "on_complete" do
|
6
|
+
it 'captures prev, next, first, last, and current page links as response headers' do
|
7
|
+
response = {
|
8
|
+
response_headers: {
|
9
|
+
link: "<current_link>; rel=\"current\",<next_link>; rel=\"next\",<prev_link>; rel=\"prev\",<first_link>; rel=\"first\",<last_link>; rel=\"last\""
|
10
|
+
}
|
11
|
+
}
|
12
|
+
|
13
|
+
Footrest::Pagination.new.on_complete(response)
|
14
|
+
|
15
|
+
%w(prev next first last current).each do |page|
|
16
|
+
expect(response["#{page}_page".to_sym]).to eq("#{page}_link")
|
17
|
+
end
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
File without changes
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: footrest
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,7 +10,7 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2014-
|
13
|
+
date: 2014-12-04 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: rake
|
@@ -77,7 +77,7 @@ dependencies:
|
|
77
77
|
- !ruby/object:Gem::Version
|
78
78
|
version: '0'
|
79
79
|
- !ruby/object:Gem::Dependency
|
80
|
-
name:
|
80
|
+
name: pry
|
81
81
|
requirement: !ruby/object:Gem::Requirement
|
82
82
|
none: false
|
83
83
|
requirements:
|
@@ -93,7 +93,7 @@ dependencies:
|
|
93
93
|
- !ruby/object:Gem::Version
|
94
94
|
version: '0'
|
95
95
|
- !ruby/object:Gem::Dependency
|
96
|
-
name:
|
96
|
+
name: debugger
|
97
97
|
requirement: !ruby/object:Gem::Requirement
|
98
98
|
none: false
|
99
99
|
requirements:
|
@@ -178,8 +178,9 @@ files:
|
|
178
178
|
- lib/footrest.rb
|
179
179
|
- spec/footrest/client_spec.rb
|
180
180
|
- spec/footrest/http_error_spec.rb
|
181
|
+
- spec/footrest/pagination_spec.rb
|
181
182
|
- spec/footrest/request_spec.rb
|
182
|
-
- spec/
|
183
|
+
- spec/spec_helper.rb
|
183
184
|
homepage: https://github.com/instructure/footrest
|
184
185
|
licenses:
|
185
186
|
- MIT
|
@@ -208,6 +209,7 @@ summary: REST APIs
|
|
208
209
|
test_files:
|
209
210
|
- spec/footrest/client_spec.rb
|
210
211
|
- spec/footrest/http_error_spec.rb
|
212
|
+
- spec/footrest/pagination_spec.rb
|
211
213
|
- spec/footrest/request_spec.rb
|
212
|
-
- spec/
|
214
|
+
- spec/spec_helper.rb
|
213
215
|
has_rdoc:
|