faraday 0.4.6 → 0.5.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/Gemfile +3 -0
- data/Gemfile.lock +28 -0
- data/README.md +84 -0
- data/Rakefile +111 -34
- data/faraday.gemspec +85 -82
- data/lib/faraday.rb +17 -26
- data/lib/faraday/adapter.rb +102 -0
- data/lib/faraday/adapter/action_dispatch.rb +39 -0
- data/lib/faraday/adapter/net_http.rb +20 -8
- data/lib/faraday/adapter/patron.rb +10 -4
- data/lib/faraday/adapter/test.rb +28 -15
- data/lib/faraday/adapter/typhoeus.rb +16 -6
- data/lib/faraday/builder.rb +6 -6
- data/lib/faraday/connection.rb +33 -46
- data/lib/faraday/error.rb +25 -1
- data/lib/faraday/middleware.rb +0 -30
- data/lib/faraday/request.rb +5 -5
- data/lib/faraday/request/active_support_json.rb +1 -1
- data/lib/faraday/request/yajl.rb +1 -1
- data/lib/faraday/response/active_support_json.rb +9 -2
- data/lib/faraday/response/yajl.rb +8 -2
- data/lib/faraday/upload_io.rb +15 -0
- data/lib/faraday/utils.rb +64 -0
- data/test/adapters/live_test.rb +24 -15
- data/test/adapters/test_middleware_test.rb +11 -0
- data/test/connection_test.rb +6 -7
- data/test/env_test.rb +2 -2
- data/test/form_post_test.rb +42 -0
- data/test/helper.rb +6 -2
- data/test/live_server.rb +6 -1
- data/test/multipart_test.rb +48 -0
- data/test/request_middleware_test.rb +9 -2
- data/test/response_middleware_test.rb +8 -1
- metadata +75 -29
- data/.document +0 -5
- data/.gitignore +0 -21
- data/README.rdoc +0 -86
- data/VERSION +0 -1
data/Gemfile
ADDED
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
PATH
|
2
|
+
remote: .
|
3
|
+
specs:
|
4
|
+
faraday (0.4.6)
|
5
|
+
addressable (~> 2.1.1)
|
6
|
+
multipart-post (~> 1.0.1)
|
7
|
+
rack (~> 1.0.1)
|
8
|
+
|
9
|
+
GEM
|
10
|
+
remote: http://rubygems.org/
|
11
|
+
specs:
|
12
|
+
addressable (2.1.2)
|
13
|
+
multipart-post (1.0.1)
|
14
|
+
rack (1.0.1)
|
15
|
+
rake (0.8.7)
|
16
|
+
sinatra (1.0)
|
17
|
+
rack (>= 1.0)
|
18
|
+
|
19
|
+
PLATFORMS
|
20
|
+
ruby
|
21
|
+
|
22
|
+
DEPENDENCIES
|
23
|
+
addressable (~> 2.1.1)
|
24
|
+
faraday!
|
25
|
+
multipart-post (~> 1.0.1)
|
26
|
+
rack (~> 1.0.1)
|
27
|
+
rake (~> 0.8.7)
|
28
|
+
sinatra (~> 1.0.0)
|
data/README.md
ADDED
@@ -0,0 +1,84 @@
|
|
1
|
+
# faraday
|
2
|
+
|
3
|
+
Modular HTTP client library using middleware heavily inspired by Rack.
|
4
|
+
|
5
|
+
This mess is gonna get raw, like sushi. So, haters to the left.
|
6
|
+
|
7
|
+
## Usage
|
8
|
+
|
9
|
+
conn = Faraday::Connection.new(:url => 'http://sushi.com') do |builder|
|
10
|
+
builder.use Faraday::Request::Yajl # convert body to json with Yajl lib
|
11
|
+
builder.use Faraday::Adapter::Logger # log the request somewhere?
|
12
|
+
builder.use Faraday::Adapter::Typhoeus # make http request with typhoeus
|
13
|
+
builder.use Faraday::Response::Yajl # # parse body with yajl
|
14
|
+
|
15
|
+
# or use shortcuts
|
16
|
+
builder.request :yajl # Faraday::Request::Yajl
|
17
|
+
builder.adapter :logger # Faraday::Adapter::Logger
|
18
|
+
builder.adapter :typhoeus # Faraday::Adapter::Typhoeus
|
19
|
+
builder.response :yajl # Faraday::Response::Yajl
|
20
|
+
end
|
21
|
+
|
22
|
+
resp1 = conn.get '/nigiri/sake.json'
|
23
|
+
resp2 = conn.post do |req|
|
24
|
+
req.url "/nigiri.json", :page => 2
|
25
|
+
req[:content_type] = 'application/json'
|
26
|
+
req.body = {:name => 'Unagi'}
|
27
|
+
end
|
28
|
+
|
29
|
+
# If you're ready to roll with just the bare minimum (net/http):
|
30
|
+
resp1 = Faraday.get 'http://sushi.com/nigiri/sake.json'
|
31
|
+
|
32
|
+
## Testing
|
33
|
+
|
34
|
+
# It's possible to define stubbed request outside a test adapter block.
|
35
|
+
stubs = Faraday::Test::Stubs.new do |stub|
|
36
|
+
stub.get('/tamago') { [200, {}, 'egg'] }
|
37
|
+
end
|
38
|
+
|
39
|
+
# You can pass stubbed request to the test adapter or define them in a block
|
40
|
+
# or a combination of the two.
|
41
|
+
test = Faraday::Connection.new do |builder|
|
42
|
+
builder.adapter :test, stubs do |stub|
|
43
|
+
stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
|
44
|
+
end
|
45
|
+
end
|
46
|
+
|
47
|
+
# It's also possible to stub additional requests after the connection has
|
48
|
+
# been initialized. This is useful for testing.
|
49
|
+
stubs.get('/uni') {[ 200, {}, 'urchin' ]}
|
50
|
+
|
51
|
+
resp = test.get '/tamago'
|
52
|
+
resp.body # => 'egg'
|
53
|
+
resp = test.get '/ebi'
|
54
|
+
resp.body # => 'shrimp'
|
55
|
+
resp = test.get '/uni'
|
56
|
+
resp.body # => 'urchin'
|
57
|
+
resp = test.get '/else' #=> raises "no such stub" error
|
58
|
+
|
59
|
+
# If you like, you can treat your stubs as mocks by verifying that all of
|
60
|
+
# the stubbed calls were made. NOTE that this feature is still fairly
|
61
|
+
# experimental: It will not verify the order or count of any stub, only that
|
62
|
+
# it was called once during the course of the test.
|
63
|
+
stubs.verify_stubbed_calls
|
64
|
+
|
65
|
+
## TODO
|
66
|
+
|
67
|
+
* support streaming requests/responses
|
68
|
+
* better stubbing API
|
69
|
+
* Support timeouts
|
70
|
+
* Add curb, em-http, fast_http
|
71
|
+
|
72
|
+
## Note on Patches/Pull Requests
|
73
|
+
|
74
|
+
* Fork the project.
|
75
|
+
* Make your feature addition or bug fix.
|
76
|
+
* Add tests for it. This is important so I don't break it in a
|
77
|
+
future version unintentionally.
|
78
|
+
* Commit, do not mess with rakefile, version, or history.
|
79
|
+
(if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
|
80
|
+
* Send me a pull request. Bonus points for topic branches.
|
81
|
+
|
82
|
+
## Copyright
|
83
|
+
|
84
|
+
Copyright (c) 2009-2010 rick, hobson. See LICENSE for details.
|
data/Rakefile
CHANGED
@@ -1,25 +1,50 @@
|
|
1
1
|
require 'rubygems'
|
2
2
|
require 'rake'
|
3
|
+
require 'date'
|
3
4
|
|
4
|
-
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
5
|
+
#############################################################################
|
6
|
+
#
|
7
|
+
# Helper functions
|
8
|
+
#
|
9
|
+
#############################################################################
|
10
|
+
|
11
|
+
def name
|
12
|
+
@name ||= Dir['*.gemspec'].first.split('.').first
|
13
|
+
end
|
14
|
+
|
15
|
+
def version
|
16
|
+
line = File.read("lib/#{name}.rb")[/^\s*VERSION\s*=\s*.*/]
|
17
|
+
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
18
|
+
end
|
19
|
+
|
20
|
+
def date
|
21
|
+
Date.today.to_s
|
22
|
+
end
|
17
23
|
|
18
|
-
|
19
|
-
|
20
|
-
puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
|
24
|
+
def rubyforge_project
|
25
|
+
name
|
21
26
|
end
|
22
27
|
|
28
|
+
def gemspec_file
|
29
|
+
"#{name}.gemspec"
|
30
|
+
end
|
31
|
+
|
32
|
+
def gem_file
|
33
|
+
"#{name}-#{version}.gem"
|
34
|
+
end
|
35
|
+
|
36
|
+
def replace_header(head, header_name)
|
37
|
+
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
38
|
+
end
|
39
|
+
|
40
|
+
#############################################################################
|
41
|
+
#
|
42
|
+
# Standard tasks
|
43
|
+
#
|
44
|
+
#############################################################################
|
45
|
+
|
46
|
+
task :default => :test
|
47
|
+
|
23
48
|
require 'rake/testtask'
|
24
49
|
Rake::TestTask.new(:test) do |test|
|
25
50
|
test.libs << 'lib' << 'test'
|
@@ -27,27 +52,79 @@ Rake::TestTask.new(:test) do |test|
|
|
27
52
|
test.verbose = true
|
28
53
|
end
|
29
54
|
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
55
|
+
desc "Open an irb session preloaded with this library"
|
56
|
+
task :console do
|
57
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
58
|
+
end
|
59
|
+
|
60
|
+
#############################################################################
|
61
|
+
#
|
62
|
+
# Custom tasks (add your own tasks here)
|
63
|
+
#
|
64
|
+
#############################################################################
|
65
|
+
|
66
|
+
|
67
|
+
|
68
|
+
#############################################################################
|
69
|
+
#
|
70
|
+
# Packaging tasks
|
71
|
+
#
|
72
|
+
#############################################################################
|
73
|
+
|
74
|
+
task :release => :build do
|
75
|
+
unless `git branch` =~ /^\* master$/
|
76
|
+
puts "You must be on the master branch to release!"
|
77
|
+
exit!
|
40
78
|
end
|
79
|
+
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
80
|
+
sh "git tag v#{version}"
|
81
|
+
sh "git push origin master"
|
82
|
+
sh "git push origin v#{version}"
|
83
|
+
sh "gem push pkg/#{name}-#{version}.gem"
|
41
84
|
end
|
42
85
|
|
43
|
-
task :
|
86
|
+
task :build => :gemspec do
|
87
|
+
sh "mkdir -p pkg"
|
88
|
+
sh "gem build #{gemspec_file}"
|
89
|
+
sh "mv #{gem_file} pkg"
|
90
|
+
end
|
91
|
+
|
92
|
+
task :gemspec => :validate do
|
93
|
+
# read spec file and split out manifest section
|
94
|
+
spec = File.read(gemspec_file)
|
95
|
+
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
96
|
+
|
97
|
+
# replace name version and date
|
98
|
+
replace_header(head, :name)
|
99
|
+
replace_header(head, :version)
|
100
|
+
replace_header(head, :date)
|
101
|
+
#comment this out if your rubyforge_project has a different name
|
102
|
+
replace_header(head, :rubyforge_project)
|
44
103
|
|
45
|
-
|
46
|
-
|
47
|
-
|
104
|
+
# determine file list from git ls-files
|
105
|
+
files = `git ls-files`.
|
106
|
+
split("\n").
|
107
|
+
sort.
|
108
|
+
reject { |file| file =~ /^\./ }.
|
109
|
+
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
110
|
+
map { |file| " #{file}" }.
|
111
|
+
join("\n")
|
48
112
|
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
113
|
+
# piece file back together and write
|
114
|
+
manifest = " s.files = %w[\n#{files}\n ]\n"
|
115
|
+
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
116
|
+
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
117
|
+
puts "Updated #{gemspec_file}"
|
53
118
|
end
|
119
|
+
|
120
|
+
task :validate do
|
121
|
+
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
122
|
+
unless libfiles.empty?
|
123
|
+
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
124
|
+
exit!
|
125
|
+
end
|
126
|
+
unless Dir['VERSION*'].empty?
|
127
|
+
puts "A `VERSION` file at root level violates Gem best practices."
|
128
|
+
exit!
|
129
|
+
end
|
130
|
+
end
|
data/faraday.gemspec
CHANGED
@@ -1,87 +1,90 @@
|
|
1
|
-
|
2
|
-
|
3
|
-
|
4
|
-
|
5
|
-
|
1
|
+
## This is the rakegem gemspec template. Make sure you read and understand
|
2
|
+
## all of the comments. Some sections require modification, and others can
|
3
|
+
## be deleted if you don't need them. Once you understand the contents of
|
4
|
+
## this file, feel free to delete any comments that begin with two hash marks.
|
5
|
+
## You can find comprehensive Gem::Specification documentation, at
|
6
|
+
## http://docs.rubygems.org/read/chapter/20
|
6
7
|
Gem::Specification.new do |s|
|
7
|
-
s.
|
8
|
-
s.version = "0.4.6"
|
9
|
-
|
8
|
+
s.specification_version = 2 if s.respond_to? :specification_version=
|
10
9
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
-
s.
|
12
|
-
s.date = %q{2010-05-28}
|
13
|
-
s.description = %q{HTTP/REST API client library with pluggable components}
|
14
|
-
s.email = %q{technoweenie@gmail.com}
|
15
|
-
s.extra_rdoc_files = [
|
16
|
-
"LICENSE",
|
17
|
-
"README.rdoc"
|
18
|
-
]
|
19
|
-
s.files = [
|
20
|
-
".document",
|
21
|
-
".gitignore",
|
22
|
-
"LICENSE",
|
23
|
-
"README.rdoc",
|
24
|
-
"Rakefile",
|
25
|
-
"VERSION",
|
26
|
-
"faraday.gemspec",
|
27
|
-
"lib/faraday.rb",
|
28
|
-
"lib/faraday/adapter/net_http.rb",
|
29
|
-
"lib/faraday/adapter/patron.rb",
|
30
|
-
"lib/faraday/adapter/test.rb",
|
31
|
-
"lib/faraday/adapter/typhoeus.rb",
|
32
|
-
"lib/faraday/builder.rb",
|
33
|
-
"lib/faraday/connection.rb",
|
34
|
-
"lib/faraday/error.rb",
|
35
|
-
"lib/faraday/middleware.rb",
|
36
|
-
"lib/faraday/request.rb",
|
37
|
-
"lib/faraday/request/active_support_json.rb",
|
38
|
-
"lib/faraday/request/yajl.rb",
|
39
|
-
"lib/faraday/response.rb",
|
40
|
-
"lib/faraday/response/active_support_json.rb",
|
41
|
-
"lib/faraday/response/yajl.rb",
|
42
|
-
"test/adapters/live_test.rb",
|
43
|
-
"test/adapters/test_middleware_test.rb",
|
44
|
-
"test/adapters/typhoeus_test.rb",
|
45
|
-
"test/connection_app_test.rb",
|
46
|
-
"test/connection_test.rb",
|
47
|
-
"test/env_test.rb",
|
48
|
-
"test/helper.rb",
|
49
|
-
"test/live_server.rb",
|
50
|
-
"test/request_middleware_test.rb",
|
51
|
-
"test/response_middleware_test.rb"
|
52
|
-
]
|
53
|
-
s.homepage = %q{http://github.com/technoweenie/faraday}
|
54
|
-
s.rdoc_options = ["--charset=UTF-8"]
|
55
|
-
s.require_paths = ["lib"]
|
56
|
-
s.rubygems_version = %q{1.3.6}
|
57
|
-
s.summary = %q{HTTP/REST API client library}
|
58
|
-
s.test_files = [
|
59
|
-
"test/adapters/live_test.rb",
|
60
|
-
"test/adapters/test_middleware_test.rb",
|
61
|
-
"test/adapters/typhoeus_test.rb",
|
62
|
-
"test/connection_app_test.rb",
|
63
|
-
"test/connection_test.rb",
|
64
|
-
"test/env_test.rb",
|
65
|
-
"test/helper.rb",
|
66
|
-
"test/live_server.rb",
|
67
|
-
"test/request_middleware_test.rb",
|
68
|
-
"test/response_middleware_test.rb"
|
69
|
-
]
|
10
|
+
s.rubygems_version = '1.3.5'
|
70
11
|
|
71
|
-
|
72
|
-
|
73
|
-
|
12
|
+
## Leave these as is they will be modified for you by the rake gemspec task.
|
13
|
+
## If your rubyforge_project name is different, then edit it and comment out
|
14
|
+
## the sub! line in the Rakefile
|
15
|
+
s.name = 'faraday'
|
16
|
+
s.version = '0.5.0'
|
17
|
+
s.date = '2010-10-08'
|
18
|
+
s.rubyforge_project = 'faraday'
|
74
19
|
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
20
|
+
## Make sure your summary is short. The description may be as long
|
21
|
+
## as you like.
|
22
|
+
s.summary = "HTTP/REST API client library."
|
23
|
+
s.description = "HTTP/REST API client library."
|
24
|
+
|
25
|
+
## List the primary authors. If there are a bunch of authors, it's probably
|
26
|
+
## better to set the email to an email list or something. If you don't have
|
27
|
+
## a custom homepage, consider using your GitHub URL or the like.
|
28
|
+
s.authors = ["Rick Olson"]
|
29
|
+
s.email = 'technoweenie@gmail.com'
|
30
|
+
s.homepage = 'http://github.com/technoweenie/faraday'
|
31
|
+
|
32
|
+
## This gets added to the $LOAD_PATH so that 'lib/NAME.rb' can be required as
|
33
|
+
## require 'NAME.rb' or'/lib/NAME/file.rb' can be as require 'NAME/file.rb'
|
34
|
+
s.require_paths = %w[lib]
|
35
|
+
|
36
|
+
s.add_development_dependency('rake', ['~> 0.8.7'])
|
37
|
+
s.add_development_dependency('sinatra', ['~> 1.0.0'])
|
38
|
+
s.add_runtime_dependency('addressable', ['~> 2.1.1'])
|
39
|
+
s.add_runtime_dependency('multipart-post', ['~> 1.0.1'])
|
40
|
+
s.add_runtime_dependency('rack', ['~> 1.2.1'])
|
41
|
+
|
42
|
+
## Leave this section as-is. It will be automatically generated from the
|
43
|
+
## contents of your Git repository via the gemspec task. DO NOT REMOVE
|
44
|
+
## THE MANIFEST COMMENTS, they are used as delimiters by the task.
|
45
|
+
# = MANIFEST =
|
46
|
+
s.files = %w[
|
47
|
+
Gemfile
|
48
|
+
Gemfile.lock
|
49
|
+
LICENSE
|
50
|
+
README.md
|
51
|
+
Rakefile
|
52
|
+
faraday.gemspec
|
53
|
+
lib/faraday.rb
|
54
|
+
lib/faraday/adapter.rb
|
55
|
+
lib/faraday/adapter/action_dispatch.rb
|
56
|
+
lib/faraday/adapter/net_http.rb
|
57
|
+
lib/faraday/adapter/patron.rb
|
58
|
+
lib/faraday/adapter/test.rb
|
59
|
+
lib/faraday/adapter/typhoeus.rb
|
60
|
+
lib/faraday/builder.rb
|
61
|
+
lib/faraday/connection.rb
|
62
|
+
lib/faraday/error.rb
|
63
|
+
lib/faraday/middleware.rb
|
64
|
+
lib/faraday/request.rb
|
65
|
+
lib/faraday/request/active_support_json.rb
|
66
|
+
lib/faraday/request/yajl.rb
|
67
|
+
lib/faraday/response.rb
|
68
|
+
lib/faraday/response/active_support_json.rb
|
69
|
+
lib/faraday/response/yajl.rb
|
70
|
+
lib/faraday/upload_io.rb
|
71
|
+
lib/faraday/utils.rb
|
72
|
+
test/adapters/live_test.rb
|
73
|
+
test/adapters/test_middleware_test.rb
|
74
|
+
test/adapters/typhoeus_test.rb
|
75
|
+
test/connection_app_test.rb
|
76
|
+
test/connection_test.rb
|
77
|
+
test/env_test.rb
|
78
|
+
test/form_post_test.rb
|
79
|
+
test/helper.rb
|
80
|
+
test/live_server.rb
|
81
|
+
test/multipart_test.rb
|
82
|
+
test/request_middleware_test.rb
|
83
|
+
test/response_middleware_test.rb
|
84
|
+
]
|
85
|
+
# = MANIFEST =
|
87
86
|
|
87
|
+
## Test files will be grabbed from the file list. Make sure the path glob
|
88
|
+
## matches what you actually use.
|
89
|
+
s.test_files = s.files.select { |path| path =~ /^test\/.*_test\.rb/ }
|
90
|
+
end
|