faraday_middleware 0.7.0 → 0.8.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.rspec +0 -1
- data/.travis.yml +1 -2
- data/CHANGELOG.md +9 -9
- data/Gemfile +3 -3
- data/README.md +2 -2
- data/Rakefile +9 -2
- data/faraday_middleware.gemspec +16 -24
- data/lib/faraday_middleware.rb +51 -11
- data/lib/faraday_middleware/addressable_patch.rb +20 -0
- data/lib/faraday_middleware/backwards_compatibility.rb +30 -0
- data/lib/faraday_middleware/instrumentation.rb +30 -0
- data/lib/faraday_middleware/rack_compatible.rb +76 -0
- data/lib/faraday_middleware/request/encode_json.rb +50 -0
- data/lib/faraday_middleware/request/oauth.rb +61 -0
- data/lib/faraday_middleware/request/oauth2.rb +60 -0
- data/lib/faraday_middleware/response/caching.rb +76 -0
- data/lib/faraday_middleware/response/follow_redirects.rb +53 -0
- data/lib/{faraday → faraday_middleware}/response/mashify.rb +2 -2
- data/lib/faraday_middleware/response/parse_json.rb +35 -0
- data/lib/faraday_middleware/response/parse_marshal.rb +10 -0
- data/lib/faraday_middleware/response/parse_xml.rb +11 -0
- data/lib/faraday_middleware/response/parse_yaml.rb +10 -0
- data/lib/faraday_middleware/response/rashify.rb +9 -0
- data/lib/faraday_middleware/response_middleware.rb +78 -0
- data/lib/faraday_middleware/version.rb +1 -1
- data/spec/caching_test.rb +122 -0
- data/spec/encode_json_spec.rb +95 -0
- data/spec/follow_redirects_spec.rb +33 -0
- data/spec/helper.rb +27 -12
- data/spec/mashify_spec.rb +8 -7
- data/spec/oauth2_spec.rb +100 -32
- data/spec/oauth_spec.rb +83 -28
- data/spec/parse_json_spec.rb +71 -46
- data/spec/parse_marshal_spec.rb +9 -26
- data/spec/parse_xml_spec.rb +56 -24
- data/spec/parse_yaml_spec.rb +40 -20
- data/spec/rashify_spec.rb +4 -3
- metadata +59 -57
- data/lib/faraday/request/oauth.rb +0 -23
- data/lib/faraday/request/oauth2.rb +0 -24
- data/lib/faraday/response/parse_json.rb +0 -20
- data/lib/faraday/response/parse_marshal.rb +0 -10
- data/lib/faraday/response/parse_xml.rb +0 -11
- data/lib/faraday/response/parse_yaml.rb +0 -11
- data/lib/faraday/response/rashify.rb +0 -19
@@ -1,23 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Request::OAuth < Faraday::Middleware
|
5
|
-
dependency 'simple_oauth'
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
params = env[:body] || {}
|
9
|
-
|
10
|
-
signature_params = params.reject{ |k,v| v.respond_to?(:content_type) }
|
11
|
-
|
12
|
-
header = SimpleOAuth::Header.new(env[:method], env[:url], signature_params, @options)
|
13
|
-
|
14
|
-
env[:request_headers]['Authorization'] = header.to_s
|
15
|
-
|
16
|
-
@app.call(env)
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(app, options)
|
20
|
-
@app, @options = app, options
|
21
|
-
end
|
22
|
-
end
|
23
|
-
end
|
@@ -1,24 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Request::OAuth2 < Faraday::Middleware
|
5
|
-
dependency 'oauth2'
|
6
|
-
|
7
|
-
def call(env)
|
8
|
-
params = env[:url].query_values || {}
|
9
|
-
|
10
|
-
env[:url].query_values = { 'access_token' => @token }.merge(params)
|
11
|
-
|
12
|
-
token = env[:url].query_values['access_token']
|
13
|
-
|
14
|
-
env[:request_headers].merge!('Authorization' => "Token token=\"#{token}\"")
|
15
|
-
|
16
|
-
@app.call env
|
17
|
-
end
|
18
|
-
|
19
|
-
def initialize(app, *args)
|
20
|
-
@app = app
|
21
|
-
@token = args.shift
|
22
|
-
end
|
23
|
-
end
|
24
|
-
end
|
@@ -1,20 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::ParseJson < Response::Middleware
|
5
|
-
dependency 'multi_json'
|
6
|
-
|
7
|
-
def parse(body)
|
8
|
-
case body
|
9
|
-
when ''
|
10
|
-
nil
|
11
|
-
when 'true'
|
12
|
-
true
|
13
|
-
when 'false'
|
14
|
-
false
|
15
|
-
else
|
16
|
-
::MultiJson.decode(body)
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|
20
|
-
end
|
@@ -1,19 +0,0 @@
|
|
1
|
-
require 'faraday'
|
2
|
-
|
3
|
-
module Faraday
|
4
|
-
class Response::Rashify < Response::Middleware
|
5
|
-
dependency 'hashie/mash'
|
6
|
-
dependency 'rash'
|
7
|
-
|
8
|
-
def parse(body)
|
9
|
-
case body
|
10
|
-
when Hash
|
11
|
-
::Hashie::Rash.new(body)
|
12
|
-
when Array
|
13
|
-
body.map { |item| item.is_a?(Hash) ? ::Hashie::Rash.new(item) : item }
|
14
|
-
else
|
15
|
-
body
|
16
|
-
end
|
17
|
-
end
|
18
|
-
end
|
19
|
-
end
|