faraday 0.2.4 → 0.3.0
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.rdoc +1 -1
- data/VERSION +1 -1
- data/faraday.gemspec +2 -2
- data/lib/faraday/builder.rb +35 -18
- data/lib/faraday/connection.rb +11 -1
- data/test/connection_app_test.rb +17 -2
- data/test/connection_test.rb +15 -0
- metadata +2 -2
data/README.rdoc
CHANGED
@@ -30,7 +30,7 @@ This mess is gonna get raw, like sushi. So, haters to the left.
|
|
30
30
|
|
31
31
|
# It's possible to define stubbed request outside a test adapter block.
|
32
32
|
stubs = Faraday::Test::Stubs.new do |stub|
|
33
|
-
stub.get('/tamago') { [200, {}, 'egg' }
|
33
|
+
stub.get('/tamago') { [200, {}, 'egg'] }
|
34
34
|
end
|
35
35
|
|
36
36
|
# You can pass stubbed request to the test adapter or define them in a block
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.
|
1
|
+
0.3.0
|
data/faraday.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{faraday}
|
8
|
-
s.version = "0.
|
8
|
+
s.version = "0.3.0"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["rick"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-04-22}
|
13
13
|
s.description = %q{HTTP/REST API client library with pluggable components}
|
14
14
|
s.email = %q{technoweenie@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
data/lib/faraday/builder.rb
CHANGED
@@ -1,31 +1,40 @@
|
|
1
1
|
module Faraday
|
2
2
|
# Possibly going to extend this a bit.
|
3
3
|
#
|
4
|
-
# Faraday::Connection.new(:url => 'http://sushi.com') do
|
5
|
-
# request :yajl # Faraday::Request::Yajl
|
6
|
-
# adapter :logger # Faraday::Adapter::Logger
|
7
|
-
# response :yajl # Faraday::Response::Yajl
|
4
|
+
# Faraday::Connection.new(:url => 'http://sushi.com') do |b|
|
5
|
+
# b.request :yajl # Faraday::Request::Yajl
|
6
|
+
# b.adapter :logger # Faraday::Adapter::Logger
|
7
|
+
# b.response :yajl # Faraday::Response::Yajl
|
8
8
|
# end
|
9
9
|
class Builder
|
10
10
|
attr_accessor :handlers
|
11
11
|
|
12
|
-
def self.
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
12
|
+
def self.create(&block)
|
13
|
+
Builder.new(&block)
|
14
|
+
end
|
15
|
+
|
16
|
+
def self.inner_app
|
17
|
+
lambda do |env|
|
18
|
+
env[:parallel_manager] ? env[:response] : env[:response].finish(env)
|
19
19
|
end
|
20
|
-
Builder.new(&block).tap { |builder| builder.run(inner) }
|
21
20
|
end
|
22
21
|
|
23
|
-
def initialize
|
24
|
-
@handlers =
|
25
|
-
|
22
|
+
def initialize(handlers = [], &block)
|
23
|
+
@handlers = handlers
|
24
|
+
build(&block) if block_given?
|
25
|
+
end
|
26
|
+
|
27
|
+
def build(&block)
|
28
|
+
block.call(self)
|
29
|
+
run(self.class.inner_app)
|
30
|
+
end
|
31
|
+
|
32
|
+
def [](index)
|
33
|
+
# @handlers are stored in reverse order
|
34
|
+
@handlers[-(index+1)]
|
26
35
|
end
|
27
36
|
|
28
|
-
def run
|
37
|
+
def run(app)
|
29
38
|
@handlers.unshift app
|
30
39
|
end
|
31
40
|
|
@@ -34,8 +43,8 @@ module Faraday
|
|
34
43
|
@handlers[1..-1].inject(inner_app) { |app, middleware| middleware.call(app) }
|
35
44
|
end
|
36
45
|
|
37
|
-
def use
|
38
|
-
|
46
|
+
def use(klass, *args, &block)
|
47
|
+
run(lambda { |app| klass.new(app, *args, &block) })
|
39
48
|
end
|
40
49
|
|
41
50
|
def request(key, *args, &block)
|
@@ -53,5 +62,13 @@ module Faraday
|
|
53
62
|
def use_symbol(mod, key, *args, &block)
|
54
63
|
use mod.lookup_module(key), *args, &block
|
55
64
|
end
|
65
|
+
|
66
|
+
def ==(other)
|
67
|
+
other.is_a?(self.class) && @handlers == other.handlers
|
68
|
+
end
|
69
|
+
|
70
|
+
def dup
|
71
|
+
self.class.new @handlers.dup
|
72
|
+
end
|
56
73
|
end
|
57
74
|
end
|
data/lib/faraday/connection.rb
CHANGED
@@ -33,10 +33,16 @@ module Faraday
|
|
33
33
|
merge_params @params, options[:params] if options[:params]
|
34
34
|
merge_headers @headers, options[:headers] if options[:headers]
|
35
35
|
if block
|
36
|
-
@builder = Builder.
|
36
|
+
@builder = Builder.create(&block)
|
37
|
+
else
|
38
|
+
@builder = options[:builder] || Builder.new
|
37
39
|
end
|
38
40
|
end
|
39
41
|
|
42
|
+
def build(&block)
|
43
|
+
@builder.build(&block)
|
44
|
+
end
|
45
|
+
|
40
46
|
def get(url = nil, headers = nil, &block)
|
41
47
|
run_request :get, url, nil, headers, &block
|
42
48
|
end
|
@@ -141,6 +147,10 @@ module Faraday
|
|
141
147
|
uri
|
142
148
|
end
|
143
149
|
|
150
|
+
def dup
|
151
|
+
self.class.new(build_url(''), :headers => headers.dup, :params => params.dup, :builder => builder.dup)
|
152
|
+
end
|
153
|
+
|
144
154
|
def replace_query(uri, params)
|
145
155
|
url_params = @params.dup
|
146
156
|
if uri.query && !uri.query.empty?
|
data/test/connection_app_test.rb
CHANGED
@@ -35,11 +35,26 @@ class TestConnectionApps < Faraday::TestCase
|
|
35
35
|
end
|
36
36
|
|
37
37
|
def test_builder_adds_middleware_to_builder_stack
|
38
|
-
assert_kind_of TestMiddleWare, @conn.builder
|
39
|
-
assert_kind_of TestAdapter, @conn.builder
|
38
|
+
assert_kind_of TestMiddleWare, @conn.builder[0].call(nil)
|
39
|
+
assert_kind_of TestAdapter, @conn.builder[1].call(nil)
|
40
40
|
end
|
41
41
|
|
42
42
|
def test_to_app_returns_rack_object
|
43
43
|
assert @conn.to_app.respond_to?(:call)
|
44
44
|
end
|
45
|
+
|
46
|
+
def test_builder_is_passed_to_new_faraday_connection
|
47
|
+
new_conn = Faraday::Connection.new :builder => @conn.builder
|
48
|
+
assert_equal @conn.builder, new_conn.builder
|
49
|
+
end
|
50
|
+
|
51
|
+
def test_builder_is_built_on_new_faraday_connection
|
52
|
+
new_conn = Faraday::Connection.new
|
53
|
+
new_conn.build do |b|
|
54
|
+
b.run @conn.builder[0]
|
55
|
+
b.run @conn.builder[1]
|
56
|
+
end
|
57
|
+
assert_kind_of TestMiddleWare, new_conn.builder[0].call(nil)
|
58
|
+
assert_kind_of TestAdapter, new_conn.builder[1].call(nil)
|
59
|
+
end
|
45
60
|
end
|
data/test/connection_test.rb
CHANGED
@@ -158,4 +158,19 @@ class TestConnection < Faraday::TestCase
|
|
158
158
|
end
|
159
159
|
assert_equal "a%5Bb%5D=1%20%2B%202", conn.build_query('a[b]' => '1 + 2')
|
160
160
|
end
|
161
|
+
|
162
|
+
def test_dups_connection_object
|
163
|
+
conn = Faraday::Connection.new 'http://sushi.com/foo' do |b|
|
164
|
+
b.adapter :net_http
|
165
|
+
end
|
166
|
+
conn.headers['content-type'] = 'text/plain'
|
167
|
+
conn.params['a'] = '1'
|
168
|
+
|
169
|
+
duped = conn.dup
|
170
|
+
assert_equal conn.build_url(''), duped.build_url('')
|
171
|
+
[:headers, :params, :builder].each do |attr|
|
172
|
+
assert_equal conn.send(attr), duped.send(attr)
|
173
|
+
assert_not_equal conn.send(attr).object_id, duped.send(attr).object_id
|
174
|
+
end
|
175
|
+
end
|
161
176
|
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.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- rick
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2010-
|
12
|
+
date: 2010-04-22 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|