faraday 0.8.0 → 0.8.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.
data/README.md CHANGED
@@ -17,7 +17,7 @@ Faraday supports these adapters:
17
17
  It also includes a Rack adapter for hitting loaded Rack applications through
18
18
  Rack::Test, and a Test adapter for stubbing requests by hand.
19
19
 
20
- ## <a name="usage"></a>Usage
20
+ ## Usage
21
21
 
22
22
  ```ruby
23
23
  conn = Faraday.new(:url => 'http://sushi.com') do |builder|
@@ -58,15 +58,8 @@ end
58
58
 
59
59
  conn.get do |req|
60
60
  req.url '/search'
61
- req.options = {
62
- :timeout => 5, # open/read timeout Integer in seconds
63
- :open_timeout => 2, # read timeout Integer in seconds
64
- :proxy => {
65
- :uri => "http://example.org/", # proxy server URI
66
- :user => "me", # proxy server username
67
- :password => "test123" # proxy server password
68
- }
69
- }
61
+ req.options[:timeout] = 5 # open/read timeout in seconds
62
+ req.options[:open_timeout] = 2 # connection open timeout in seconds
70
63
  end
71
64
  ```
72
65
 
@@ -149,7 +142,7 @@ later, response. Some keys are:
149
142
  :response_headers
150
143
  ```
151
144
 
152
- ## <a name="testing"></a>Testing
145
+ ## Testing
153
146
 
154
147
  ```ruby
155
148
  # It's possible to define stubbed request outside a test adapter block.
@@ -184,11 +177,11 @@ resp = test.get '/else' #=> raises "no such stub" error
184
177
  stubs.verify_stubbed_calls
185
178
  ```
186
179
 
187
- ## <a name="todo"></a>TODO
180
+ ## TODO
188
181
  * support streaming requests/responses
189
182
  * better stubbing API
190
183
 
191
- ## <a name="pulls"></a>Note on Patches/Pull Requests
184
+ ## Note on Patches/Pull Requests
192
185
  1. Fork the project.
193
186
  2. Make your feature addition or bug fix.
194
187
  3. Add tests for it. This is important so I don't break it in a future version
@@ -202,7 +195,7 @@ We are pushing towards a 1.0 release, when we will have to follow [Semantic
202
195
  Versioning](http://semver.org/). If your patch includes changes to break
203
196
  compatiblitity, note that so we can add it to the [Changelog](https://github.com/technoweenie/faraday/wiki/Changelog).
204
197
 
205
- ## <a name="versions"></a>Supported Ruby Versions
198
+ ## Supported Ruby Versions
206
199
  This library aims to support and is [tested against][travis] the following Ruby
207
200
  implementations:
208
201
 
@@ -229,8 +222,8 @@ implementation, you will be personally responsible for providing patches in a
229
222
  timely fashion. If critical issues for a particular implementation exist at the
230
223
  time of a major release, support for that Ruby version may be dropped.
231
224
 
232
- ## <a name="copyright"></a>Copyright
233
- Copyright (c) 2009-12 [Rick Olson](mailto:technoweenie@gmail.com), zack hobson.
225
+ ## Copyright
226
+ Copyright (c) 2009-2012 [Rick Olson](mailto:technoweenie@gmail.com), zack hobson.
234
227
  See [LICENSE][] for details.
235
228
 
236
229
  [license]: https://github.com/technoweenie/faraday/blob/master/LICENSE.md
data/faraday.gemspec CHANGED
@@ -3,7 +3,7 @@ Gem::Specification.new do |s|
3
3
  s.required_rubygems_version = Gem::Requirement.new(">= 1.3.5") if s.respond_to? :required_rubygems_version=
4
4
 
5
5
  s.name = 'faraday'
6
- s.version = '0.8.0'
6
+ s.version = '0.8.1'
7
7
 
8
8
  s.summary = "HTTP/REST API client library."
9
9
  # TODO: s.description
data/lib/faraday.rb CHANGED
@@ -1,5 +1,5 @@
1
1
  module Faraday
2
- VERSION = "0.8.0"
2
+ VERSION = "0.8.1"
3
3
 
4
4
  class << self
5
5
  attr_accessor :root_path, :lib_path
@@ -33,13 +33,18 @@ module Faraday
33
33
  @default_connection ||= Connection.new
34
34
  end
35
35
 
36
- begin
37
- require RUBY_VERSION < '1.9' ? 'system_timer' : 'timeout'
38
- rescue LoadError
36
+ if (!defined?(RUBY_ENGINE) || "ruby" == RUBY_ENGINE) && RUBY_VERSION < '1.9'
37
+ begin
38
+ require 'system_timer'
39
+ Timer = SystemTimer
40
+ rescue LoadError
41
+ warn "Faraday: you may want to install system_timer for reliable timeouts"
42
+ end
43
+ end
44
+
45
+ unless const_defined? :Timer
39
46
  require 'timeout'
40
- warn "Faraday: you may want to install system_timer for reliable timeouts"
41
- ensure
42
- Timer = defined?(::SystemTimer) ? ::SystemTimer : ::Timeout
47
+ Timer = Timeout
43
48
  end
44
49
 
45
50
  module MiddlewareRegistry
@@ -4,6 +4,70 @@ module Faraday
4
4
  # when in EM reactor loop or for making parallel requests in
5
5
  # synchronous code.
6
6
  class EMHttp < Faraday::Adapter
7
+ module Options
8
+ def connection_config(env)
9
+ options = {}
10
+ configure_ssl(options, env)
11
+ configure_proxy(options, env)
12
+ configure_timeout(options, env)
13
+ options
14
+ end
15
+
16
+ def request_config(env)
17
+ options = {
18
+ :body => read_body(env),
19
+ :head => env[:request_headers],
20
+ # :keepalive => true,
21
+ # :file => 'path/to/file', # stream data off disk
22
+ }
23
+ configure_compression(options, env)
24
+ # configure_proxy_auth
25
+ # :proxy => {:authorization => [user, pass]}
26
+ # proxy[:username] && proxy[:password]
27
+ options
28
+ end
29
+
30
+ def read_body(env)
31
+ body = env[:body]
32
+ body.respond_to?(:read) ? body.read : body
33
+ end
34
+
35
+ def configure_ssl(options, env)
36
+ if ssl = env[:ssl]
37
+ # :ssl => {
38
+ # :private_key_file => '/tmp/server.key',
39
+ # :cert_chain_file => '/tmp/server.crt',
40
+ # :verify_peer => false
41
+ end
42
+ end
43
+
44
+ def configure_proxy(options, env)
45
+ if proxy = request_options(env)[:proxy]
46
+ options[:proxy] = {
47
+ :host => proxy[:uri].host,
48
+ :port => proxy[:uri].port
49
+ }
50
+ end
51
+ end
52
+
53
+ def configure_timeout(options, env)
54
+ timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
55
+ options[:connect_timeout] = options[:inactivity_timeout] = timeout
56
+ options[:connect_timeout] = open_timeout if open_timeout
57
+ end
58
+
59
+ def configure_compression(options, env)
60
+ if env[:method] == :get and not options[:head].key? 'accept-encoding'
61
+ options[:head]['accept-encoding'] = 'gzip, compressed'
62
+ end
63
+ end
64
+
65
+ def request_options(env)
66
+ env[:request]
67
+ end
68
+ end
69
+
70
+ include Options
7
71
 
8
72
  dependency 'em-http'
9
73
 
@@ -80,67 +144,6 @@ module Faraday
80
144
  raise errklass, msg
81
145
  end
82
146
 
83
- def connection_config(env)
84
- options = {}
85
- configure_ssl(options, env)
86
- configure_proxy(options, env)
87
- configure_timeout(options, env)
88
- options
89
- end
90
-
91
- def request_config(env)
92
- options = {
93
- :body => read_body(env),
94
- :head => env[:request_headers],
95
- # :keepalive => true,
96
- # :file => 'path/to/file', # stream data off disk
97
- }
98
- configure_compression(options, env)
99
- # configure_proxy_auth
100
- # :proxy => {:authorization => [user, pass]}
101
- # proxy[:username] && proxy[:password]
102
- options
103
- end
104
-
105
- def read_body(env)
106
- body = env[:body]
107
- body.respond_to?(:read) ? body.read : body
108
- end
109
-
110
- def configure_ssl(options, env)
111
- if ssl = env[:ssl]
112
- # :ssl => {
113
- # :private_key_file => '/tmp/server.key',
114
- # :cert_chain_file => '/tmp/server.crt',
115
- # :verify_peer => false
116
- end
117
- end
118
-
119
- def configure_proxy(options, env)
120
- if proxy = request_options(env)[:proxy]
121
- options[:proxy] = {
122
- :host => proxy[:uri].host,
123
- :port => proxy[:uri].port
124
- }
125
- end
126
- end
127
-
128
- def configure_timeout(options, env)
129
- timeout, open_timeout = request_options(env).values_at(:timeout, :open_timeout)
130
- options[:connect_timeout] = options[:inactivity_timeout] = timeout
131
- options[:connect_timeout] = open_timeout if open_timeout
132
- end
133
-
134
- def configure_compression(options, env)
135
- if env[:method] == :get and not options[:head].key? 'accept-encoding'
136
- options[:head]['accept-encoding'] = 'gzip, compressed'
137
- end
138
- end
139
-
140
- def request_options(env)
141
- env[:request]
142
- end
143
-
144
147
  def parallel?(env)
145
148
  !!env[:parallel_manager]
146
149
  end
@@ -3,6 +3,7 @@ require 'uri'
3
3
  module Faraday
4
4
  class Adapter
5
5
  class EMSynchrony < Faraday::Adapter
6
+ include EMHttp::Options
6
7
 
7
8
  dependency do
8
9
  require 'em-synchrony/em-http'
@@ -18,41 +19,13 @@ module Faraday
18
19
 
19
20
  def call(env)
20
21
  super
21
- request = EventMachine::HttpRequest.new(URI::parse(env[:url].to_s))
22
- options = {:head => env[:request_headers]}
23
- options[:ssl] = env[:ssl] if env[:ssl]
24
-
25
- if env[:body]
26
- if env[:body].respond_to? :read
27
- options[:body] = env[:body].read
28
- else
29
- options[:body] = env[:body]
30
- end
31
- end
32
-
33
- if req = env[:request]
34
- if proxy = req[:proxy]
35
- uri = URI.parse(proxy[:uri])
36
- options[:proxy] = {
37
- :host => uri.host,
38
- :port => uri.port
39
- }
40
- if proxy[:username] && proxy[:password]
41
- options[:proxy][:authorization] = [proxy[:username], proxy[:password]]
42
- end
43
- end
44
-
45
- # only one timeout currently supported by em http request
46
- if req[:timeout] or req[:open_timeout]
47
- options[:timeout] = [req[:timeout] || 0, req[:open_timeout] || 0].max
48
- end
49
- end
22
+ request = EventMachine::HttpRequest.new(URI::parse(env[:url].to_s), connection_config(env)) # end
50
23
 
51
24
  http_method = env[:method].to_s.downcase.to_sym
52
25
 
53
26
  # Queue requests for parallel execution.
54
27
  if env[:parallel_manager]
55
- env[:parallel_manager].add(request, http_method, options) do |resp|
28
+ env[:parallel_manager].add(request, http_method, request_config(env)) do |resp|
56
29
  save_response(env, resp.response_header.status, resp.response) do |resp_headers|
57
30
  resp.response_header.each do |name, value|
58
31
  resp_headers[name.to_sym] = value
@@ -66,7 +39,7 @@ module Faraday
66
39
  # Execute single request.
67
40
  else
68
41
  client = nil
69
- block = lambda { request.send(http_method, options) }
42
+ block = lambda { request.send(http_method, request_config(env)) }
70
43
 
71
44
  if !EM.reactor_running?
72
45
  EM.run do
@@ -7,7 +7,7 @@ module Faraday
7
7
  super
8
8
 
9
9
  conn = ::Excon.new(env[:url].to_s)
10
- if ssl = (env[:url].scheme == 'https' && env[:ssl])
10
+ if env[:url].scheme == 'https' && ssl = env[:ssl]
11
11
  ::Excon.ssl_verify_peer = !!ssl.fetch(:verify, true)
12
12
  ::Excon.ssl_ca_path = ssl[:ca_file] if ssl[:ca_file]
13
13
  end
data/test/helper.rb CHANGED
@@ -1,7 +1,9 @@
1
1
  unless ENV['CI']
2
2
  begin
3
3
  require 'simplecov'
4
- SimpleCov.start
4
+ SimpleCov.start do
5
+ add_filter 'test'
6
+ end
5
7
  rescue LoadError
6
8
  end
7
9
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: faraday
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.8.0
4
+ version: 0.8.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-04-23 00:00:00.000000000 Z
12
+ date: 2012-05-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multipart-post
16
- requirement: &70331771782880 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ~>
@@ -21,10 +21,15 @@ dependencies:
21
21
  version: '1.1'
22
22
  type: :runtime
23
23
  prerelease: false
24
- version_requirements: *70331771782880
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ~>
28
+ - !ruby/object:Gem::Version
29
+ version: '1.1'
25
30
  - !ruby/object:Gem::Dependency
26
31
  name: rake
27
- requirement: &70331771781000 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
28
33
  none: false
29
34
  requirements:
30
35
  - - ! '>='
@@ -32,10 +37,15 @@ dependencies:
32
37
  version: '0'
33
38
  type: :development
34
39
  prerelease: false
35
- version_requirements: *70331771781000
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
36
46
  - !ruby/object:Gem::Dependency
37
47
  name: simplecov
38
- requirement: &70331771779420 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
39
49
  none: false
40
50
  requirements:
41
51
  - - ! '>='
@@ -43,10 +53,15 @@ dependencies:
43
53
  version: '0'
44
54
  type: :development
45
55
  prerelease: false
46
- version_requirements: *70331771779420
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
47
62
  - !ruby/object:Gem::Dependency
48
63
  name: test-unit
49
- requirement: &70331771778040 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
50
65
  none: false
51
66
  requirements:
52
67
  - - ! '>='
@@ -54,10 +69,15 @@ dependencies:
54
69
  version: '0'
55
70
  type: :development
56
71
  prerelease: false
57
- version_requirements: *70331771778040
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
58
78
  - !ruby/object:Gem::Dependency
59
79
  name: webmock
60
- requirement: &70331771775860 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
61
81
  none: false
62
82
  requirements:
63
83
  - - ! '>='
@@ -65,7 +85,12 @@ dependencies:
65
85
  version: '0'
66
86
  type: :development
67
87
  prerelease: false
68
- version_requirements: *70331771775860
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
69
94
  description:
70
95
  email: technoweenie@gmail.com
71
96
  executables: []
@@ -147,7 +172,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
147
172
  version: 1.3.5
148
173
  requirements: []
149
174
  rubyforge_project:
150
- rubygems_version: 1.8.10
175
+ rubygems_version: 1.8.24
151
176
  signing_key:
152
177
  specification_version: 2
153
178
  summary: HTTP/REST API client library.