faraday_middleware 0.6.3 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,8 @@
1
1
  rvm:
2
2
  - 1.8.7
3
+ - 1.9.1
3
4
  - 1.9.2
5
+ - jruby
6
+ - rbx
4
7
  - ree
5
- - jruby
8
+ - ruby-head
data/Gemfile CHANGED
@@ -1,3 +1,7 @@
1
- source "http://rubygems.org"
1
+ source 'http://rubygems.org'
2
+
3
+ platforms :jruby do
4
+ gem "jruby-openssl", "~> 0.7"
5
+ end
2
6
 
3
7
  gemspec
data/README.md CHANGED
@@ -1,43 +1,41 @@
1
- # Faraday Middleware
1
+ Faraday Middleware
2
+ ==================
2
3
 
3
- Collection of [Faraday](http://github.com/technoweenie/faraday) middlewares I've been using in some of my API wrappers
4
+ A collection of some useful [Faraday](https://github.com/technoweenie/faraday) middleware
4
5
 
6
+ Installation
7
+ ------------
8
+ gem install faraday_middleware
5
9
 
6
- ## Installation
10
+ Examples
11
+ --------
12
+ Let's decode the response body with [MultiJson](https://github.com/intridea/multi_json)!
7
13
 
8
- sudo gem install faraday_middleware
9
-
10
-
11
- #### Some examples
12
-
13
- Let's decode the response body with [MultiJson](http://github.com/intridea/multi_json)
14
-
15
- conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
16
- builder.adapter Faraday.default_adapter
14
+ connection = Faraday.new(:url => 'http://api.twitter.com/1') do |builder|
17
15
  builder.use Faraday::Response::ParseJson
16
+ builder.adapter Faraday.default_adapter
18
17
  end
19
18
 
20
- resp = conn.get do |req|
21
- req.url '/users/show.json', :screen_name => 'pengwynn'
19
+ response = connection.get do |request|
20
+ request.url '/users/show.json', :screen_name => 'pengwynn'
22
21
  end
23
22
 
24
- u = resp.body
23
+ u = response.body
25
24
  u['name']
26
25
  # => "Wynn Netherland"
27
26
 
27
+ Want to ditch the brackets and use dot notation? [Mashify](https://github.com/intridea/hashie) it!
28
28
 
29
- Want to ditch the brackets and use dot notation? [Mashify](http://github.com/intridea/hashie) it!
30
-
31
- conn = Faraday::Connection.new(:url => 'http://api.twitter.com/1') do |builder|
32
- builder.adapter Faraday.default_adapter
33
- builder.use Faraday::Response::ParseJson
29
+ connection = Faraday.new(:url => 'http://api.twitter.com/1') do |builder|
34
30
  builder.use Faraday::Response::Mashify
31
+ builder.use Faraday::Response::ParseJson
32
+ builder.adapter Faraday.default_adapter
35
33
  end
36
34
 
37
- resp = conn.get do |req|
38
- req.url '/users/show.json', :screen_name => 'pengwynn'
35
+ response = connection.get do |request|
36
+ request.url '/users/show.json', :screen_name => 'pengwynn'
39
37
  end
40
38
 
41
- u = resp.body
39
+ u = response.body
42
40
  u.name
43
41
  # => "Wynn Netherland"
data/Rakefile CHANGED
@@ -1,3 +1,5 @@
1
+ #!/usr/bin/env rake
2
+
1
3
  require 'bundler'
2
4
  Bundler::GemHelper.install_tasks
3
5
 
@@ -1,33 +1,32 @@
1
1
  require File.expand_path('../lib/faraday_middleware/version', __FILE__)
2
2
 
3
- Gem::Specification.new do |s|
4
- s.name = 'faraday_middleware'
5
- s.summary = %q{Various middleware for Faraday}
6
- s.description = s.summary
3
+ Gem::Specification.new do |gem|
4
+ gem.name = 'faraday_middleware'
5
+ gem.summary = %q{Various middleware for Faraday}
6
+ gem.description = gem.summary
7
7
 
8
- s.homepage = 'http://wynnnetherland.com/projects/faraday-middleware/'
8
+ gem.homepage = 'https://github.com/pengwynn/faraday_middleware'
9
9
 
10
- s.authors = ["Erik Michaels-Ober", "Wynn Netherland"]
11
- s.email = ['sferik@gmail.com', 'wynn.netherland@gmail.com']
10
+ gem.authors = ["Erik Michaels-Ober", "Wynn Netherland"]
11
+ gem.email = ['sferik@gmail.com', 'wynn.netherland@gmail.com']
12
12
 
13
- s.version = FaradayMiddleware::VERSION
14
- s.platform = Gem::Platform::RUBY
13
+ gem.version = FaradayMiddleware::VERSION
15
14
 
16
- s.require_paths = ['lib']
17
- s.files = `git ls-files`.split("\n")
18
- s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
19
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
15
+ gem.require_paths = ['lib']
16
+ gem.files = `git ls-files`.split("\n")
17
+ gem.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
18
+ gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
20
19
 
21
- s.required_rubygems_version = Gem::Requirement.new('>= 1.3.6') if s.respond_to? :required_rubygems_version=
20
+ gem.required_rubygems_version = Gem::Requirement.new('>= 1.3.6')
22
21
 
23
- s.add_runtime_dependency('faraday', '~> 0.6.0')
24
- s.add_development_dependency('rake', '~> 0.8')
25
- s.add_development_dependency('rspec', '~> 2.5')
26
- s.add_development_dependency('simplecov', '~> 0.4')
27
- s.add_development_dependency('rash', '~> 0.3')
28
- s.add_development_dependency('json_pure', '~> 1.5')
29
- s.add_development_dependency('multi_json', '~> 0.0')
30
- s.add_development_dependency('multi_xml', '~> 0.2')
31
- s.add_development_dependency('oauth2', '~> 0.2')
32
- s.add_development_dependency('simple_oauth', '~> 0.1')
22
+ gem.add_runtime_dependency 'faraday', '~> 0.6.0'
23
+ gem.add_development_dependency 'rake', '~> 0.9'
24
+ gem.add_development_dependency 'rspec', '~> 2.6'
25
+ gem.add_development_dependency 'simplecov', '~> 0.4'
26
+ gem.add_development_dependency 'rash', '~> 0.3'
27
+ gem.add_development_dependency 'json_pure', '~> 1.5'
28
+ gem.add_development_dependency 'multi_json', '~> 1.0'
29
+ gem.add_development_dependency 'multi_xml', '~> 0.2'
30
+ gem.add_development_dependency 'oauth2', '~> 0.2'
31
+ gem.add_development_dependency 'simple_oauth', '~> 0.1'
33
32
  end
@@ -0,0 +1,10 @@
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
@@ -0,0 +1,11 @@
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
@@ -6,8 +6,10 @@ class Faraday::Request
6
6
  end
7
7
 
8
8
  class Faraday::Response
9
- autoload :Mashify, 'faraday/response/mashify'
10
- autoload :ParseJson, 'faraday/response/parse_json'
11
- autoload :ParseXml, 'faraday/response/parse_xml'
12
- autoload :Rashify, 'faraday/response/rashify'
9
+ autoload :Mashify, 'faraday/response/mashify'
10
+ autoload :ParseJson, 'faraday/response/parse_json'
11
+ autoload :ParseMarshal, 'faraday/response/parse_marshal'
12
+ autoload :ParseXml, 'faraday/response/parse_xml'
13
+ autoload :ParseYaml, 'faraday/response/parse_yaml'
14
+ autoload :Rashify, 'faraday/response/rashify'
13
15
  end
@@ -1,3 +1,3 @@
1
1
  module FaradayMiddleware
2
- VERSION = "0.6.3"
2
+ VERSION = "0.6.5"
3
3
  end
@@ -1,16 +1,9 @@
1
- begin
2
- require 'bundler/setup'
3
- rescue LoadError
4
- puts 'although not required, its recommended you use bundler when running the tests'
5
- end
6
-
1
+ $:.unshift File.expand_path('..', __FILE__)
2
+ $:.unshift File.expand_path('../../lib', __FILE__)
7
3
  require 'simplecov'
8
4
  SimpleCov.start
9
-
10
- require 'rspec'
11
-
12
5
  require 'faraday_middleware'
13
-
6
+ require 'rspec'
14
7
 
15
8
  class DummyApp
16
9
  attr_accessor :env
@@ -22,4 +15,4 @@ class DummyApp
22
15
  def reset
23
16
  @env = nil
24
17
  end
25
- end
18
+ end
@@ -2,46 +2,46 @@ require 'helper'
2
2
 
3
3
  describe Faraday::Response::ParseJson do
4
4
  context 'when used' do
5
- let(:multi_json) { Faraday::Response::ParseJson.new }
5
+ let(:parse_json) { Faraday::Response::ParseJson.new }
6
6
 
7
7
  it 'should handle a blank response' do
8
- empty = multi_json.on_complete(:body => '')
8
+ empty = parse_json.on_complete(:body => '')
9
9
  empty.should be_nil
10
10
  end
11
11
 
12
12
  it 'should handle a true response' do
13
- response = multi_json.on_complete(:body => 'true')
13
+ response = parse_json.on_complete(:body => 'true')
14
14
  response.should be_true
15
15
  end
16
16
 
17
17
  it 'should handle a false response' do
18
- response = multi_json.on_complete(:body => 'false')
18
+ response = parse_json.on_complete(:body => 'false')
19
19
  response.should be_false
20
20
  end
21
21
 
22
22
  it 'should handle hashes' do
23
- me = multi_json.on_complete(:body => '{"name":"Erik Michaels-Ober","screen_name":"sferik"}')
23
+ me = parse_json.on_complete(:body => '{"name":"Erik Michaels-Ober","screen_name":"sferik"}')
24
24
  me.class.should == Hash
25
25
  me['name'].should == 'Erik Michaels-Ober'
26
26
  me['screen_name'].should == 'sferik'
27
27
  end
28
28
 
29
29
  it 'should handle arrays' do
30
- values = multi_json.on_complete(:body => '[123, 456]')
30
+ values = parse_json.on_complete(:body => '[123, 456]')
31
31
  values.class.should == Array
32
32
  values.first.should == 123
33
33
  values.last.should == 456
34
34
  end
35
35
 
36
36
  it 'should handle arrays of hashes' do
37
- us = multi_json.on_complete(:body => '[{"screen_name":"sferik"},{"screen_name":"pengwynn"}]')
37
+ us = parse_json.on_complete(:body => '[{"screen_name":"sferik"},{"screen_name":"pengwynn"}]')
38
38
  us.class.should == Array
39
39
  us.first['screen_name'].should == 'sferik'
40
40
  us.last['screen_name'].should == 'pengwynn'
41
41
  end
42
42
 
43
43
  it 'should handle mixed arrays' do
44
- values = multi_json.on_complete(:body => '[123, {"screen_name":"sferik"}, 456]')
44
+ values = parse_json.on_complete(:body => '[123, {"screen_name":"sferik"}, 456]')
45
45
  values.class.should == Array
46
46
  values.first.should == 123
47
47
  values.last.should == 456
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ describe Faraday::Response::ParseMarshal do
4
+ context 'when used' do
5
+ let(:parse_marshal) { Faraday::Response::ParseMarshal.new }
6
+
7
+ it 'should load a marshalled hash' do
8
+ me = parse_marshal.on_complete(:body => "\x04\b{\x06I\"\tname\x06:\x06ETI\"\x17Erik Michaels-Ober\x06;\x00T")
9
+ me.class.should == Hash
10
+ end
11
+
12
+ it 'should handle hashes' do
13
+ me = parse_marshal.on_complete(:body => "\x04\b{\x06I\"\tname\x06:\x06ETI\"\x17Erik Michaels-Ober\x06;\x00T")
14
+ me['name'].should == 'Erik Michaels-Ober'
15
+ end
16
+ end
17
+
18
+ context 'integration test' do
19
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
20
+ let(:connection) do
21
+ Faraday::Connection.new do |builder|
22
+ builder.adapter :test, stubs
23
+ builder.use Faraday::Response::ParseMarshal
24
+ end
25
+ end
26
+
27
+ it 'should create a Hash from the body' do
28
+ stubs.get('/hash') {[200, {'content-type' => 'application/xml; charset=utf-8'}, "\x04\b{\x06I\"\tname\x06:\x06ETI\"\x17Erik Michaels-Ober\x06;\x00T"]}
29
+ me = connection.get('/hash').body
30
+ me.class.should == Hash
31
+ end
32
+ end
33
+ end
@@ -2,20 +2,20 @@ require 'helper'
2
2
 
3
3
  describe Faraday::Response::ParseXml do
4
4
  context 'when used' do
5
- let(:multi_xml) { Faraday::Response::ParseXml.new }
5
+ let(:parse_xml) { Faraday::Response::ParseXml.new }
6
6
 
7
7
  it 'should handle an empty response' do
8
- empty = multi_xml.on_complete(:body => '')
8
+ empty = parse_xml.on_complete(:body => '')
9
9
  empty.should == Hash.new
10
10
  end
11
11
 
12
12
  it 'should create a Hash from the body' do
13
- me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
13
+ me = parse_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
14
14
  me.class.should == Hash
15
15
  end
16
16
 
17
17
  it 'should handle hashes' do
18
- me = multi_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
18
+ me = parse_xml.on_complete(:body => '<user><name>Erik Michaels-Ober</name><screen_name>sferik</screen_name></user>')
19
19
  me['user']['name'].should == 'Erik Michaels-Ober'
20
20
  me['user']['screen_name'].should == 'sferik'
21
21
  end
@@ -0,0 +1,33 @@
1
+ require 'helper'
2
+
3
+ describe Faraday::Response::ParseYaml do
4
+ context 'when used' do
5
+ let(:parse_yaml) { Faraday::Response::ParseYaml.new }
6
+
7
+ it 'should load a marshalled hash' do
8
+ me = parse_yaml.on_complete(:body => "--- \nname: Erik Michaels-Ober\n")
9
+ me.class.should == Hash
10
+ end
11
+
12
+ it 'should handle hashes' do
13
+ me = parse_yaml.on_complete(:body => "--- \nname: Erik Michaels-Ober\n")
14
+ me['name'].should == 'Erik Michaels-Ober'
15
+ end
16
+ end
17
+
18
+ context 'integration test' do
19
+ let(:stubs) { Faraday::Adapter::Test::Stubs.new }
20
+ let(:connection) do
21
+ Faraday::Connection.new do |builder|
22
+ builder.adapter :test, stubs
23
+ builder.use Faraday::Response::ParseYaml
24
+ end
25
+ end
26
+
27
+ it 'should create a Hash from the body' do
28
+ stubs.get('/hash') {[200, {'content-type' => 'application/xml; charset=utf-8'}, "--- \nname: Erik Michaels-Ober\n"]}
29
+ me = connection.get('/hash').body
30
+ me.class.should == Hash
31
+ end
32
+ end
33
+ 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.3
5
+ version: 0.6.5
6
6
  platform: ruby
7
7
  authors:
8
8
  - Erik Michaels-Ober
@@ -11,7 +11,8 @@ autorequire:
11
11
  bindir: bin
12
12
  cert_chain: []
13
13
 
14
- date: 2011-04-06 00:00:00 Z
14
+ date: 2011-06-22 00:00:00 -07:00
15
+ default_executable:
15
16
  dependencies:
16
17
  - !ruby/object:Gem::Dependency
17
18
  name: faraday
@@ -32,7 +33,7 @@ dependencies:
32
33
  requirements:
33
34
  - - ~>
34
35
  - !ruby/object:Gem::Version
35
- version: "0.8"
36
+ version: "0.9"
36
37
  type: :development
37
38
  version_requirements: *id002
38
39
  - !ruby/object:Gem::Dependency
@@ -43,7 +44,7 @@ dependencies:
43
44
  requirements:
44
45
  - - ~>
45
46
  - !ruby/object:Gem::Version
46
- version: "2.5"
47
+ version: "2.6"
47
48
  type: :development
48
49
  version_requirements: *id003
49
50
  - !ruby/object:Gem::Dependency
@@ -87,7 +88,7 @@ dependencies:
87
88
  requirements:
88
89
  - - ~>
89
90
  - !ruby/object:Gem::Version
90
- version: "0.0"
91
+ version: "1.0"
91
92
  type: :development
92
93
  version_requirements: *id007
93
94
  - !ruby/object:Gem::Dependency
@@ -148,7 +149,9 @@ files:
148
149
  - lib/faraday/request/oauth2.rb
149
150
  - lib/faraday/response/mashify.rb
150
151
  - lib/faraday/response/parse_json.rb
152
+ - lib/faraday/response/parse_marshal.rb
151
153
  - lib/faraday/response/parse_xml.rb
154
+ - lib/faraday/response/parse_yaml.rb
152
155
  - lib/faraday/response/rashify.rb
153
156
  - lib/faraday_middleware.rb
154
157
  - lib/faraday_middleware/version.rb
@@ -157,9 +160,12 @@ files:
157
160
  - spec/oauth2_spec.rb
158
161
  - spec/oauth_spec.rb
159
162
  - spec/parse_json_spec.rb
163
+ - spec/parse_marshal_spec.rb
160
164
  - spec/parse_xml_spec.rb
165
+ - spec/parse_yaml_spec.rb
161
166
  - spec/rashify_spec.rb
162
- homepage: http://wynnnetherland.com/projects/faraday-middleware/
167
+ has_rdoc: true
168
+ homepage: https://github.com/pengwynn/faraday_middleware
163
169
  licenses: []
164
170
 
165
171
  post_install_message:
@@ -182,7 +188,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
188
  requirements: []
183
189
 
184
190
  rubyforge_project:
185
- rubygems_version: 1.7.2
191
+ rubygems_version: 1.5.3
186
192
  signing_key:
187
193
  specification_version: 3
188
194
  summary: Various middleware for Faraday
@@ -192,5 +198,7 @@ test_files:
192
198
  - spec/oauth2_spec.rb
193
199
  - spec/oauth_spec.rb
194
200
  - spec/parse_json_spec.rb
201
+ - spec/parse_marshal_spec.rb
195
202
  - spec/parse_xml_spec.rb
203
+ - spec/parse_yaml_spec.rb
196
204
  - spec/rashify_spec.rb