shin-faraday 0.4.7
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.gitignore +21 -0
- data/LICENSE +20 -0
- data/README.rdoc +84 -0
- data/Rakefile +53 -0
- data/VERSION +1 -0
- data/faraday.gemspec +87 -0
- data/lib/faraday.rb +94 -0
- data/lib/faraday/adapter/action_dispatch.rb +33 -0
- data/lib/faraday/adapter/net_http.rb +59 -0
- data/lib/faraday/adapter/patron.rb +33 -0
- data/lib/faraday/adapter/test.rb +117 -0
- data/lib/faraday/adapter/typhoeus.rb +65 -0
- data/lib/faraday/builder.rb +82 -0
- data/lib/faraday/connection.rb +263 -0
- data/lib/faraday/error.rb +8 -0
- data/lib/faraday/middleware.rb +54 -0
- data/lib/faraday/request.rb +87 -0
- data/lib/faraday/request/active_support_json.rb +21 -0
- data/lib/faraday/request/yajl.rb +18 -0
- data/lib/faraday/response.rb +56 -0
- data/lib/faraday/response/active_support_json.rb +31 -0
- data/lib/faraday/response/nokogiri.rb +21 -0
- data/lib/faraday/response/yajl.rb +26 -0
- data/test/adapters/live_test.rb +141 -0
- data/test/adapters/test_middleware_test.rb +26 -0
- data/test/adapters/typhoeus_test.rb +26 -0
- data/test/connection_app_test.rb +60 -0
- data/test/connection_test.rb +284 -0
- data/test/env_test.rb +56 -0
- data/test/helper.rb +32 -0
- data/test/live_server.rb +34 -0
- data/test/request_middleware_test.rb +24 -0
- data/test/response_middleware_test.rb +44 -0
- metadata +142 -0
data/test/helper.rb
ADDED
@@ -0,0 +1,32 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
gem 'rack', '>= 1.0.1'
|
3
|
+
gem 'addressable', '>= 2.1.1'
|
4
|
+
|
5
|
+
require 'test/unit'
|
6
|
+
if ENV['LEFTRIGHT']
|
7
|
+
require 'leftright'
|
8
|
+
end
|
9
|
+
|
10
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
11
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
12
|
+
require 'faraday'
|
13
|
+
|
14
|
+
begin
|
15
|
+
require 'ruby-debug'
|
16
|
+
Debugger.start
|
17
|
+
rescue LoadError
|
18
|
+
end
|
19
|
+
|
20
|
+
module Faraday
|
21
|
+
class TestCase < Test::Unit::TestCase
|
22
|
+
LIVE_SERVER = case ENV['LIVE']
|
23
|
+
when /^http/ then ENV['LIVE']
|
24
|
+
when nil then nil
|
25
|
+
else 'http://localhost:4567'
|
26
|
+
end
|
27
|
+
|
28
|
+
def test_default
|
29
|
+
assert true
|
30
|
+
end
|
31
|
+
end
|
32
|
+
end
|
data/test/live_server.rb
ADDED
@@ -0,0 +1,34 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'sinatra'
|
3
|
+
|
4
|
+
get '/hello_world' do
|
5
|
+
'hello world'
|
6
|
+
end
|
7
|
+
|
8
|
+
get '/json' do
|
9
|
+
"[1,2,3]"
|
10
|
+
end
|
11
|
+
|
12
|
+
post '/hello' do
|
13
|
+
"hello #{params[:name]}"
|
14
|
+
end
|
15
|
+
|
16
|
+
get '/hello' do
|
17
|
+
"hello #{params[:name]}"
|
18
|
+
end
|
19
|
+
|
20
|
+
post '/echo_name' do
|
21
|
+
params[:name].inspect
|
22
|
+
end
|
23
|
+
|
24
|
+
put '/echo_name' do
|
25
|
+
params[:name].inspect
|
26
|
+
end
|
27
|
+
|
28
|
+
delete '/delete_with_json' do
|
29
|
+
%/{"deleted":true}/
|
30
|
+
end
|
31
|
+
|
32
|
+
delete '/delete_with_params' do
|
33
|
+
params[:deleted]
|
34
|
+
end
|
@@ -0,0 +1,24 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class RequestMiddlewareTest < Faraday::TestCase
|
4
|
+
[:yajl, :rails_json].each do |key|
|
5
|
+
encoder = Faraday::Request.lookup_module(key)
|
6
|
+
next if !encoder.loaded?
|
7
|
+
|
8
|
+
define_method "test_encodes_json_with_#{key}" do
|
9
|
+
raw_json = create_json_connection(encoder).post('echo_body', :a => 1).body
|
10
|
+
raw_json.gsub! /: 1/, ':1' # sometimes rails_json adds a space
|
11
|
+
assert_equal %({"a":1}), raw_json
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
private
|
16
|
+
def create_json_connection(encoder)
|
17
|
+
Faraday::Connection.new do |b|
|
18
|
+
b.use encoder
|
19
|
+
b.adapter :test do |stub|
|
20
|
+
stub.post('echo_body') { |env| [200, {'Content-Type' => 'text/html'}, env[:body]] }
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
@@ -0,0 +1,44 @@
|
|
1
|
+
require File.expand_path(File.join(File.dirname(__FILE__), 'helper'))
|
2
|
+
|
3
|
+
class ResponseMiddlewareTest < Faraday::TestCase
|
4
|
+
[:yajl, :rails_json].each do |key|
|
5
|
+
encoder = Faraday::Response.lookup_module(key)
|
6
|
+
next if !encoder.loaded?
|
7
|
+
|
8
|
+
define_method "test_uses_#{key}_to_parse_json_content" do
|
9
|
+
response = create_json_connection(encoder).get('json')
|
10
|
+
assert response.success?
|
11
|
+
assert_equal [1,2,3], response.body
|
12
|
+
end
|
13
|
+
|
14
|
+
define_method "test_uses_#{key}_to_skip_blank_content" do
|
15
|
+
response = create_json_connection(encoder).get('blank')
|
16
|
+
assert response.success?
|
17
|
+
assert !response.body
|
18
|
+
end
|
19
|
+
|
20
|
+
define_method "test_uses_#{key}_to_skip_nil_content" do
|
21
|
+
response = create_json_connection(encoder).get('nil')
|
22
|
+
assert response.success?
|
23
|
+
assert !response.body
|
24
|
+
end
|
25
|
+
|
26
|
+
define_method "test_use_#{key}_to_raise_Faraday_Error_Parsing_with_no_json_content" do
|
27
|
+
assert_raises Faraday::Error::ParsingError do
|
28
|
+
response = create_json_connection(encoder).get('bad_json')
|
29
|
+
end
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
def create_json_connection(encoder)
|
34
|
+
Faraday::Connection.new do |b|
|
35
|
+
b.adapter :test do |stub|
|
36
|
+
stub.get('json') { [200, {'Content-Type' => 'text/html'}, "[1,2,3]"] }
|
37
|
+
stub.get('blank') { [200, {'Content-Type' => 'text/html'}, ''] }
|
38
|
+
stub.get('nil') { [200, {'Content-Type' => 'text/html'}, nil] }
|
39
|
+
stub.get("bad_json") {[200, {'Content-Type' => 'text/html'}, '<body></body>']}
|
40
|
+
end
|
41
|
+
b.use encoder
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
metadata
ADDED
@@ -0,0 +1,142 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: shin-faraday
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 1
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 4
|
9
|
+
- 7
|
10
|
+
version: 0.4.7
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- rick
|
14
|
+
- Cyril Mougel
|
15
|
+
autorequire:
|
16
|
+
bindir: bin
|
17
|
+
cert_chain: []
|
18
|
+
|
19
|
+
date: 2010-10-04 00:00:00 +02:00
|
20
|
+
default_executable:
|
21
|
+
dependencies:
|
22
|
+
- !ruby/object:Gem::Dependency
|
23
|
+
name: rack
|
24
|
+
prerelease: false
|
25
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ">="
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 21
|
31
|
+
segments:
|
32
|
+
- 1
|
33
|
+
- 0
|
34
|
+
- 1
|
35
|
+
version: 1.0.1
|
36
|
+
type: :runtime
|
37
|
+
version_requirements: *id001
|
38
|
+
- !ruby/object:Gem::Dependency
|
39
|
+
name: addressable
|
40
|
+
prerelease: false
|
41
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ">="
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 9
|
47
|
+
segments:
|
48
|
+
- 2
|
49
|
+
- 1
|
50
|
+
- 1
|
51
|
+
version: 2.1.1
|
52
|
+
type: :runtime
|
53
|
+
version_requirements: *id002
|
54
|
+
description: HTTP/REST API client library with pluggable components
|
55
|
+
email: technoweenie@gmail.com
|
56
|
+
executables: []
|
57
|
+
|
58
|
+
extensions: []
|
59
|
+
|
60
|
+
extra_rdoc_files:
|
61
|
+
- LICENSE
|
62
|
+
- README.rdoc
|
63
|
+
files:
|
64
|
+
- .document
|
65
|
+
- .gitignore
|
66
|
+
- LICENSE
|
67
|
+
- README.rdoc
|
68
|
+
- Rakefile
|
69
|
+
- VERSION
|
70
|
+
- faraday.gemspec
|
71
|
+
- lib/faraday.rb
|
72
|
+
- lib/faraday/adapter/action_dispatch.rb
|
73
|
+
- lib/faraday/adapter/net_http.rb
|
74
|
+
- lib/faraday/adapter/patron.rb
|
75
|
+
- lib/faraday/adapter/test.rb
|
76
|
+
- lib/faraday/adapter/typhoeus.rb
|
77
|
+
- lib/faraday/builder.rb
|
78
|
+
- lib/faraday/connection.rb
|
79
|
+
- lib/faraday/error.rb
|
80
|
+
- lib/faraday/middleware.rb
|
81
|
+
- lib/faraday/request.rb
|
82
|
+
- lib/faraday/request/active_support_json.rb
|
83
|
+
- lib/faraday/request/yajl.rb
|
84
|
+
- lib/faraday/response.rb
|
85
|
+
- lib/faraday/response/active_support_json.rb
|
86
|
+
- lib/faraday/response/nokogiri.rb
|
87
|
+
- lib/faraday/response/yajl.rb
|
88
|
+
- test/adapters/live_test.rb
|
89
|
+
- test/adapters/test_middleware_test.rb
|
90
|
+
- test/adapters/typhoeus_test.rb
|
91
|
+
- test/connection_app_test.rb
|
92
|
+
- test/connection_test.rb
|
93
|
+
- test/env_test.rb
|
94
|
+
- test/helper.rb
|
95
|
+
- test/live_server.rb
|
96
|
+
- test/request_middleware_test.rb
|
97
|
+
- test/response_middleware_test.rb
|
98
|
+
has_rdoc: true
|
99
|
+
homepage: http://github.com/shingara/faraday
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options:
|
104
|
+
- --charset=UTF-8
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
hash: 3
|
113
|
+
segments:
|
114
|
+
- 0
|
115
|
+
version: "0"
|
116
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
117
|
+
none: false
|
118
|
+
requirements:
|
119
|
+
- - ">="
|
120
|
+
- !ruby/object:Gem::Version
|
121
|
+
hash: 3
|
122
|
+
segments:
|
123
|
+
- 0
|
124
|
+
version: "0"
|
125
|
+
requirements: []
|
126
|
+
|
127
|
+
rubyforge_project:
|
128
|
+
rubygems_version: 1.3.7
|
129
|
+
signing_key:
|
130
|
+
specification_version: 3
|
131
|
+
summary: HTTP/REST API client library
|
132
|
+
test_files:
|
133
|
+
- test/adapters/live_test.rb
|
134
|
+
- test/adapters/test_middleware_test.rb
|
135
|
+
- test/adapters/typhoeus_test.rb
|
136
|
+
- test/connection_app_test.rb
|
137
|
+
- test/connection_test.rb
|
138
|
+
- test/env_test.rb
|
139
|
+
- test/helper.rb
|
140
|
+
- test/live_server.rb
|
141
|
+
- test/request_middleware_test.rb
|
142
|
+
- test/response_middleware_test.rb
|