faraday-curb 0.0.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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +19 -0
- data/Rakefile +2 -0
- data/faraday-curb.gemspec +26 -0
- data/lib/faraday/adapter/curb.rb +69 -0
- data/lib/faraday/curb.rb +2 -0
- data/lib/faraday/curb/version.rb +5 -0
- metadata +110 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d17c8dd124c1124a29dcb306c890ac3b52dd2556
|
4
|
+
data.tar.gz: fdfbc79c333e200b8ef792c9b8112fb8c8d4d403
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 8c564602e0f2c55eedf2045c9ca4165270a4fdb1fde8158c6e0ce439184707b4e656a2fa4c6687fd31d0be2c2f56f8d0ed1e3b7300f0c5bea1a649a924852e71
|
7
|
+
data.tar.gz: 27896f36aea9c8430a677d430869a8f32f98d86bb7f28eb84bd946226374844908813468bc18d5698eaa1723f90908ef8929ae8d0d83ff0cf9571cd182450b52
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 Aaron
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Faraday::Curb
|
2
|
+
|
3
|
+
A Curb adapter for Faraday.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'faraday-curb'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install faraday-curb
|
data/Rakefile
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'faraday/curb/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "faraday-curb"
|
8
|
+
spec.version = Faraday::Curb::VERSION
|
9
|
+
spec.authors = ["Aaron Eisenberger"]
|
10
|
+
spec.email = ["aaron@bitium.com"]
|
11
|
+
spec.summary = %q{A Curb adapter for Faraday.}
|
12
|
+
#spec.description = %q{TODO: Write a longer description. Optional.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib"]
|
20
|
+
|
21
|
+
spec.add_dependency "curb"
|
22
|
+
spec.add_dependency "faraday"
|
23
|
+
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
@@ -0,0 +1,69 @@
|
|
1
|
+
module Faraday
|
2
|
+
class Adapter
|
3
|
+
class Curb < Faraday::Adapter
|
4
|
+
dependency 'curb'
|
5
|
+
|
6
|
+
def call(env)
|
7
|
+
super
|
8
|
+
perform_request env
|
9
|
+
@app.call env
|
10
|
+
end
|
11
|
+
|
12
|
+
private
|
13
|
+
|
14
|
+
def perform_request(env)
|
15
|
+
read_body env
|
16
|
+
|
17
|
+
client = ::Curl::Easy.new(env[:url].to_s) do |c|
|
18
|
+
c.headers = env[:request_headers]
|
19
|
+
end
|
20
|
+
|
21
|
+
configure_timeout(client, env)
|
22
|
+
|
23
|
+
client.send(*(["http_#{env[:method]}", env[:body]].compact))
|
24
|
+
save_response(env, client.response_code, client.body_str, parse_header_string(client.header_str).last)
|
25
|
+
rescue Curl::Err::ConnectionFailedError => e
|
26
|
+
raise Faraday::Error::ConnectionFailed, e
|
27
|
+
rescue Curl::Err::TimeoutError => e
|
28
|
+
raise Faraday::Error::TimeoutError, e
|
29
|
+
end
|
30
|
+
|
31
|
+
def read_body(env)
|
32
|
+
env[:body] = env[:body].read if env[:body].respond_to? :read
|
33
|
+
end
|
34
|
+
|
35
|
+
def configure_timeout(client, env)
|
36
|
+
req = env[:request]
|
37
|
+
client.timeout = req[:timeout] if req[:timeout]
|
38
|
+
client.connect_timeout = req[:open_timeout] if req[:open_timeout]
|
39
|
+
end
|
40
|
+
|
41
|
+
# Borrowed from Webmock's Curb adapter:
|
42
|
+
# http://github.com/bblimke/webmock/blob/master/lib/webmock/http_lib_adapters/curb.rb
|
43
|
+
def parse_header_string(header_string)
|
44
|
+
status, headers = nil, {}
|
45
|
+
return [status, headers] unless header_string
|
46
|
+
|
47
|
+
header_string.split(/\r\n/).each do |header|
|
48
|
+
if header =~ %r|^HTTP/1.[01] \d\d\d (.*)|
|
49
|
+
status = $1
|
50
|
+
else
|
51
|
+
parts = header.split(':', 2)
|
52
|
+
unless parts.empty?
|
53
|
+
parts[1].strip! unless parts[1].nil?
|
54
|
+
if headers.has_key?(parts[0])
|
55
|
+
headers[parts[0]] = [headers[parts[0]]] unless headers[parts[0]].kind_of? Array
|
56
|
+
headers[parts[0]] << parts[1]
|
57
|
+
else
|
58
|
+
headers[parts[0]] = parts[1]
|
59
|
+
end
|
60
|
+
end
|
61
|
+
end
|
62
|
+
end
|
63
|
+
|
64
|
+
[status, headers]
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
end
|
69
|
+
end
|
data/lib/faraday/curb.rb
ADDED
metadata
ADDED
@@ -0,0 +1,110 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: faraday-curb
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Aaron Eisenberger
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: curb
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: faraday
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: bundler
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '1.7'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '1.7'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: rake
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '10.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '10.0'
|
69
|
+
description:
|
70
|
+
email:
|
71
|
+
- aaron@bitium.com
|
72
|
+
executables: []
|
73
|
+
extensions: []
|
74
|
+
extra_rdoc_files: []
|
75
|
+
files:
|
76
|
+
- ".gitignore"
|
77
|
+
- Gemfile
|
78
|
+
- LICENSE.txt
|
79
|
+
- README.md
|
80
|
+
- Rakefile
|
81
|
+
- faraday-curb.gemspec
|
82
|
+
- lib/faraday/adapter/curb.rb
|
83
|
+
- lib/faraday/curb.rb
|
84
|
+
- lib/faraday/curb/version.rb
|
85
|
+
homepage: ''
|
86
|
+
licenses:
|
87
|
+
- MIT
|
88
|
+
metadata: {}
|
89
|
+
post_install_message:
|
90
|
+
rdoc_options: []
|
91
|
+
require_paths:
|
92
|
+
- lib
|
93
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
94
|
+
requirements:
|
95
|
+
- - ">="
|
96
|
+
- !ruby/object:Gem::Version
|
97
|
+
version: '0'
|
98
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
99
|
+
requirements:
|
100
|
+
- - ">="
|
101
|
+
- !ruby/object:Gem::Version
|
102
|
+
version: '0'
|
103
|
+
requirements: []
|
104
|
+
rubyforge_project:
|
105
|
+
rubygems_version: 2.4.2
|
106
|
+
signing_key:
|
107
|
+
specification_version: 4
|
108
|
+
summary: A Curb adapter for Faraday.
|
109
|
+
test_files: []
|
110
|
+
has_rdoc:
|