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.
Files changed (45) hide show
  1. data/.rspec +0 -1
  2. data/.travis.yml +1 -2
  3. data/CHANGELOG.md +9 -9
  4. data/Gemfile +3 -3
  5. data/README.md +2 -2
  6. data/Rakefile +9 -2
  7. data/faraday_middleware.gemspec +16 -24
  8. data/lib/faraday_middleware.rb +51 -11
  9. data/lib/faraday_middleware/addressable_patch.rb +20 -0
  10. data/lib/faraday_middleware/backwards_compatibility.rb +30 -0
  11. data/lib/faraday_middleware/instrumentation.rb +30 -0
  12. data/lib/faraday_middleware/rack_compatible.rb +76 -0
  13. data/lib/faraday_middleware/request/encode_json.rb +50 -0
  14. data/lib/faraday_middleware/request/oauth.rb +61 -0
  15. data/lib/faraday_middleware/request/oauth2.rb +60 -0
  16. data/lib/faraday_middleware/response/caching.rb +76 -0
  17. data/lib/faraday_middleware/response/follow_redirects.rb +53 -0
  18. data/lib/{faraday → faraday_middleware}/response/mashify.rb +2 -2
  19. data/lib/faraday_middleware/response/parse_json.rb +35 -0
  20. data/lib/faraday_middleware/response/parse_marshal.rb +10 -0
  21. data/lib/faraday_middleware/response/parse_xml.rb +11 -0
  22. data/lib/faraday_middleware/response/parse_yaml.rb +10 -0
  23. data/lib/faraday_middleware/response/rashify.rb +9 -0
  24. data/lib/faraday_middleware/response_middleware.rb +78 -0
  25. data/lib/faraday_middleware/version.rb +1 -1
  26. data/spec/caching_test.rb +122 -0
  27. data/spec/encode_json_spec.rb +95 -0
  28. data/spec/follow_redirects_spec.rb +33 -0
  29. data/spec/helper.rb +27 -12
  30. data/spec/mashify_spec.rb +8 -7
  31. data/spec/oauth2_spec.rb +100 -32
  32. data/spec/oauth_spec.rb +83 -28
  33. data/spec/parse_json_spec.rb +71 -46
  34. data/spec/parse_marshal_spec.rb +9 -26
  35. data/spec/parse_xml_spec.rb +56 -24
  36. data/spec/parse_yaml_spec.rb +40 -20
  37. data/spec/rashify_spec.rb +4 -3
  38. metadata +59 -57
  39. data/lib/faraday/request/oauth.rb +0 -23
  40. data/lib/faraday/request/oauth2.rb +0 -24
  41. data/lib/faraday/response/parse_json.rb +0 -20
  42. data/lib/faraday/response/parse_marshal.rb +0 -10
  43. data/lib/faraday/response/parse_xml.rb +0 -11
  44. data/lib/faraday/response/parse_yaml.rb +0 -11
  45. 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,10 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Response::ParseMarshal < Response::Middleware
5
-
6
- def parse(body)
7
- ::Marshal.load(body)
8
- end
9
- end
10
- end
@@ -1,11 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Response::ParseXml < Response::Middleware
5
- dependency 'multi_xml'
6
-
7
- def parse(body)
8
- ::MultiXml.parse(body)
9
- end
10
- end
11
- end
@@ -1,11 +0,0 @@
1
- require 'faraday'
2
-
3
- module Faraday
4
- class Response::ParseYaml < Response::Middleware
5
- dependency 'yaml'
6
-
7
- def parse(body)
8
- ::YAML.load(body)
9
- end
10
- end
11
- 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