faraday_middleware 0.6.0 → 0.6.3

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,5 @@
1
+ rvm:
2
+ - 1.8.7
3
+ - 1.9.2
4
+ - ree
5
+ - jruby
@@ -18,16 +18,13 @@ Gem::Specification.new do |s|
18
18
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
19
  s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
20
 
21
- s.extra_rdoc_files = ["README.md"]
22
- s.rdoc_options = ['--charset=UTF-8']
23
-
24
21
  s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
25
22
 
26
23
  s.add_runtime_dependency('faraday', '~> 0.6.0')
27
24
  s.add_development_dependency('rake', '~> 0.8')
28
25
  s.add_development_dependency('rspec', '~> 2.5')
29
26
  s.add_development_dependency('simplecov', '~> 0.4')
30
- s.add_development_dependency('hashie', '~> 1.0')
27
+ s.add_development_dependency('rash', '~> 0.3')
31
28
  s.add_development_dependency('json_pure', '~> 1.5')
32
29
  s.add_development_dependency('multi_json', '~> 0.0')
33
30
  s.add_development_dependency('multi_xml', '~> 0.2')
@@ -5,7 +5,7 @@ module Faraday
5
5
  dependency 'simple_oauth'
6
6
 
7
7
  def call(env)
8
- params = env[:body].is_a?(Hash) ? env[:body] : {}
8
+ params = env[:body] || {}
9
9
 
10
10
  signature_params = params.reject{ |k,v| v.respond_to?(:content_type) }
11
11
 
@@ -20,4 +20,4 @@ module Faraday
20
20
  @app, @options = app, options
21
21
  end
22
22
  end
23
- end
23
+ end
@@ -2,13 +2,13 @@ require 'faraday'
2
2
 
3
3
  module Faraday
4
4
  class Response::Mashify < Response::Middleware
5
- dependency 'faraday_middleware/support/rash'
5
+ dependency 'hashie/mash'
6
6
 
7
7
  class << self
8
8
  attr_accessor :mash_class
9
9
  end
10
10
 
11
- self.mash_class = ::Hashie::Rash
11
+ self.mash_class = ::Hashie::Mash
12
12
 
13
13
  def parse(body)
14
14
  case body
@@ -0,0 +1,19 @@
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
@@ -9,4 +9,5 @@ class Faraday::Response
9
9
  autoload :Mashify, 'faraday/response/mashify'
10
10
  autoload :ParseJson, 'faraday/response/parse_json'
11
11
  autoload :ParseXml, 'faraday/response/parse_xml'
12
+ autoload :Rashify, 'faraday/response/rashify'
12
13
  end
@@ -1,3 +1,3 @@
1
1
  module FaradayMiddleware
2
- VERSION = "0.6.0"
2
+ VERSION = "0.6.3"
3
3
  end
@@ -9,13 +9,13 @@ describe Faraday::Response::Mashify do
9
9
  end
10
10
 
11
11
  context 'when used' do
12
- before(:each) { Faraday::Response::Mashify.mash_class = ::Hashie::Rash }
12
+ before(:each) { Faraday::Response::Mashify.mash_class = ::Hashie::Mash }
13
13
  let(:mashify) { Faraday::Response::Mashify.new }
14
14
 
15
- it 'should create a Hashie::Rash from the body' do
15
+ it 'should create a Hashie::Mash from the body' do
16
16
  env = { :body => { "name" => "Erik Michaels-Ober", "username" => "sferik" } }
17
17
  me = mashify.on_complete(env)
18
- me.class.should == Hashie::Rash
18
+ me.class.should == Hashie::Mash
19
19
  end
20
20
 
21
21
  it 'should handle strings' do
@@ -24,13 +24,6 @@ describe Faraday::Response::Mashify do
24
24
  me.should == "Most amazing string EVER"
25
25
  end
26
26
 
27
- it 'should handle hashes and decamelcase the keys' do
28
- env = { :body => { "name" => "Erik Michaels-Ober", "userName" => "sferik" } }
29
- me = mashify.on_complete(env)
30
- me.name.should == 'Erik Michaels-Ober'
31
- me.user_name.should == 'sferik'
32
- end
33
-
34
27
  it 'should handle arrays' do
35
28
  env = { :body => [123, 456] }
36
29
  values = mashify.on_complete(env)
@@ -0,0 +1,68 @@
1
+ require 'helper'
2
+
3
+ describe Faraday::Response::Rashify do
4
+
5
+ context 'when used' do
6
+ let(:rashify) { Faraday::Response::Rashify.new }
7
+
8
+ it 'should create a Hashie::Rash from the body' do
9
+ env = { :body => { "name" => "Erik Michaels-Ober", "username" => "sferik" } }
10
+ me = rashify.on_complete(env)
11
+ me.class.should == Hashie::Rash
12
+ end
13
+
14
+ it 'should handle strings' do
15
+ env = { :body => "Most amazing string EVER" }
16
+ me = rashify.on_complete(env)
17
+ me.should == "Most amazing string EVER"
18
+ end
19
+
20
+ it 'should handle hashes and decamelcase the keys' do
21
+ env = { :body => { "name" => "Erik Michaels-Ober", "userName" => "sferik" } }
22
+ me = rashify.on_complete(env)
23
+ me.name.should == 'Erik Michaels-Ober'
24
+ me.user_name.should == 'sferik'
25
+ end
26
+
27
+ it 'should handle arrays' do
28
+ env = { :body => [123, 456] }
29
+ values = rashify.on_complete(env)
30
+ values.first.should == 123
31
+ values.last.should == 456
32
+ end
33
+
34
+ it 'should handle arrays of hashes' do
35
+ env = { :body => [{ "username" => "sferik" }, { "username" => "pengwynn" }] }
36
+ us = rashify.on_complete(env)
37
+ us.first.username.should == 'sferik'
38
+ us.last.username.should == 'pengwynn'
39
+ end
40
+
41
+ it 'should handle mixed arrays' do
42
+ env = { :body => [123, { "username" => "sferik" }, 456] }
43
+ values = rashify.on_complete(env)
44
+ values.first.should == 123
45
+ values.last.should == 456
46
+ values[1].username.should == 'sferik'
47
+ end
48
+ end
49
+
50
+ context 'integration test' do
51
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
52
+ let(:connection) do
53
+ Faraday::Connection.new do |builder|
54
+ builder.adapter :test, stubs
55
+ builder.use Faraday::Response::Rashify
56
+ end
57
+ end
58
+
59
+ # although it is not good practice to pass a hash as the body, if we add ParseJson
60
+ # to the middleware stack we end up testing two middlewares instead of one
61
+ it 'should create a Hash from the body' do
62
+ stubs.get('/hash') {[200, {'content-type' => 'application/json; charset=utf-8'}, { "name" => "Erik Michaels-Ober", "username" => "sferik" }]}
63
+ me = connection.get('/hash').body
64
+ me.name.should == 'Erik Michaels-Ober'
65
+ me.username.should == 'sferik'
66
+ end
67
+ end
68
+ end
metadata CHANGED
@@ -2,7 +2,7 @@
2
2
  name: faraday_middleware
3
3
  version: !ruby/object:Gem::Version
4
4
  prerelease:
5
- version: 0.6.0
5
+ version: 0.6.3
6
6
  platform: ruby
7
7
  authors:
8
8
  - Erik Michaels-Ober
@@ -11,8 +11,7 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-01 00:00:00 -07:00
15
- default_executable:
14
+ date: 2011-04-06 00:00:00 Z
16
15
  dependencies:
17
16
  - !ruby/object:Gem::Dependency
18
17
  name: faraday
@@ -59,14 +58,14 @@ dependencies:
59
58
  type: :development
60
59
  version_requirements: *id004
61
60
  - !ruby/object:Gem::Dependency
62
- name: hashie
61
+ name: rash
63
62
  prerelease: false
64
63
  requirement: &id005 !ruby/object:Gem::Requirement
65
64
  none: false
66
65
  requirements:
67
66
  - - ~>
68
67
  - !ruby/object:Gem::Version
69
- version: "1.0"
68
+ version: "0.3"
70
69
  type: :development
71
70
  version_requirements: *id005
72
71
  - !ruby/object:Gem::Dependency
@@ -132,12 +131,13 @@ executables: []
132
131
 
133
132
  extensions: []
134
133
 
135
- extra_rdoc_files:
136
- - README.md
134
+ extra_rdoc_files: []
135
+
137
136
  files:
138
137
  - .gemtest
139
138
  - .gitignore
140
139
  - .rspec
140
+ - .travis.yml
141
141
  - CHANGELOG.md
142
142
  - Gemfile
143
143
  - LICENSE.md
@@ -149,8 +149,8 @@ files:
149
149
  - lib/faraday/response/mashify.rb
150
150
  - lib/faraday/response/parse_json.rb
151
151
  - lib/faraday/response/parse_xml.rb
152
+ - lib/faraday/response/rashify.rb
152
153
  - lib/faraday_middleware.rb
153
- - lib/faraday_middleware/support/rash.rb
154
154
  - lib/faraday_middleware/version.rb
155
155
  - spec/helper.rb
156
156
  - spec/mashify_spec.rb
@@ -158,13 +158,13 @@ files:
158
158
  - spec/oauth_spec.rb
159
159
  - spec/parse_json_spec.rb
160
160
  - spec/parse_xml_spec.rb
161
- has_rdoc: true
161
+ - spec/rashify_spec.rb
162
162
  homepage: http://wynnnetherland.com/projects/faraday-middleware/
163
163
  licenses: []
164
164
 
165
165
  post_install_message:
166
- rdoc_options:
167
- - --charset=UTF-8
166
+ rdoc_options: []
167
+
168
168
  require_paths:
169
169
  - lib
170
170
  required_ruby_version: !ruby/object:Gem::Requirement
@@ -182,7 +182,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
182
  requirements: []
183
183
 
184
184
  rubyforge_project:
185
- rubygems_version: 1.6.2
185
+ rubygems_version: 1.7.2
186
186
  signing_key:
187
187
  specification_version: 3
188
188
  summary: Various middleware for Faraday
@@ -193,3 +193,4 @@ test_files:
193
193
  - spec/oauth_spec.rb
194
194
  - spec/parse_json_spec.rb
195
195
  - spec/parse_xml_spec.rb
196
+ - spec/rashify_spec.rb
@@ -1,26 +0,0 @@
1
- require 'hashie/mash'
2
-
3
- module Hashie
4
- class Rash < Mash
5
-
6
- protected
7
-
8
- def convert_key(key) #:nodoc:
9
- underscore_string(key.to_s)
10
- end
11
-
12
- # converts a camel_cased string to a underscore string
13
- # subs spaces with underscores, strips whitespace
14
- # Same way ActiveSupport does string.underscore
15
- def underscore_string(str)
16
- str.to_s.strip.
17
- gsub(' ', '_').
18
- gsub(/::/, '/').
19
- gsub(/([A-Z]+)([A-Z][a-z])/,'\1_\2').
20
- gsub(/([a-z\d])([A-Z])/,'\1_\2').
21
- tr("-", "_").
22
- downcase
23
- end
24
-
25
- end
26
- end