faraday 0.6.0 → 0.9.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.
- checksums.yaml +7 -0
- data/.document +6 -0
- data/CHANGELOG.md +15 -0
- data/CONTRIBUTING.md +36 -0
- data/Gemfile +25 -15
- data/{LICENSE → LICENSE.md} +1 -1
- data/README.md +187 -137
- data/Rakefile +38 -101
- data/faraday.gemspec +26 -81
- data/lib/faraday/adapter/em_http.rb +237 -0
- data/lib/faraday/adapter/em_http_ssl_patch.rb +56 -0
- data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +66 -0
- data/lib/faraday/adapter/em_synchrony.rb +65 -38
- data/lib/faraday/adapter/excon.rb +60 -9
- data/lib/faraday/adapter/httpclient.rb +106 -0
- data/lib/faraday/adapter/net_http.rb +89 -38
- data/lib/faraday/adapter/net_http_persistent.rb +47 -0
- data/lib/faraday/adapter/patron.rb +46 -9
- data/lib/faraday/adapter/rack.rb +58 -0
- data/lib/faraday/adapter/test.rb +68 -28
- data/lib/faraday/adapter/typhoeus.rb +94 -16
- data/lib/faraday/adapter.rb +33 -25
- data/lib/faraday/autoload.rb +85 -0
- data/lib/faraday/connection.rb +342 -134
- data/lib/faraday/error.rb +44 -29
- data/lib/faraday/middleware.rb +18 -10
- data/lib/faraday/options.rb +350 -0
- data/lib/faraday/parameters.rb +193 -0
- data/lib/faraday/rack_builder.rb +212 -0
- data/lib/faraday/request/authorization.rb +42 -0
- data/lib/faraday/request/basic_authentication.rb +13 -0
- data/lib/faraday/request/instrumentation.rb +36 -0
- data/lib/faraday/request/multipart.rb +15 -15
- data/lib/faraday/request/retry.rb +118 -0
- data/lib/faraday/request/token_authentication.rb +15 -0
- data/lib/faraday/request/url_encoded.rb +8 -9
- data/lib/faraday/request.rb +46 -45
- data/lib/faraday/response/logger.rb +4 -4
- data/lib/faraday/response/raise_error.rb +8 -3
- data/lib/faraday/response.rb +20 -25
- data/lib/faraday/upload_io.rb +51 -7
- data/lib/faraday/utils.rb +240 -44
- data/lib/faraday.rb +218 -38
- data/script/console +7 -0
- data/script/generate_certs +42 -0
- data/script/package +7 -0
- data/script/proxy-server +42 -0
- data/script/release +17 -0
- data/script/server +36 -0
- data/script/test +172 -0
- data/test/adapters/default_test.rb +14 -0
- data/test/adapters/em_http_test.rb +20 -0
- data/test/adapters/em_synchrony_test.rb +20 -0
- data/test/adapters/excon_test.rb +20 -0
- data/test/adapters/httpclient_test.rb +21 -0
- data/test/adapters/integration.rb +254 -0
- data/test/adapters/logger_test.rb +3 -3
- data/test/adapters/net_http_persistent_test.rb +20 -0
- data/test/adapters/net_http_test.rb +6 -25
- data/test/adapters/patron_test.rb +20 -0
- data/test/adapters/rack_test.rb +31 -0
- data/test/adapters/test_middleware_test.rb +74 -3
- data/test/adapters/typhoeus_test.rb +28 -0
- data/test/authentication_middleware_test.rb +65 -0
- data/test/composite_read_io_test.rb +111 -0
- data/test/connection_test.rb +381 -104
- data/test/env_test.rb +116 -40
- data/test/helper.rb +61 -25
- data/test/live_server.rb +55 -29
- data/test/middleware/instrumentation_test.rb +88 -0
- data/test/middleware/retry_test.rb +109 -0
- data/test/middleware_stack_test.rb +87 -5
- data/test/multibyte.txt +1 -0
- data/test/options_test.rb +252 -0
- data/test/request_middleware_test.rb +78 -21
- data/test/response_middleware_test.rb +32 -7
- data/test/strawberry.rb +2 -0
- data/test/utils_test.rb +58 -0
- metadata +116 -117
- data/lib/faraday/adapter/action_dispatch.rb +0 -30
- data/lib/faraday/builder.rb +0 -137
- data/lib/faraday/request/json.rb +0 -31
- data/test/adapters/live_test.rb +0 -186
checksums.yaml
ADDED
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
---
|
|
2
|
+
SHA1:
|
|
3
|
+
metadata.gz: 0e442daff424089e143751d7cb1d684c169bf4fc
|
|
4
|
+
data.tar.gz: ba1dd50171576d5064350e48b8869364c0710a26
|
|
5
|
+
SHA512:
|
|
6
|
+
metadata.gz: 80c7a955f7d0a2217fcde0be2760649b9e5fc2d950929b118383ba61ea7282410b224315e289b40fec12be13898b0b00551e441704462ac39269368a8f9d5931
|
|
7
|
+
data.tar.gz: cdef47ebdb9519d0e45e7511326ed1368fa520ad314a4055ea154187193c967f8821573705161e3bbca5d3cbbf40f219071223ba8d24821c5dd89e37ddd16a9e
|
data/.document
ADDED
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
# Faraday Changelog
|
|
2
|
+
|
|
3
|
+
## v0.9.0
|
|
4
|
+
|
|
5
|
+
* Add HTTPClient adapter (@hakanensari)
|
|
6
|
+
* Improve Retry handler (@mislav)
|
|
7
|
+
* Remove autoloading by default (@technoweenie)
|
|
8
|
+
* Improve internal docs (@technoweenie, @mislav)
|
|
9
|
+
* Respect user/password in http proxy string (@mislav)
|
|
10
|
+
* Adapter options are structs. Reinforces consistent options across adapters
|
|
11
|
+
(@technoweenie)
|
|
12
|
+
* Stop stripping trailing / off base URLs in a Faraday::Connection. (@technoweenie)
|
|
13
|
+
* Add a configurable URI parser. (@technoweenie)
|
|
14
|
+
* Remove need to manually autoload when using the authorization header helpers on `Faraday::Connection`. (@technoweenie)
|
|
15
|
+
* `Faraday::Adapter::Test` respects the `Faraday::RequestOptions#params_encoder` option. (@technoweenie)
|
data/CONTRIBUTING.md
ADDED
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
## Contributing
|
|
2
|
+
|
|
3
|
+
You can run the test suite against a live server by running `script/test`. It
|
|
4
|
+
automatically starts a test server in background. Only tests in
|
|
5
|
+
`test/adapters/*_test.rb` require a server, though.
|
|
6
|
+
|
|
7
|
+
``` sh
|
|
8
|
+
# run the whole suite
|
|
9
|
+
$ script/test
|
|
10
|
+
|
|
11
|
+
# run only specific files
|
|
12
|
+
$ script/test excon typhoeus
|
|
13
|
+
|
|
14
|
+
# run tests using SSL
|
|
15
|
+
$ SSL=yes script/test
|
|
16
|
+
```
|
|
17
|
+
|
|
18
|
+
We will accept middleware that:
|
|
19
|
+
|
|
20
|
+
1. is useful to a broader audience, but can be implemented relatively
|
|
21
|
+
simple; and
|
|
22
|
+
2. which isn't already present in [faraday_middleware][] project.
|
|
23
|
+
|
|
24
|
+
We will accept adapters that:
|
|
25
|
+
|
|
26
|
+
1. support SSL & streaming;
|
|
27
|
+
1. are proven and may have better performance than existing ones; or
|
|
28
|
+
2. if they have features not present in included adapters.
|
|
29
|
+
|
|
30
|
+
We are pushing towards a 1.0 release, when we will have to follow [Semantic
|
|
31
|
+
Versioning][semver]. If your patch includes changes to break compatiblitity,
|
|
32
|
+
note that so we can add it to the [Changelog][].
|
|
33
|
+
|
|
34
|
+
[semver]: http://semver.org/
|
|
35
|
+
[changelog]: https://github.com/technoweenie/faraday/wiki/Changelog
|
|
36
|
+
[faraday_middleware]: https://github.com/pengwynn/faraday_middleware/wiki
|
data/Gemfile
CHANGED
|
@@ -1,19 +1,29 @@
|
|
|
1
|
-
source
|
|
1
|
+
source 'https://rubygems.org'
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
gem '
|
|
9
|
-
gem '
|
|
10
|
-
gem '
|
|
11
|
-
gem '
|
|
12
|
-
gem '
|
|
13
|
-
gem '
|
|
14
|
-
|
|
15
|
-
gem '
|
|
16
|
-
gem '
|
|
3
|
+
gem 'ffi-ncurses', '~> 0.3', :platforms => :jruby
|
|
4
|
+
gem 'jruby-openssl', '~> 0.8.8', :platforms => :jruby
|
|
5
|
+
gem 'rake'
|
|
6
|
+
|
|
7
|
+
group :test do
|
|
8
|
+
gem 'coveralls', :require => false
|
|
9
|
+
gem 'em-http-request', '>= 1.1', :require => 'em-http'
|
|
10
|
+
gem 'em-synchrony', '>= 1.0.3', :require => ['em-synchrony', 'em-synchrony/em-http']
|
|
11
|
+
gem 'excon', '>= 0.27.4'
|
|
12
|
+
gem 'httpclient', '>= 2.2'
|
|
13
|
+
gem 'leftright', '>= 0.9', :require => false
|
|
14
|
+
gem 'mime-types', '~> 1.25', :platforms => [:jruby, :ruby_18]
|
|
15
|
+
gem 'minitest', '>= 5.0.5'
|
|
16
|
+
gem 'net-http-persistent', '>= 2.5', :require => false
|
|
17
|
+
gem 'patron', '>= 0.4.2', :platforms => :ruby
|
|
18
|
+
gem 'rack-test', '>= 0.6', :require => 'rack/test'
|
|
19
|
+
gem 'simplecov'
|
|
20
|
+
gem 'sinatra', '~> 1.3'
|
|
21
|
+
gem 'typhoeus', '~> 0.3.3', :platforms => :ruby
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
platforms :rbx do
|
|
25
|
+
gem 'rubinius-coverage'
|
|
26
|
+
gem 'rubysl'
|
|
17
27
|
end
|
|
18
28
|
|
|
19
29
|
gemspec
|
data/{LICENSE → LICENSE.md}
RENAMED
data/README.md
CHANGED
|
@@ -1,166 +1,216 @@
|
|
|
1
|
-
#
|
|
1
|
+
# Faraday
|
|
2
2
|
|
|
3
|
-
|
|
3
|
+
Faraday is an HTTP client lib that provides a common interface over many
|
|
4
|
+
adapters (such as Net::HTTP) and embraces the concept of Rack middleware when
|
|
5
|
+
processing the request/response cycle.
|
|
4
6
|
|
|
5
|
-
|
|
7
|
+
Faraday supports these adapters:
|
|
8
|
+
|
|
9
|
+
* Net::HTTP
|
|
10
|
+
* [Excon][]
|
|
11
|
+
* [Typhoeus][]
|
|
12
|
+
* [Patron][]
|
|
13
|
+
* [EventMachine][]
|
|
14
|
+
|
|
15
|
+
It also includes a Rack adapter for hitting loaded Rack applications through
|
|
16
|
+
Rack::Test, and a Test adapter for stubbing requests by hand.
|
|
6
17
|
|
|
7
18
|
## Usage
|
|
8
19
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
If you'
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
20
|
+
```ruby
|
|
21
|
+
conn = Faraday.new(:url => 'http://sushi.com') do |faraday|
|
|
22
|
+
faraday.request :url_encoded # form-encode POST params
|
|
23
|
+
faraday.response :logger # log requests to STDOUT
|
|
24
|
+
faraday.adapter Faraday.default_adapter # make requests with Net::HTTP
|
|
25
|
+
end
|
|
26
|
+
|
|
27
|
+
## GET ##
|
|
28
|
+
|
|
29
|
+
response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
|
|
30
|
+
response.body
|
|
31
|
+
|
|
32
|
+
conn.get '/nigiri', { :name => 'Maguro' } # GET /nigiri?name=Maguro
|
|
33
|
+
|
|
34
|
+
conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
|
|
35
|
+
req.url '/search', :page => 2
|
|
36
|
+
req.params['limit'] = 100
|
|
37
|
+
end
|
|
38
|
+
|
|
39
|
+
## POST ##
|
|
40
|
+
|
|
41
|
+
conn.post '/nigiri', { :name => 'Maguro' } # POST "name=maguro" to http://sushi.com/nigiri
|
|
42
|
+
|
|
43
|
+
# post payload as JSON instead of "www-form-urlencoded" encoding:
|
|
44
|
+
conn.post do |req|
|
|
45
|
+
req.url '/nigiri'
|
|
46
|
+
req.headers['Content-Type'] = 'application/json'
|
|
47
|
+
req.body = '{ "name": "Unagi" }'
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
## Per-request options ##
|
|
51
|
+
|
|
52
|
+
conn.get do |req|
|
|
53
|
+
req.url '/search'
|
|
54
|
+
req.options.timeout = 5 # open/read timeout in seconds
|
|
55
|
+
req.options.open_timeout = 2 # connection open timeout in seconds
|
|
56
|
+
end
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
If you don't need to set up anything, you can roll with just the bare minimum:
|
|
60
|
+
|
|
61
|
+
```ruby
|
|
62
|
+
# using the default stack:
|
|
63
|
+
response = Faraday.get 'http://sushi.com/nigiri/sake.json'
|
|
64
|
+
```
|
|
52
65
|
|
|
53
66
|
## Advanced middleware usage
|
|
54
67
|
|
|
55
|
-
The order in which middleware is stacked is important. Like with Rack, the
|
|
68
|
+
The order in which middleware is stacked is important. Like with Rack, the
|
|
69
|
+
first middleware on the list wraps all others, while the last middleware is the
|
|
70
|
+
innermost one, so that must be the adapter.
|
|
56
71
|
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
72
|
+
```ruby
|
|
73
|
+
Faraday.new(...) do |conn|
|
|
74
|
+
# POST/PUT params encoders:
|
|
75
|
+
conn.request :multipart
|
|
76
|
+
conn.request :url_encoded
|
|
77
|
+
|
|
78
|
+
conn.adapter :net_http
|
|
79
|
+
end
|
|
80
|
+
```
|
|
65
81
|
|
|
66
82
|
This request middleware setup affects POST/PUT requests in the following way:
|
|
67
83
|
|
|
68
|
-
1. `Request::Multipart` checks for files in the payload, otherwise leaves
|
|
69
|
-
|
|
70
|
-
2. `Request::
|
|
84
|
+
1. `Request::Multipart` checks for files in the payload, otherwise leaves
|
|
85
|
+
everything untouched;
|
|
86
|
+
2. `Request::UrlEncoded` encodes as "application/x-www-form-urlencoded" if not
|
|
87
|
+
already encoded or of another type
|
|
71
88
|
|
|
72
|
-
|
|
89
|
+
Swapping middleware means giving the other priority. Specifying the
|
|
90
|
+
"Content-Type" for the request is explicitly stating which middleware should
|
|
91
|
+
process it.
|
|
73
92
|
|
|
74
93
|
Examples:
|
|
75
94
|
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
# "Multipart" middleware detects files and encodes with "multipart/form-data":
|
|
85
|
-
conn.put '/profile', payload
|
|
95
|
+
```ruby
|
|
96
|
+
# uploading a file:
|
|
97
|
+
payload[:profile_pic] = Faraday::UploadIO.new('/path/to/avatar.jpg', 'image/jpeg')
|
|
98
|
+
|
|
99
|
+
# "Multipart" middleware detects files and encodes with "multipart/form-data":
|
|
100
|
+
conn.put '/profile', payload
|
|
101
|
+
```
|
|
86
102
|
|
|
87
103
|
## Writing middleware
|
|
88
104
|
|
|
89
|
-
Middleware are classes that
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
105
|
+
Middleware are classes that implement a `call` instance method. They hook into
|
|
106
|
+
the request/response cycle.
|
|
107
|
+
|
|
108
|
+
```ruby
|
|
109
|
+
def call(env)
|
|
110
|
+
# do something with the request
|
|
111
|
+
|
|
112
|
+
@app.call(env).on_complete do
|
|
113
|
+
# do something with the response
|
|
114
|
+
end
|
|
115
|
+
end
|
|
116
|
+
```
|
|
117
|
+
|
|
118
|
+
It's important to do all processing of the response only in the `on_complete`
|
|
119
|
+
block. This enables middleware to work in parallel mode where requests are
|
|
120
|
+
asynchronous.
|
|
121
|
+
|
|
122
|
+
The `env` is a hash with symbol keys that contains info about the request and,
|
|
123
|
+
later, response. Some keys are:
|
|
124
|
+
|
|
125
|
+
```
|
|
126
|
+
# request phase
|
|
127
|
+
:method - :get, :post, ...
|
|
128
|
+
:url - URI for the current request; also contains GET parameters
|
|
129
|
+
:body - POST parameters for :post/:put requests
|
|
130
|
+
:request_headers
|
|
131
|
+
|
|
132
|
+
# response phase
|
|
133
|
+
:status - HTTP response status code, such as 200
|
|
134
|
+
:body - the response body
|
|
135
|
+
:response_headers
|
|
136
|
+
```
|
|
137
|
+
|
|
138
|
+
## Using Faraday for testing
|
|
139
|
+
|
|
140
|
+
```ruby
|
|
141
|
+
# It's possible to define stubbed request outside a test adapter block.
|
|
142
|
+
stubs = Faraday::Adapter::Test::Stubs.new do |stub|
|
|
143
|
+
stub.get('/tamago') { [200, {}, 'egg'] }
|
|
144
|
+
end
|
|
145
|
+
|
|
146
|
+
# You can pass stubbed request to the test adapter or define them in a block
|
|
147
|
+
# or a combination of the two.
|
|
148
|
+
test = Faraday.new do |builder|
|
|
149
|
+
builder.adapter :test, stubs do |stub|
|
|
150
|
+
stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
|
|
151
|
+
end
|
|
152
|
+
end
|
|
153
|
+
|
|
154
|
+
# It's also possible to stub additional requests after the connection has
|
|
155
|
+
# been initialized. This is useful for testing.
|
|
156
|
+
stubs.get('/uni') {[ 200, {}, 'urchin' ]}
|
|
157
|
+
|
|
158
|
+
resp = test.get '/tamago'
|
|
159
|
+
resp.body # => 'egg'
|
|
160
|
+
resp = test.get '/ebi'
|
|
161
|
+
resp.body # => 'shrimp'
|
|
162
|
+
resp = test.get '/uni'
|
|
163
|
+
resp.body # => 'urchin'
|
|
164
|
+
resp = test.get '/else' #=> raises "no such stub" error
|
|
165
|
+
|
|
166
|
+
# If you like, you can treat your stubs as mocks by verifying that all of
|
|
167
|
+
# the stubbed calls were made. NOTE that this feature is still fairly
|
|
168
|
+
# experimental: It will not verify the order or count of any stub, only that
|
|
169
|
+
# it was called once during the course of the test.
|
|
170
|
+
stubs.verify_stubbed_calls
|
|
171
|
+
```
|
|
146
172
|
|
|
147
173
|
## TODO
|
|
148
174
|
|
|
149
175
|
* support streaming requests/responses
|
|
150
176
|
* better stubbing API
|
|
151
|
-
* Support timeouts
|
|
152
|
-
* Add curb, em-http, fast_http
|
|
153
177
|
|
|
154
|
-
##
|
|
178
|
+
## Supported Ruby versions
|
|
179
|
+
|
|
180
|
+
This library aims to support and is [tested against][travis] the following Ruby
|
|
181
|
+
implementations:
|
|
182
|
+
|
|
183
|
+
* MRI 1.8.7
|
|
184
|
+
* MRI 1.9.2
|
|
185
|
+
* MRI 1.9.3
|
|
186
|
+
* MRI 2.0.0
|
|
187
|
+
* MRI 2.1.0
|
|
188
|
+
* [JRuby][]
|
|
189
|
+
* [Rubinius][]
|
|
190
|
+
|
|
191
|
+
If something doesn't work on one of these Ruby versions, it's a bug.
|
|
192
|
+
|
|
193
|
+
This library may inadvertently work (or seem to work) on other Ruby
|
|
194
|
+
implementations, however support will only be provided for the versions listed
|
|
195
|
+
above.
|
|
155
196
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
* Send me a pull request. Bonus points for topic branches.
|
|
197
|
+
If you would like this library to support another Ruby version, you may
|
|
198
|
+
volunteer to be a maintainer. Being a maintainer entails making sure all tests
|
|
199
|
+
run and pass on that implementation. When something breaks on your
|
|
200
|
+
implementation, you will be responsible for providing patches in a timely
|
|
201
|
+
fashion. If critical issues for a particular implementation exist at the time
|
|
202
|
+
of a major release, support for that Ruby version may be dropped.
|
|
163
203
|
|
|
164
204
|
## Copyright
|
|
165
205
|
|
|
166
|
-
Copyright (c) 2009-
|
|
206
|
+
Copyright (c) 2009-2013 [Rick Olson](mailto:technoweenie@gmail.com), Zack Hobson.
|
|
207
|
+
See [LICENSE][] for details.
|
|
208
|
+
|
|
209
|
+
[travis]: http://travis-ci.org/lostisland/faraday
|
|
210
|
+
[excon]: https://github.com/geemus/excon#readme
|
|
211
|
+
[typhoeus]: https://github.com/typhoeus/typhoeus#readme
|
|
212
|
+
[patron]: http://toland.github.com/patron/
|
|
213
|
+
[eventmachine]: https://github.com/igrigorik/em-http-request#readme
|
|
214
|
+
[jruby]: http://jruby.org/
|
|
215
|
+
[rubinius]: http://rubini.us/
|
|
216
|
+
[license]: LICENSE.md
|
data/Rakefile
CHANGED
|
@@ -1,12 +1,13 @@
|
|
|
1
|
-
require 'rubygems'
|
|
2
|
-
require 'rake'
|
|
3
1
|
require 'date'
|
|
2
|
+
require 'fileutils'
|
|
3
|
+
require 'openssl'
|
|
4
|
+
require 'rake/testtask'
|
|
5
|
+
require 'bundler'
|
|
6
|
+
Bundler::GemHelper.install_tasks
|
|
7
|
+
|
|
8
|
+
task :default => :test
|
|
4
9
|
|
|
5
|
-
|
|
6
|
-
#
|
|
7
|
-
# Helper functions
|
|
8
|
-
#
|
|
9
|
-
#############################################################################
|
|
10
|
+
## helper functions
|
|
10
11
|
|
|
11
12
|
def name
|
|
12
13
|
@name ||= Dir['*.gemspec'].first.split('.').first
|
|
@@ -17,14 +18,6 @@ def version
|
|
|
17
18
|
line.match(/.*VERSION\s*=\s*['"](.*)['"]/)[1]
|
|
18
19
|
end
|
|
19
20
|
|
|
20
|
-
def date
|
|
21
|
-
Date.today.to_s
|
|
22
|
-
end
|
|
23
|
-
|
|
24
|
-
def rubyforge_project
|
|
25
|
-
name
|
|
26
|
-
end
|
|
27
|
-
|
|
28
21
|
def gemspec_file
|
|
29
22
|
"#{name}.gemspec"
|
|
30
23
|
end
|
|
@@ -37,98 +30,42 @@ def replace_header(head, header_name)
|
|
|
37
30
|
head.sub!(/(\.#{header_name}\s*= ').*'/) { "#{$1}#{send(header_name)}'"}
|
|
38
31
|
end
|
|
39
32
|
|
|
40
|
-
|
|
41
|
-
#
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
desc "Open an irb session preloaded with this library"
|
|
56
|
-
task :console do
|
|
57
|
-
sh "irb -rubygems -r ./lib/#{name}.rb"
|
|
33
|
+
# Adapted from WEBrick::Utils. Skips cert extensions so it
|
|
34
|
+
# can be used as a CA bundle
|
|
35
|
+
def create_self_signed_cert(bits, cn, comment)
|
|
36
|
+
rsa = OpenSSL::PKey::RSA.new(bits)
|
|
37
|
+
cert = OpenSSL::X509::Certificate.new
|
|
38
|
+
cert.version = 2
|
|
39
|
+
cert.serial = 1
|
|
40
|
+
name = OpenSSL::X509::Name.new(cn)
|
|
41
|
+
cert.subject = name
|
|
42
|
+
cert.issuer = name
|
|
43
|
+
cert.not_before = Time.now
|
|
44
|
+
cert.not_after = Time.now + (365*24*60*60)
|
|
45
|
+
cert.public_key = rsa.public_key
|
|
46
|
+
cert.sign(rsa, OpenSSL::Digest::SHA1.new)
|
|
47
|
+
return [cert, rsa]
|
|
58
48
|
end
|
|
59
49
|
|
|
60
|
-
|
|
61
|
-
#
|
|
62
|
-
# Custom tasks (add your own tasks here)
|
|
63
|
-
#
|
|
64
|
-
#############################################################################
|
|
65
|
-
|
|
50
|
+
## standard tasks
|
|
66
51
|
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
# Packaging tasks
|
|
71
|
-
#
|
|
72
|
-
#############################################################################
|
|
73
|
-
|
|
74
|
-
desc "Create tag v#{version} and build and push #{gem_file} to Rubygems"
|
|
75
|
-
task :release => :build do
|
|
76
|
-
unless `git branch` =~ /^\* master$/
|
|
77
|
-
puts "You must be on the master branch to release!"
|
|
78
|
-
exit!
|
|
79
|
-
end
|
|
80
|
-
sh "git commit --allow-empty -a -m 'Release #{version}'"
|
|
81
|
-
sh "git tag v#{version}"
|
|
82
|
-
sh "git push origin master"
|
|
83
|
-
sh "git push origin v#{version}"
|
|
84
|
-
sh "gem push pkg/#{gem_file}"
|
|
52
|
+
desc "Run all tests"
|
|
53
|
+
task :test do
|
|
54
|
+
exec 'script/test'
|
|
85
55
|
end
|
|
86
56
|
|
|
87
|
-
desc "
|
|
88
|
-
task :
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
57
|
+
desc "Generate certificates for SSL tests"
|
|
58
|
+
task :'test:generate_certs' do
|
|
59
|
+
cert, key = create_self_signed_cert(1024, [['CN', 'localhost']], 'Faraday Test CA')
|
|
60
|
+
FileUtils.mkdir_p 'tmp'
|
|
61
|
+
File.open('tmp/faraday-cert.key', 'w') {|f| f.puts(key) }
|
|
62
|
+
File.open('tmp/faraday-cert.crt', 'w') {|f| f.puts(cert.to_s) }
|
|
92
63
|
end
|
|
93
64
|
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
# read spec file and split out manifest section
|
|
97
|
-
spec = File.read(gemspec_file)
|
|
98
|
-
head, manifest, tail = spec.split(" # = MANIFEST =\n")
|
|
99
|
-
|
|
100
|
-
# replace name version and date
|
|
101
|
-
replace_header(head, :name)
|
|
102
|
-
replace_header(head, :version)
|
|
103
|
-
replace_header(head, :date)
|
|
104
|
-
#comment this out if your rubyforge_project has a different name
|
|
105
|
-
replace_header(head, :rubyforge_project)
|
|
65
|
+
file 'tmp/faraday-cert.key' => :'test:generate_certs'
|
|
66
|
+
file 'tmp/faraday-cert.crt' => :'test:generate_certs'
|
|
106
67
|
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
sort.
|
|
111
|
-
reject { |file| file =~ /^\./ }.
|
|
112
|
-
reject { |file| file =~ /^(rdoc|pkg)/ }.
|
|
113
|
-
map { |file| " #{file}" }.
|
|
114
|
-
join("\n")
|
|
115
|
-
|
|
116
|
-
# piece file back together and write
|
|
117
|
-
manifest = " s.files = %w[\n#{files}\n ]\n"
|
|
118
|
-
spec = [head, manifest, tail].join(" # = MANIFEST =\n")
|
|
119
|
-
File.open(gemspec_file, 'w') { |io| io.write(spec) }
|
|
120
|
-
puts "Updated #{gemspec_file}"
|
|
121
|
-
end
|
|
122
|
-
|
|
123
|
-
desc "Validate #{gemspec_file}"
|
|
124
|
-
task :validate do
|
|
125
|
-
libfiles = Dir['lib/*'] - ["lib/#{name}.rb", "lib/#{name}"]
|
|
126
|
-
unless libfiles.empty?
|
|
127
|
-
puts "Directory `lib` should only contain a `#{name}.rb` file and `#{name}` dir."
|
|
128
|
-
exit!
|
|
129
|
-
end
|
|
130
|
-
unless Dir['VERSION*'].empty?
|
|
131
|
-
puts "A `VERSION` file at root level violates Gem best practices."
|
|
132
|
-
exit!
|
|
133
|
-
end
|
|
68
|
+
desc "Open an irb session preloaded with this library"
|
|
69
|
+
task :console do
|
|
70
|
+
sh "irb -rubygems -r ./lib/#{name}.rb"
|
|
134
71
|
end
|