faraday_middleware 0.9.0 → 0.9.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +7 -0
- data/CONTRIBUTING.md +46 -0
- data/README.md +2 -2
- data/Rakefile +8 -9
- data/faraday_middleware.gemspec +21 -21
- data/lib/faraday_middleware.rb +4 -4
- data/lib/faraday_middleware/rack_compatible.rb +17 -12
- data/lib/faraday_middleware/request/oauth.rb +1 -1
- data/lib/faraday_middleware/request/oauth2.rb +2 -1
- data/lib/faraday_middleware/response/caching.rb +1 -1
- data/lib/faraday_middleware/response/parse_dates.rb +1 -1
- data/lib/faraday_middleware/response_middleware.rb +32 -0
- data/lib/faraday_middleware/version.rb +1 -1
- data/spec/caching_spec.rb +170 -0
- data/spec/encode_json_spec.rb +1 -1
- data/spec/follow_redirects_spec.rb +3 -0
- data/spec/helper.rb +14 -2
- data/spec/mashify_spec.rb +31 -60
- data/spec/method_override_spec.rb +2 -2
- data/spec/oauth2_spec.rb +2 -2
- data/spec/oauth_spec.rb +1 -1
- data/spec/parse_dates_spec.rb +5 -0
- data/spec/rashify_spec.rb +16 -41
- metadata +25 -130
- data/.gemtest +0 -0
- data/.gitignore +0 -29
- data/.rspec +0 -2
- data/.travis.yml +0 -10
- data/Gemfile +0 -11
- data/spec/caching_test.rb +0 -155
data/.gemtest
DELETED
File without changes
|
data/.gitignore
DELETED
@@ -1,29 +0,0 @@
|
|
1
|
-
# TextMate
|
2
|
-
*.tmproj
|
3
|
-
tmtags
|
4
|
-
|
5
|
-
# emails
|
6
|
-
*~
|
7
|
-
\#*
|
8
|
-
.\#*
|
9
|
-
|
10
|
-
# vim
|
11
|
-
*.swp
|
12
|
-
|
13
|
-
# General
|
14
|
-
coverage
|
15
|
-
rdoc
|
16
|
-
doc
|
17
|
-
log
|
18
|
-
.yardoc
|
19
|
-
tmp
|
20
|
-
|
21
|
-
# Bundler
|
22
|
-
*.gem
|
23
|
-
.bundle
|
24
|
-
Gemfile.lock
|
25
|
-
pkg
|
26
|
-
*.gem
|
27
|
-
|
28
|
-
# Rubinius
|
29
|
-
*.rbc
|
data/.rspec
DELETED
data/.travis.yml
DELETED
data/Gemfile
DELETED
data/spec/caching_test.rb
DELETED
@@ -1,155 +0,0 @@
|
|
1
|
-
require 'test/unit'
|
2
|
-
require 'forwardable'
|
3
|
-
require 'fileutils'
|
4
|
-
require 'rack/cache'
|
5
|
-
require 'faraday'
|
6
|
-
require 'faraday_middleware/response/caching'
|
7
|
-
require 'faraday_middleware/rack_compatible'
|
8
|
-
|
9
|
-
class CachingTest < Test::Unit::TestCase
|
10
|
-
class TestCache < Hash
|
11
|
-
def read(key)
|
12
|
-
if cached = self[key]
|
13
|
-
Marshal.load(cached)
|
14
|
-
end
|
15
|
-
end
|
16
|
-
|
17
|
-
def write(key, data)
|
18
|
-
self[key] = Marshal.dump(data)
|
19
|
-
end
|
20
|
-
|
21
|
-
def fetch(key)
|
22
|
-
read(key) || yield.tap { |data| write(key, data) }
|
23
|
-
end
|
24
|
-
end
|
25
|
-
|
26
|
-
class Lint < Struct.new(:app)
|
27
|
-
def call(env)
|
28
|
-
app.call(env).on_complete do
|
29
|
-
raise "no headers" unless env[:response_headers].is_a? Hash
|
30
|
-
raise "no response" unless env[:response].is_a? Faraday::Response
|
31
|
-
raise "env not identical" unless env[:response].env.object_id == env.object_id
|
32
|
-
end
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
def setup
|
37
|
-
@cache = TestCache.new
|
38
|
-
|
39
|
-
request_count = 0
|
40
|
-
response = lambda { |env|
|
41
|
-
[200, {'Content-Type' => 'text/plain'}, "request:#{request_count+=1}"]
|
42
|
-
}
|
43
|
-
|
44
|
-
@conn = Faraday.new do |b|
|
45
|
-
b.use Lint
|
46
|
-
b.use FaradayMiddleware::Caching, @cache
|
47
|
-
b.adapter :test do |stub|
|
48
|
-
stub.get('/', &response)
|
49
|
-
stub.get('/?foo=bar', &response)
|
50
|
-
stub.post('/', &response)
|
51
|
-
stub.get('/other', &response)
|
52
|
-
end
|
53
|
-
end
|
54
|
-
end
|
55
|
-
|
56
|
-
extend Forwardable
|
57
|
-
def_delegators :@conn, :get, :post
|
58
|
-
|
59
|
-
def test_cache_get
|
60
|
-
assert_equal 'request:1', get('/').body
|
61
|
-
assert_equal 'request:1', get('/').body
|
62
|
-
assert_equal 'request:2', get('/other').body
|
63
|
-
assert_equal 'request:2', get('/other').body
|
64
|
-
end
|
65
|
-
|
66
|
-
def test_response_has_request_params
|
67
|
-
get('/') # make cache
|
68
|
-
response = get('/')
|
69
|
-
assert_equal :get, response.env[:method]
|
70
|
-
assert_equal '/', response.env[:url].request_uri
|
71
|
-
end
|
72
|
-
|
73
|
-
def test_cache_query_params
|
74
|
-
assert_equal 'request:1', get('/').body
|
75
|
-
assert_equal 'request:2', get('/?foo=bar').body
|
76
|
-
assert_equal 'request:2', get('/?foo=bar').body
|
77
|
-
assert_equal 'request:1', get('/').body
|
78
|
-
end
|
79
|
-
|
80
|
-
def test_doesnt_cache_post
|
81
|
-
assert_equal 'request:1', post('/').body
|
82
|
-
assert_equal 'request:2', post('/').body
|
83
|
-
assert_equal 'request:3', post('/').body
|
84
|
-
end
|
85
|
-
end
|
86
|
-
|
87
|
-
# RackCompatible + Rack::Cache
|
88
|
-
class HttpCachingTest < Test::Unit::TestCase
|
89
|
-
include FileUtils
|
90
|
-
|
91
|
-
CACHE_DIR = File.expand_path('../../tmp/cache', __FILE__)
|
92
|
-
|
93
|
-
# middleware to check whether "rack.errors" is free of error reports
|
94
|
-
class RackErrorsComplainer < Struct.new(:app)
|
95
|
-
def call(env)
|
96
|
-
response = app.call(env)
|
97
|
-
error_stream = env['rack.errors'].string
|
98
|
-
raise %(unexpected error in 'rack.errors') if error_stream.include? 'error'
|
99
|
-
response
|
100
|
-
end
|
101
|
-
end
|
102
|
-
|
103
|
-
def setup
|
104
|
-
rm_r CACHE_DIR if File.exists? CACHE_DIR
|
105
|
-
# force reinitializing cache dirs
|
106
|
-
Rack::Cache::Storage.instance.clear
|
107
|
-
|
108
|
-
request_count = 0
|
109
|
-
response = lambda { |env|
|
110
|
-
[200, { 'Content-Type' => 'text/plain',
|
111
|
-
'Cache-Control' => 'public, max-age=900',
|
112
|
-
},
|
113
|
-
"request:#{request_count+=1}"]
|
114
|
-
}
|
115
|
-
|
116
|
-
@conn = Faraday.new do |b|
|
117
|
-
b.use RackErrorsComplainer
|
118
|
-
|
119
|
-
b.use FaradayMiddleware::RackCompatible, Rack::Cache::Context,
|
120
|
-
:metastore => "file:#{CACHE_DIR}/rack/meta",
|
121
|
-
:entitystore => "file:#{CACHE_DIR}/rack/body",
|
122
|
-
:verbose => true
|
123
|
-
|
124
|
-
b.adapter :test do |stub|
|
125
|
-
stub.get('/', &response)
|
126
|
-
stub.post('/', &response)
|
127
|
-
end
|
128
|
-
end
|
129
|
-
end
|
130
|
-
|
131
|
-
extend Forwardable
|
132
|
-
def_delegators :@conn, :get, :post
|
133
|
-
|
134
|
-
def test_cache_get
|
135
|
-
response = get('/', :user_agent => 'test')
|
136
|
-
assert_equal 'request:1', response.body
|
137
|
-
assert_equal :get, response.env[:method]
|
138
|
-
assert_equal 200, response.status
|
139
|
-
|
140
|
-
response = get('/', :user_agent => 'test')
|
141
|
-
assert_equal 'request:1', response.body
|
142
|
-
assert_equal 'text/plain', response['content-type']
|
143
|
-
assert_equal :get, response.env[:method]
|
144
|
-
assert response.env[:request].respond_to?(:fetch)
|
145
|
-
assert_equal 200, response.status
|
146
|
-
|
147
|
-
assert_equal 'request:2', post('/').body
|
148
|
-
end
|
149
|
-
|
150
|
-
def test_doesnt_cache_post
|
151
|
-
assert_equal 'request:1', get('/').body
|
152
|
-
assert_equal 'request:2', post('/').body
|
153
|
-
assert_equal 'request:3', post('/').body
|
154
|
-
end
|
155
|
-
end unless defined? RUBY_ENGINE and "rbx" == RUBY_ENGINE # rbx bug #1522
|