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.
Files changed (83) hide show
  1. checksums.yaml +7 -0
  2. data/.document +6 -0
  3. data/CHANGELOG.md +15 -0
  4. data/CONTRIBUTING.md +36 -0
  5. data/Gemfile +25 -15
  6. data/{LICENSE → LICENSE.md} +1 -1
  7. data/README.md +187 -137
  8. data/Rakefile +38 -101
  9. data/faraday.gemspec +26 -81
  10. data/lib/faraday/adapter/em_http.rb +237 -0
  11. data/lib/faraday/adapter/em_http_ssl_patch.rb +56 -0
  12. data/lib/faraday/adapter/em_synchrony/parallel_manager.rb +66 -0
  13. data/lib/faraday/adapter/em_synchrony.rb +65 -38
  14. data/lib/faraday/adapter/excon.rb +60 -9
  15. data/lib/faraday/adapter/httpclient.rb +106 -0
  16. data/lib/faraday/adapter/net_http.rb +89 -38
  17. data/lib/faraday/adapter/net_http_persistent.rb +47 -0
  18. data/lib/faraday/adapter/patron.rb +46 -9
  19. data/lib/faraday/adapter/rack.rb +58 -0
  20. data/lib/faraday/adapter/test.rb +68 -28
  21. data/lib/faraday/adapter/typhoeus.rb +94 -16
  22. data/lib/faraday/adapter.rb +33 -25
  23. data/lib/faraday/autoload.rb +85 -0
  24. data/lib/faraday/connection.rb +342 -134
  25. data/lib/faraday/error.rb +44 -29
  26. data/lib/faraday/middleware.rb +18 -10
  27. data/lib/faraday/options.rb +350 -0
  28. data/lib/faraday/parameters.rb +193 -0
  29. data/lib/faraday/rack_builder.rb +212 -0
  30. data/lib/faraday/request/authorization.rb +42 -0
  31. data/lib/faraday/request/basic_authentication.rb +13 -0
  32. data/lib/faraday/request/instrumentation.rb +36 -0
  33. data/lib/faraday/request/multipart.rb +15 -15
  34. data/lib/faraday/request/retry.rb +118 -0
  35. data/lib/faraday/request/token_authentication.rb +15 -0
  36. data/lib/faraday/request/url_encoded.rb +8 -9
  37. data/lib/faraday/request.rb +46 -45
  38. data/lib/faraday/response/logger.rb +4 -4
  39. data/lib/faraday/response/raise_error.rb +8 -3
  40. data/lib/faraday/response.rb +20 -25
  41. data/lib/faraday/upload_io.rb +51 -7
  42. data/lib/faraday/utils.rb +240 -44
  43. data/lib/faraday.rb +218 -38
  44. data/script/console +7 -0
  45. data/script/generate_certs +42 -0
  46. data/script/package +7 -0
  47. data/script/proxy-server +42 -0
  48. data/script/release +17 -0
  49. data/script/server +36 -0
  50. data/script/test +172 -0
  51. data/test/adapters/default_test.rb +14 -0
  52. data/test/adapters/em_http_test.rb +20 -0
  53. data/test/adapters/em_synchrony_test.rb +20 -0
  54. data/test/adapters/excon_test.rb +20 -0
  55. data/test/adapters/httpclient_test.rb +21 -0
  56. data/test/adapters/integration.rb +254 -0
  57. data/test/adapters/logger_test.rb +3 -3
  58. data/test/adapters/net_http_persistent_test.rb +20 -0
  59. data/test/adapters/net_http_test.rb +6 -25
  60. data/test/adapters/patron_test.rb +20 -0
  61. data/test/adapters/rack_test.rb +31 -0
  62. data/test/adapters/test_middleware_test.rb +74 -3
  63. data/test/adapters/typhoeus_test.rb +28 -0
  64. data/test/authentication_middleware_test.rb +65 -0
  65. data/test/composite_read_io_test.rb +111 -0
  66. data/test/connection_test.rb +381 -104
  67. data/test/env_test.rb +116 -40
  68. data/test/helper.rb +61 -25
  69. data/test/live_server.rb +55 -29
  70. data/test/middleware/instrumentation_test.rb +88 -0
  71. data/test/middleware/retry_test.rb +109 -0
  72. data/test/middleware_stack_test.rb +87 -5
  73. data/test/multibyte.txt +1 -0
  74. data/test/options_test.rb +252 -0
  75. data/test/request_middleware_test.rb +78 -21
  76. data/test/response_middleware_test.rb +32 -7
  77. data/test/strawberry.rb +2 -0
  78. data/test/utils_test.rb +58 -0
  79. metadata +116 -117
  80. data/lib/faraday/adapter/action_dispatch.rb +0 -30
  81. data/lib/faraday/builder.rb +0 -137
  82. data/lib/faraday/request/json.rb +0 -31
  83. 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
@@ -0,0 +1,6 @@
1
+ CONTRIBUTING.md
2
+ LICENSE.md
3
+ README.md
4
+ bin/*
5
+ lib/**/*.rb
6
+ test/**/*.rb
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 "http://rubygems.org"
1
+ source 'https://rubygems.org'
2
2
 
3
- # Bundle gems for the local environment. Make sure to
4
- # put test-only gems in this group so their generators
5
- # and rake tasks are available in development mode:
6
- group :development, :test do
7
- gem 'patron', '~> 0.4', :platforms => :ruby
8
- gem 'sinatra', '~> 1.1'
9
- gem 'typhoeus', '~> 0.2', :platforms => :ruby
10
- gem 'excon', '~> 0.5.8'
11
- gem 'em-http-request', '~> 0.3', :require => 'em-http', :platforms => :ruby
12
- gem 'em-synchrony', '~> 0.2', :require => ['em-synchrony', 'em-synchrony/em-http'], :platforms => :ruby_19
13
- gem 'webmock'
14
- # ActiveSupport::JSON will be used in ruby 1.8 and Yajl in 1.9; this is to test against both adapters
15
- gem 'activesupport', '~> 2.3.8', :require => nil, :platforms => [:ruby_18, :jruby]
16
- gem 'yajl-ruby', :require => 'yajl', :platforms => :ruby_19
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
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009-* rick olson, zack hobson
1
+ Copyright (c) 2009-2013 Rick Olson, Zack Hobson
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.md CHANGED
@@ -1,166 +1,216 @@
1
- # faraday
1
+ # Faraday
2
2
 
3
- Modular HTTP client library using middleware heavily inspired by Rack.
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
- This mess is gonna get raw, like sushi. So, haters to the left.
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
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
10
- builder.use Faraday::Request::UrlEncoded # convert request params as "www-form-urlencoded"
11
- builder.use Faraday::Request::JSON # encode request params as json
12
- builder.use Faraday::Response::Logger # log the request to STDOUT
13
- builder.use Faraday::Adapter::NetHttp # make http requests with Net::HTTP
14
-
15
- # or, use shortcuts:
16
- builder.request :url_encoded
17
- builder.request :json
18
- builder.response :logger
19
- builder.adapter :net_http
20
- end
21
-
22
- ## GET ##
23
-
24
- response = conn.get '/nigiri/sake.json' # GET http://sushi.com/nigiri/sake.json
25
- response.body
26
-
27
- conn.get '/nigiri', 'X-Awesome' => true # custom request header
28
-
29
- conn.get do |req| # GET http://sushi.com/search?page=2&limit=100
30
- req.url '/search', :page => 2
31
- req.params['limit'] = 100
32
- end
33
-
34
- ## POST ##
35
-
36
- conn.post '/nigiri', { :name => 'Maguro' } # POST "name=maguro" to http://sushi.com/nigiri
37
-
38
- # post payload as JSON instead of "www-form-urlencoded" encoding:
39
- conn.post '/nigiri', payload, 'Content-Type' => 'application/json'
40
-
41
- # a more verbose way:
42
- conn.post do |req|
43
- req.url '/nigiri'
44
- req.headers['Content-Type'] = 'application/json'
45
- req.body = { :name => 'Unagi' }
46
- end
47
-
48
- If you're ready to roll with just the bare minimum:
49
-
50
- # default stack (net/http), no extra middleware:
51
- response = Faraday.get 'http://sushi.com/nigiri/sake.json'
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 first middleware on the list wraps all others, while the last middleware is the innermost one, so that's usually the adapter.
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
- conn = Faraday.new(:url => 'http://sushi.com') do |builder|
58
- # POST/PUT params encoders:
59
- builder.request :multipart
60
- builder.request :url_encoded
61
- builder.request :json
62
-
63
- builder.adapter :net_http
64
- end
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 everything untouched;
69
- 2. `Request::UrlEncoded` encodes as "application/x-www-form-urlencoded" if not already encoded or of another type
70
- 2. `Request::JSON` encodes as "application/json" if not already encoded or of another type
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
- Because "UrlEncoded" is higher on the stack than JSON encoder, it will get to process the request first. Swapping them means giving the other priority. Specifying the "Content-Type" for the request is explicitly stating which middleware should process it.
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
- payload = { :name => 'Maguro' }
77
-
78
- # post payload as JSON instead of urlencoded:
79
- conn.post '/nigiri', payload, 'Content-Type' => 'application/json'
80
-
81
- # uploading a file:
82
- payload = { :profile_pic => Faraday::UploadIO.new('avatar.jpg', 'image/jpeg') }
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 respond to `call()`. They wrap the request/response cycle.
90
-
91
- def call(env)
92
- # do something with the request
93
-
94
- @app.call(env).on_complete do
95
- # do something with the response
96
- end
97
- end
98
-
99
- It's important to do all processing of the response only in the `on_complete` block. This enables middleware to work in parallel mode where requests are asynchronous.
100
-
101
- The `env` is a hash with symbol keys that contains info about the request and, later, response. Some keys are:
102
-
103
- # request phase
104
- :method - :get, :post, ...
105
- :url - URI for the current request; also contains GET parameters
106
- :body - POST parameters for :post/:put requests
107
- :request_headers
108
-
109
- # response phase
110
- :status - HTTP response status code, such as 200
111
- :body - the response body
112
- :response_headers
113
-
114
- ## Testing
115
-
116
- # It's possible to define stubbed request outside a test adapter block.
117
- stubs = Faraday::Adapter::Test::Stubs.new do |stub|
118
- stub.get('/tamago') { [200, {}, 'egg'] }
119
- end
120
-
121
- # You can pass stubbed request to the test adapter or define them in a block
122
- # or a combination of the two.
123
- test = Faraday.new do |builder|
124
- builder.adapter :test, stubs do |stub|
125
- stub.get('/ebi') {[ 200, {}, 'shrimp' ]}
126
- end
127
- end
128
-
129
- # It's also possible to stub additional requests after the connection has
130
- # been initialized. This is useful for testing.
131
- stubs.get('/uni') {[ 200, {}, 'urchin' ]}
132
-
133
- resp = test.get '/tamago'
134
- resp.body # => 'egg'
135
- resp = test.get '/ebi'
136
- resp.body # => 'shrimp'
137
- resp = test.get '/uni'
138
- resp.body # => 'urchin'
139
- resp = test.get '/else' #=> raises "no such stub" error
140
-
141
- # If you like, you can treat your stubs as mocks by verifying that all of
142
- # the stubbed calls were made. NOTE that this feature is still fairly
143
- # experimental: It will not verify the order or count of any stub, only that
144
- # it was called once during the course of the test.
145
- stubs.verify_stubbed_calls
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
- ## Note on Patches/Pull Requests
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
- * Fork the project.
157
- * Make your feature addition or bug fix.
158
- * Add tests for it. This is important so I don't break it in a
159
- future version unintentionally.
160
- * Commit, do not mess with rakefile, version, or history.
161
- (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)
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-2011 rick, hobson. See LICENSE for details.
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
- # Standard tasks
43
- #
44
- #############################################################################
45
-
46
- task :default => :test
47
-
48
- require 'rake/testtask'
49
- Rake::TestTask.new(:test) do |test|
50
- test.libs << 'lib' << 'test'
51
- test.pattern = 'test/**/*_test.rb'
52
- test.verbose = true
53
- end
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 "Build #{gem_file} into the pkg directory"
88
- task :build => :gemspec do
89
- sh "mkdir -p pkg"
90
- sh "gem build #{gemspec_file}"
91
- sh "mv #{gem_file} pkg"
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
- desc "Generate #{gemspec_file}"
95
- task :gemspec => :validate do
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
- # determine file list from git ls-files
108
- files = `git ls-files`.
109
- split("\n").
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