rack-client 0.4.1 → 0.4.2

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,58 @@
1
+ require 'faraday'
2
+
3
+ module Faraday
4
+ class Adapter
5
+
6
+ class RackClient < Faraday::Adapter
7
+ dependency 'rack/client'
8
+
9
+ def initialize(faraday_app, rack_client_adapter = :default, *a, &b)
10
+ super(faraday_app)
11
+
12
+ klass = case rack_client_adapter
13
+ when :default then ::Rack::Client
14
+ when :simple then ::Rack::Client::Simple
15
+ when :base then ::Rack::Client::Base
16
+ else rack_client_adapter
17
+ end
18
+
19
+ @rack_client_app = klass.new(*a, &b)
20
+ end
21
+
22
+ def call(faraday_env)
23
+ rack_env = to_rack_env(faraday_env)
24
+ timeout = faraday_env[:request][:timeout] || faraday_env[:request][:open_timeout]
25
+
26
+ rack_response = if timeout
27
+ Timer.timeout(timeout, Faraday::Error::TimeoutError) { @rack_client_app.call(rack_env) }
28
+ else
29
+ @rack_client_app.call(rack_env)
30
+ end
31
+
32
+ status, headers, rack_body = rack_response.to_a
33
+
34
+ body = ''
35
+ rack_body.each {|part| body << part }
36
+
37
+ rack_body.close if rack_body.respond_to? :close
38
+
39
+ save_response(faraday_env, status, body, headers)
40
+
41
+ @app.call faraday_env
42
+ end
43
+
44
+ def to_rack_env(faraday_env)
45
+ body = faraday_env.body
46
+ body = body.read if body.respond_to? :read
47
+
48
+ @rack_client_app.build_env(faraday_env.method.to_s.upcase,
49
+ faraday_env.url.to_s,
50
+ faraday_env.request_headers,
51
+ body)
52
+ end
53
+
54
+ end
55
+
56
+ register_middleware nil, :rack_client => RackClient
57
+ end
58
+ end
@@ -1,5 +1,5 @@
1
1
  module Rack
2
2
  module Client
3
- VERSION = "0.4.1"
3
+ VERSION = "0.4.2"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,109 +1,124 @@
1
- --- !ruby/object:Gem::Specification
1
+ --- !ruby/object:Gem::Specification
2
2
  name: rack-client
3
- version: !ruby/object:Gem::Version
4
- hash: 13
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.2
5
5
  prerelease:
6
- segments:
7
- - 0
8
- - 4
9
- - 1
10
- version: 0.4.1
11
6
  platform: ruby
12
- authors:
7
+ authors:
13
8
  - Tim Carey-Smith
14
9
  autorequire:
15
10
  bindir: bin
16
11
  cert_chain: []
17
-
18
- date: 2013-02-25 00:00:00 -08:00
19
- default_executable:
20
- dependencies:
21
- - !ruby/object:Gem::Dependency
12
+ date: 2013-06-04 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
22
15
  name: rack
23
- prerelease: false
24
- requirement: &id001 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
25
17
  none: false
26
- requirements:
27
- - - ">="
28
- - !ruby/object:Gem::Version
29
- hash: 23
30
- segments:
31
- - 1
32
- - 0
33
- - 0
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
34
21
  version: 1.0.0
35
22
  type: :runtime
36
- version_requirements: *id001
37
- - !ruby/object:Gem::Dependency
38
- name: excon
39
23
  prerelease: false
40
- requirement: &id002 !ruby/object:Gem::Requirement
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: 1.0.0
30
+ - !ruby/object:Gem::Dependency
31
+ name: excon
32
+ requirement: !ruby/object:Gem::Requirement
41
33
  none: false
42
- requirements:
43
- - - ">="
44
- - !ruby/object:Gem::Version
45
- hash: 3
46
- segments:
47
- - 0
48
- version: "0"
34
+ requirements:
35
+ - - ! '>='
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
49
38
  type: :development
50
- version_requirements: *id002
51
- - !ruby/object:Gem::Dependency
52
- name: em-http-request
53
39
  prerelease: false
54
- requirement: &id003 !ruby/object:Gem::Requirement
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
46
+ - !ruby/object:Gem::Dependency
47
+ name: em-http-request
48
+ requirement: !ruby/object:Gem::Requirement
55
49
  none: false
56
- requirements:
57
- - - ">="
58
- - !ruby/object:Gem::Version
59
- hash: 3
60
- segments:
61
- - 0
62
- version: "0"
50
+ requirements:
51
+ - - ! '>='
52
+ - !ruby/object:Gem::Version
53
+ version: '0'
63
54
  type: :development
64
- version_requirements: *id003
65
- - !ruby/object:Gem::Dependency
66
- name: typhoeus
67
55
  prerelease: false
68
- requirement: &id004 !ruby/object:Gem::Requirement
56
+ version_requirements: !ruby/object:Gem::Requirement
69
57
  none: false
70
- requirements:
71
- - - ">="
72
- - !ruby/object:Gem::Version
73
- hash: 3
74
- segments:
75
- - 0
76
- version: "0"
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
62
+ - !ruby/object:Gem::Dependency
63
+ name: typhoeus
64
+ requirement: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ! '>='
68
+ - !ruby/object:Gem::Version
69
+ version: '0'
77
70
  type: :development
78
- version_requirements: *id004
79
- - !ruby/object:Gem::Dependency
71
+ prerelease: false
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
78
+ - !ruby/object:Gem::Dependency
80
79
  name: json
80
+ requirement: !ruby/object:Gem::Requirement
81
+ none: false
82
+ requirements:
83
+ - - ! '>='
84
+ - !ruby/object:Gem::Version
85
+ version: '0'
86
+ type: :development
81
87
  prerelease: false
82
- requirement: &id005 !ruby/object:Gem::Requirement
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
94
+ - !ruby/object:Gem::Dependency
95
+ name: faraday
96
+ requirement: !ruby/object:Gem::Requirement
83
97
  none: false
84
- requirements:
85
- - - ">="
86
- - !ruby/object:Gem::Version
87
- hash: 3
88
- segments:
89
- - 0
90
- version: "0"
98
+ requirements:
99
+ - - ! '>='
100
+ - !ruby/object:Gem::Version
101
+ version: 0.9.0.rc1
91
102
  type: :development
92
- version_requirements: *id005
103
+ prerelease: false
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: 0.9.0.rc1
93
110
  description: A client wrapper around a Rack app or HTTP
94
111
  email: tim@spork.in
95
112
  executables: []
96
-
97
113
  extensions: []
98
-
99
114
  extra_rdoc_files: []
100
-
101
- files:
115
+ files:
102
116
  - History.txt
103
117
  - LICENSE
104
118
  - README.textile
105
119
  - Rakefile
106
120
  - lib/rack/client/adapter/base.rb
121
+ - lib/rack/client/adapter/faraday.rb
107
122
  - lib/rack/client/adapter/simple.rb
108
123
  - lib/rack/client/adapter.rb
109
124
  - lib/rack/client/body.rb
@@ -156,39 +171,28 @@ files:
156
171
  - demo/client.rb
157
172
  - demo/demo.rb
158
173
  - demo/demo_spec.rb
159
- has_rdoc: true
160
174
  homepage: http://github.com/halorgium/rack-client
161
175
  licenses: []
162
-
163
176
  post_install_message:
164
177
  rdoc_options: []
165
-
166
- require_paths:
178
+ require_paths:
167
179
  - lib
168
- required_ruby_version: !ruby/object:Gem::Requirement
180
+ required_ruby_version: !ruby/object:Gem::Requirement
169
181
  none: false
170
- requirements:
171
- - - ">="
172
- - !ruby/object:Gem::Version
173
- hash: 3
174
- segments:
175
- - 0
176
- version: "0"
177
- required_rubygems_version: !ruby/object:Gem::Requirement
182
+ requirements:
183
+ - - ! '>='
184
+ - !ruby/object:Gem::Version
185
+ version: '0'
186
+ required_rubygems_version: !ruby/object:Gem::Requirement
178
187
  none: false
179
- requirements:
180
- - - ">="
181
- - !ruby/object:Gem::Version
182
- hash: 3
183
- segments:
184
- - 0
185
- version: "0"
188
+ requirements:
189
+ - - ! '>='
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
186
192
  requirements: []
187
-
188
193
  rubyforge_project:
189
- rubygems_version: 1.6.2
194
+ rubygems_version: 1.8.23
190
195
  signing_key:
191
196
  specification_version: 3
192
197
  summary: A client wrapper around a Rack app or HTTP
193
198
  test_files: []
194
-