httparty 0.10.0 → 0.14.0
Sign up to get free protection for your applications and to get access to all the features.
Potentially problematic release.
This version of httparty might be problematic. Click here for more details.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +124 -0
- data/.simplecov +1 -0
- data/.travis.yml +5 -4
- data/CONTRIBUTING.md +23 -0
- data/Gemfile +9 -5
- data/Guardfile +3 -3
- data/History +109 -8
- data/README.md +21 -21
- data/Rakefile +5 -10
- data/bin/httparty +21 -14
- data/docs/README.md +100 -0
- data/examples/README.md +67 -0
- data/examples/aaws.rb +9 -9
- data/examples/basic.rb +6 -10
- data/examples/crack.rb +3 -3
- data/examples/custom_parsers.rb +1 -4
- data/examples/delicious.rb +12 -12
- data/examples/google.rb +2 -2
- data/examples/headers_and_user_agents.rb +2 -2
- data/examples/logging.rb +36 -0
- data/examples/nokogiri_html_parser.rb +0 -3
- data/examples/rescue_json.rb +17 -0
- data/examples/rubyurl.rb +3 -3
- data/examples/stackexchange.rb +24 -0
- data/examples/tripit_sign_in.rb +20 -9
- data/examples/twitter.rb +11 -11
- data/examples/whoismyrep.rb +2 -2
- data/features/command_line.feature +90 -2
- data/features/digest_authentication.feature +10 -0
- data/features/handles_compressed_responses.feature +8 -0
- data/features/handles_multiple_formats.feature +23 -0
- data/features/steps/env.rb +16 -11
- data/features/steps/httparty_response_steps.rb +40 -10
- data/features/steps/httparty_steps.rb +19 -3
- data/features/steps/mongrel_helper.rb +35 -2
- data/features/steps/remote_service_steps.rb +31 -8
- data/features/supports_read_timeout_option.feature +13 -0
- data/httparty.gemspec +9 -6
- data/lib/httparty/connection_adapter.rb +76 -11
- data/lib/httparty/cookie_hash.rb +3 -4
- data/lib/httparty/exceptions.rb +10 -4
- data/lib/httparty/hash_conversions.rb +19 -17
- data/lib/httparty/logger/apache_formatter.rb +22 -0
- data/lib/httparty/logger/curl_formatter.rb +91 -0
- data/lib/httparty/logger/logger.rb +26 -0
- data/lib/httparty/module_inheritable_attributes.rb +1 -1
- data/lib/httparty/net_digest_auth.rb +69 -18
- data/lib/httparty/parser.rb +15 -11
- data/lib/httparty/request.rb +186 -47
- data/lib/httparty/response/headers.rb +2 -2
- data/lib/httparty/response.rb +44 -9
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +187 -65
- data/script/release +42 -0
- data/spec/fixtures/twitter.csv +2 -0
- data/spec/httparty/connection_adapter_spec.rb +334 -62
- data/spec/httparty/cookie_hash_spec.rb +53 -23
- data/spec/httparty/exception_spec.rb +45 -0
- data/spec/httparty/hash_conversions_spec.rb +49 -0
- data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
- data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
- data/spec/httparty/logger/logger_spec.rb +38 -0
- data/spec/httparty/net_digest_auth_spec.rb +148 -23
- data/spec/httparty/parser_spec.rb +48 -41
- data/spec/httparty/request_spec.rb +845 -151
- data/spec/httparty/response_spec.rb +147 -70
- data/spec/httparty/ssl_spec.rb +33 -21
- data/spec/httparty_spec.rb +337 -186
- data/spec/spec_helper.rb +38 -9
- data/spec/support/ssl_test_helper.rb +10 -10
- data/spec/support/ssl_test_server.rb +21 -21
- data/spec/support/stub_response.rb +20 -14
- data/website/index.html +3 -3
- metadata +46 -37
- data/lib/httparty/core_extensions.rb +0 -32
- data/spec/spec.opts +0 -2
data/lib/httparty.rb
CHANGED
@@ -4,32 +4,22 @@ require 'net/https'
|
|
4
4
|
require 'uri'
|
5
5
|
require 'zlib'
|
6
6
|
require 'multi_xml'
|
7
|
-
require '
|
7
|
+
require 'json'
|
8
|
+
require 'csv'
|
9
|
+
require 'erb'
|
8
10
|
|
9
11
|
require 'httparty/module_inheritable_attributes'
|
10
12
|
require 'httparty/cookie_hash'
|
11
13
|
require 'httparty/net_digest_auth'
|
12
14
|
require 'httparty/version'
|
13
15
|
require 'httparty/connection_adapter'
|
16
|
+
require 'httparty/logger/logger'
|
14
17
|
|
15
18
|
# @see HTTParty::ClassMethods
|
16
19
|
module HTTParty
|
17
|
-
module AllowedFormatsDeprecation
|
18
|
-
def const_missing(const)
|
19
|
-
if const.to_s =~ /AllowedFormats$/
|
20
|
-
Kernel.warn("Deprecated: Use HTTParty::Parser::SupportedFormats")
|
21
|
-
HTTParty::Parser::SupportedFormats
|
22
|
-
else
|
23
|
-
super
|
24
|
-
end
|
25
|
-
end
|
26
|
-
end
|
27
|
-
|
28
|
-
extend AllowedFormatsDeprecation
|
29
|
-
|
30
20
|
def self.included(base)
|
31
21
|
base.extend ClassMethods
|
32
|
-
base.send :include,
|
22
|
+
base.send :include, ModuleInheritableAttributes
|
33
23
|
base.send(:mattr_inheritable, :default_options)
|
34
24
|
base.send(:mattr_inheritable, :default_cookies)
|
35
25
|
base.instance_variable_set("@default_options", {})
|
@@ -39,14 +29,18 @@ module HTTParty
|
|
39
29
|
# == Common Request Options
|
40
30
|
# Request methods (get, post, patch, put, delete, head, options) all take a common set of options. These are:
|
41
31
|
#
|
42
|
-
# [:+body+:] Body of the request. If passed
|
32
|
+
# [:+body+:] Body of the request. If passed an object that responds to #to_hash, will try to normalize it first, by default passing it to ActiveSupport::to_params. Any other kind of object will get used as-is.
|
43
33
|
# [:+http_proxyaddr+:] Address of proxy server to use.
|
44
34
|
# [:+http_proxyport+:] Port of proxy server to use.
|
45
35
|
# [:+http_proxyuser+:] User for proxy server authentication.
|
46
36
|
# [:+http_proxypass+:] Password for proxy server authentication.
|
47
37
|
# [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
|
48
|
-
# [:+query+:] Query string, or
|
38
|
+
# [:+query+:] Query string, or an object that responds to #to_hash representing it. Normalized according to the same rules as :+body+. If you specify this on a POST, you must use an object which responds to #to_hash. See also HTTParty::ClassMethods.default_params.
|
49
39
|
# [:+timeout+:] Timeout for opening connection and reading data.
|
40
|
+
# [:+local_host:] Local address to bind to before connecting.
|
41
|
+
# [:+local_port:] Local port to bind to before connecting.
|
42
|
+
# [:+body_steam:] Allow streaming to a REST server to specify a body_stream.
|
43
|
+
# [:+stream_body:] Allow for streaming large files without loading them into memory.
|
50
44
|
#
|
51
45
|
# There are also another set of options with names corresponding to various class methods. The methods in question are those that let you set a class-wide default, and the options override the defaults on a request-by-request basis. Those options are:
|
52
46
|
# * :+base_uri+: see HTTParty::ClassMethods.base_uri.
|
@@ -54,10 +48,11 @@ module HTTParty
|
|
54
48
|
# * :+debug_output+: see HTTParty::ClassMethods.debug_output.
|
55
49
|
# * :+digest_auth+: see HTTParty::ClassMethods.digest_auth. Only one of :+basic_auth+ and :+digest_auth+ can be used at a time; if you try using both, you'll get an ArgumentError.
|
56
50
|
# * :+format+: see HTTParty::ClassMethods.format.
|
57
|
-
# * :+headers+: see HTTParty::ClassMethods.headers. Must be a
|
51
|
+
# * :+headers+: see HTTParty::ClassMethods.headers. Must be a an object which responds to #to_hash.
|
58
52
|
# * :+maintain_method_across_redirects+: see HTTParty::ClassMethods.maintain_method_across_redirects.
|
59
53
|
# * :+no_follow+: see HTTParty::ClassMethods.no_follow.
|
60
54
|
# * :+parser+: see HTTParty::ClassMethods.parser.
|
55
|
+
# * :+uri_adapter+: see HTTParty::ClassMethods.uri_adapter
|
61
56
|
# * :+connection_adapter+: see HTTParty::ClassMethods.connection_adapter.
|
62
57
|
# * :+pem+: see HTTParty::ClassMethods.pem.
|
63
58
|
# * :+query_string_normalizer+: see HTTParty::ClassMethods.query_string_normalizer
|
@@ -65,8 +60,27 @@ module HTTParty
|
|
65
60
|
# * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
|
66
61
|
|
67
62
|
module ClassMethods
|
63
|
+
# Turns on logging
|
64
|
+
#
|
65
|
+
# class Foo
|
66
|
+
# include HTTParty
|
67
|
+
# logger Logger.new('http_logger'), :info, :apache
|
68
|
+
# end
|
69
|
+
def logger(logger, level = :info, format = :apache)
|
70
|
+
default_options[:logger] = logger
|
71
|
+
default_options[:log_level] = level
|
72
|
+
default_options[:log_format] = format
|
73
|
+
end
|
68
74
|
|
69
|
-
|
75
|
+
# Raises HTTParty::ResponseError if response's code matches this statuses
|
76
|
+
#
|
77
|
+
# class Foo
|
78
|
+
# include HTTParty
|
79
|
+
# raise_on [404, 500]
|
80
|
+
# end
|
81
|
+
def raise_on(codes = [])
|
82
|
+
default_options[:raise_on] = *codes
|
83
|
+
end
|
70
84
|
|
71
85
|
# Allows setting http proxy information to be used
|
72
86
|
#
|
@@ -74,7 +88,7 @@ module HTTParty
|
|
74
88
|
# include HTTParty
|
75
89
|
# http_proxy 'http://foo.com', 80, 'user', 'pass'
|
76
90
|
# end
|
77
|
-
def http_proxy(addr=nil, port=nil, user=nil, pass=nil)
|
91
|
+
def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
|
78
92
|
default_options[:http_proxyaddr] = addr
|
79
93
|
default_options[:http_proxyport] = port
|
80
94
|
default_options[:http_proxyuser] = user
|
@@ -88,7 +102,7 @@ module HTTParty
|
|
88
102
|
# include HTTParty
|
89
103
|
# base_uri 'twitter.com'
|
90
104
|
# end
|
91
|
-
def base_uri(uri=nil)
|
105
|
+
def base_uri(uri = nil)
|
92
106
|
return default_options[:base_uri] unless uri
|
93
107
|
default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
|
94
108
|
end
|
@@ -100,7 +114,7 @@ module HTTParty
|
|
100
114
|
# basic_auth 'username', 'password'
|
101
115
|
# end
|
102
116
|
def basic_auth(u, p)
|
103
|
-
default_options[:basic_auth] = {:
|
117
|
+
default_options[:basic_auth] = {username: u, password: p}
|
104
118
|
end
|
105
119
|
|
106
120
|
# Allows setting digest authentication username and password.
|
@@ -110,14 +124,14 @@ module HTTParty
|
|
110
124
|
# digest_auth 'username', 'password'
|
111
125
|
# end
|
112
126
|
def digest_auth(u, p)
|
113
|
-
default_options[:digest_auth] = {:
|
127
|
+
default_options[:digest_auth] = {username: u, password: p}
|
114
128
|
end
|
115
129
|
|
116
130
|
# Do not send rails style query strings.
|
117
131
|
# Specically, don't use bracket notation when sending an array
|
118
132
|
#
|
119
133
|
# For a query:
|
120
|
-
# get '/', :
|
134
|
+
# get '/', query: {selected_ids: [1,2,3]}
|
121
135
|
#
|
122
136
|
# The default query string looks like this:
|
123
137
|
# /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
@@ -140,10 +154,10 @@ module HTTParty
|
|
140
154
|
#
|
141
155
|
# class Foo
|
142
156
|
# include HTTParty
|
143
|
-
# default_params :
|
157
|
+
# default_params api_key: 'secret', another: 'foo'
|
144
158
|
# end
|
145
|
-
def default_params(h={})
|
146
|
-
raise ArgumentError, 'Default params must be
|
159
|
+
def default_params(h = {})
|
160
|
+
raise ArgumentError, 'Default params must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
147
161
|
default_options[:default_params] ||= {}
|
148
162
|
default_options[:default_params].merge!(h)
|
149
163
|
end
|
@@ -160,6 +174,28 @@ module HTTParty
|
|
160
174
|
default_options[:timeout] = t
|
161
175
|
end
|
162
176
|
|
177
|
+
# Allows setting a default open_timeout for all HTTP calls in seconds
|
178
|
+
#
|
179
|
+
# class Foo
|
180
|
+
# include HTTParty
|
181
|
+
# open_timeout 10
|
182
|
+
# end
|
183
|
+
def open_timeout(t)
|
184
|
+
raise ArgumentError, 'open_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float))
|
185
|
+
default_options[:open_timeout] = t
|
186
|
+
end
|
187
|
+
|
188
|
+
# Allows setting a default read_timeout for all HTTP calls in seconds
|
189
|
+
#
|
190
|
+
# class Foo
|
191
|
+
# include HTTParty
|
192
|
+
# read_timeout 10
|
193
|
+
# end
|
194
|
+
def read_timeout(t)
|
195
|
+
raise ArgumentError, 'read_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float))
|
196
|
+
default_options[:read_timeout] = t
|
197
|
+
end
|
198
|
+
|
163
199
|
# Set an output stream for debugging, defaults to $stderr.
|
164
200
|
# The output stream is passed on to Net::HTTP#set_debug_output.
|
165
201
|
#
|
@@ -177,14 +213,14 @@ module HTTParty
|
|
177
213
|
# include HTTParty
|
178
214
|
# headers 'Accept' => 'text/html'
|
179
215
|
# end
|
180
|
-
def headers(h={})
|
181
|
-
raise ArgumentError, 'Headers must be
|
216
|
+
def headers(h = {})
|
217
|
+
raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
182
218
|
default_options[:headers] ||= {}
|
183
|
-
default_options[:headers].merge!(h)
|
219
|
+
default_options[:headers].merge!(h.to_hash)
|
184
220
|
end
|
185
221
|
|
186
|
-
def cookies(h={})
|
187
|
-
raise ArgumentError, 'Cookies must be
|
222
|
+
def cookies(h = {})
|
223
|
+
raise ArgumentError, 'Cookies must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
|
188
224
|
default_cookies.add_cookies(h)
|
189
225
|
end
|
190
226
|
|
@@ -242,7 +278,9 @@ module HTTParty
|
|
242
278
|
end
|
243
279
|
|
244
280
|
# Declare that you wish to maintain the chosen HTTP method across redirects.
|
245
|
-
# The default behavior is to follow redirects via the GET method
|
281
|
+
# The default behavior is to follow redirects via the GET method, except
|
282
|
+
# if you are making a HEAD request, in which case the default is to
|
283
|
+
# follow all redirects with HEAD requests.
|
246
284
|
# If you wish to maintain the original method, you can set this option to true.
|
247
285
|
#
|
248
286
|
# @example
|
@@ -256,22 +294,51 @@ module HTTParty
|
|
256
294
|
default_options[:maintain_method_across_redirects] = value
|
257
295
|
end
|
258
296
|
|
297
|
+
# Declare that you wish to resend the full HTTP request across redirects,
|
298
|
+
# even on redirects that should logically become GET requests.
|
299
|
+
# A 303 redirect in HTTP signifies that the redirected url should normally
|
300
|
+
# retrieved using a GET request, for instance, it is the output of a previous
|
301
|
+
# POST. maintain_method_across_redirects respects this behavior, but you
|
302
|
+
# can force HTTParty to resend_on_redirect even on 303 responses.
|
303
|
+
#
|
304
|
+
# @example
|
305
|
+
# class Foo
|
306
|
+
# include HTTParty
|
307
|
+
# base_uri 'http://google.com'
|
308
|
+
# resend_on_redirect
|
309
|
+
# end
|
310
|
+
|
311
|
+
def resend_on_redirect(value = true)
|
312
|
+
default_options[:resend_on_redirect] = value
|
313
|
+
end
|
314
|
+
|
259
315
|
# Allows setting a PEM file to be used
|
260
316
|
#
|
261
317
|
# class Foo
|
262
318
|
# include HTTParty
|
263
319
|
# pem File.read('/home/user/my.pem'), "optional password"
|
264
320
|
# end
|
265
|
-
def pem(pem_contents, password=nil)
|
321
|
+
def pem(pem_contents, password = nil)
|
266
322
|
default_options[:pem] = pem_contents
|
267
323
|
default_options[:pem_password] = password
|
268
324
|
end
|
269
325
|
|
326
|
+
# Allows setting a PKCS12 file to be used
|
327
|
+
#
|
328
|
+
# class Foo
|
329
|
+
# include HTTParty
|
330
|
+
# pkcs12 File.read('/home/user/my.p12'), "password"
|
331
|
+
# end
|
332
|
+
def pkcs12(p12_contents, password)
|
333
|
+
default_options[:p12] = p12_contents
|
334
|
+
default_options[:p12_password] = password
|
335
|
+
end
|
336
|
+
|
270
337
|
# Override the way query strings are normalized.
|
271
338
|
# Helpful for overriding the default rails normalization of Array queries.
|
272
339
|
#
|
273
340
|
# For a query:
|
274
|
-
# get '/', :
|
341
|
+
# get '/', query: {selected_ids: [1,2,3]}
|
275
342
|
#
|
276
343
|
# The default query string normalizer returns:
|
277
344
|
# /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
|
@@ -312,7 +379,7 @@ module HTTParty
|
|
312
379
|
|
313
380
|
# Allows setting of SSL ciphers to use. This only works in Ruby 1.9+.
|
314
381
|
# You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
|
315
|
-
# You also can specify a cipher suite here, listed here at openssl.org:
|
382
|
+
# You also can specify a cipher suite here, listed here at openssl.org:
|
316
383
|
# http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
|
317
384
|
#
|
318
385
|
# class Foo
|
@@ -323,7 +390,13 @@ module HTTParty
|
|
323
390
|
default_options[:ciphers] = cipher_names
|
324
391
|
end
|
325
392
|
|
326
|
-
# Allows setting an OpenSSL certificate authority file
|
393
|
+
# Allows setting an OpenSSL certificate authority file. The file
|
394
|
+
# should contain one or more certificates in PEM format.
|
395
|
+
#
|
396
|
+
# Setting this option enables certificate verification. All
|
397
|
+
# certificates along a chain must be available in ssl_ca_file or
|
398
|
+
# ssl_ca_path for verification to succeed.
|
399
|
+
#
|
327
400
|
#
|
328
401
|
# class Foo
|
329
402
|
# include HTTParty
|
@@ -333,7 +406,11 @@ module HTTParty
|
|
333
406
|
default_options[:ssl_ca_file] = path
|
334
407
|
end
|
335
408
|
|
336
|
-
# Allows setting an OpenSSL certificate authority path (directory)
|
409
|
+
# Allows setting an OpenSSL certificate authority path (directory).
|
410
|
+
#
|
411
|
+
# Setting this option enables certificate verification. All
|
412
|
+
# certificates along a chain must be available in ssl_ca_file or
|
413
|
+
# ssl_ca_path for verification to succeed.
|
337
414
|
#
|
338
415
|
# class Foo
|
339
416
|
# include HTTParty
|
@@ -358,6 +435,17 @@ module HTTParty
|
|
358
435
|
end
|
359
436
|
end
|
360
437
|
|
438
|
+
# Allows setting a custom URI adapter.
|
439
|
+
#
|
440
|
+
# class Foo
|
441
|
+
# include HTTParty
|
442
|
+
# uri_adapter Addressable::URI
|
443
|
+
# end
|
444
|
+
def uri_adapter(uri_adapter)
|
445
|
+
raise ArgumentError, 'The URI adapter should respond to #parse' unless uri_adapter.respond_to?(:parse)
|
446
|
+
default_options[:uri_adapter] = uri_adapter
|
447
|
+
end
|
448
|
+
|
361
449
|
# Allows setting a custom connection_adapter for the http connections
|
362
450
|
#
|
363
451
|
# @example
|
@@ -369,7 +457,7 @@ module HTTParty
|
|
369
457
|
# @example provide optional configuration for your connection_adapter
|
370
458
|
# class Foo
|
371
459
|
# include HTTParty
|
372
|
-
# connection_adapter Proc.new {|uri, options| ... }, {:
|
460
|
+
# connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}
|
373
461
|
# end
|
374
462
|
#
|
375
463
|
# @see HTTParty::ConnectionAdapter
|
@@ -393,8 +481,8 @@ module HTTParty
|
|
393
481
|
#
|
394
482
|
# # Simple get with full url and query parameters
|
395
483
|
# # ie: http://foo.com/resource.json?limit=10
|
396
|
-
# Foo.get('http://foo.com/resource.json', :
|
397
|
-
def get(path, options={}, &block)
|
484
|
+
# Foo.get('http://foo.com/resource.json', query: {limit: 10})
|
485
|
+
def get(path, options = {}, &block)
|
398
486
|
perform_request Net::HTTP::Get, path, options, &block
|
399
487
|
end
|
400
488
|
|
@@ -405,63 +493,90 @@ module HTTParty
|
|
405
493
|
# end
|
406
494
|
#
|
407
495
|
# # Simple post with full url and setting the body
|
408
|
-
# Foo.post('http://foo.com/resources', :
|
496
|
+
# Foo.post('http://foo.com/resources', body: {bar: 'baz'})
|
409
497
|
#
|
410
498
|
# # Simple post with full url using :query option,
|
411
|
-
# # which
|
412
|
-
# Foo.post('http://foo.com/resources', :
|
413
|
-
def post(path, options={}, &block)
|
499
|
+
# # which appends the parameters to the URI.
|
500
|
+
# Foo.post('http://foo.com/resources', query: {bar: 'baz'})
|
501
|
+
def post(path, options = {}, &block)
|
414
502
|
perform_request Net::HTTP::Post, path, options, &block
|
415
503
|
end
|
416
504
|
|
417
505
|
# Perform a PATCH request to a path
|
418
|
-
def patch(path, options={}, &block)
|
506
|
+
def patch(path, options = {}, &block)
|
419
507
|
perform_request Net::HTTP::Patch, path, options, &block
|
420
508
|
end
|
421
509
|
|
422
510
|
# Perform a PUT request to a path
|
423
|
-
def put(path, options={}, &block)
|
511
|
+
def put(path, options = {}, &block)
|
424
512
|
perform_request Net::HTTP::Put, path, options, &block
|
425
513
|
end
|
426
514
|
|
427
515
|
# Perform a DELETE request to a path
|
428
|
-
def delete(path, options={}, &block)
|
516
|
+
def delete(path, options = {}, &block)
|
429
517
|
perform_request Net::HTTP::Delete, path, options, &block
|
430
518
|
end
|
431
519
|
|
520
|
+
# Perform a MOVE request to a path
|
521
|
+
def move(path, options = {}, &block)
|
522
|
+
perform_request Net::HTTP::Move, path, options, &block
|
523
|
+
end
|
524
|
+
|
525
|
+
# Perform a COPY request to a path
|
526
|
+
def copy(path, options = {}, &block)
|
527
|
+
perform_request Net::HTTP::Copy, path, options, &block
|
528
|
+
end
|
529
|
+
|
432
530
|
# Perform a HEAD request to a path
|
433
|
-
def head(path, options={}, &block)
|
531
|
+
def head(path, options = {}, &block)
|
532
|
+
ensure_method_maintained_across_redirects options
|
434
533
|
perform_request Net::HTTP::Head, path, options, &block
|
435
534
|
end
|
436
535
|
|
437
536
|
# Perform an OPTIONS request to a path
|
438
|
-
def options(path, options={}, &block)
|
537
|
+
def options(path, options = {}, &block)
|
439
538
|
perform_request Net::HTTP::Options, path, options, &block
|
440
539
|
end
|
441
540
|
|
442
|
-
|
443
|
-
|
541
|
+
# Perform a MKCOL request to a path
|
542
|
+
def mkcol(path, options = {}, &block)
|
543
|
+
perform_request Net::HTTP::Mkcol, path, options, &block
|
444
544
|
end
|
445
545
|
|
546
|
+
attr_reader :default_options
|
547
|
+
|
446
548
|
private
|
447
549
|
|
448
|
-
|
449
|
-
|
450
|
-
|
451
|
-
Request.new(http_method, path, options).perform(&block)
|
550
|
+
def ensure_method_maintained_across_redirects(options)
|
551
|
+
unless options.key?(:maintain_method_across_redirects)
|
552
|
+
options[:maintain_method_across_redirects] = true
|
452
553
|
end
|
554
|
+
end
|
555
|
+
|
556
|
+
def perform_request(http_method, path, options, &block) #:nodoc:
|
557
|
+
options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
|
558
|
+
process_headers(options)
|
559
|
+
process_cookies(options)
|
560
|
+
Request.new(http_method, path, options).perform(&block)
|
561
|
+
end
|
453
562
|
|
454
|
-
|
455
|
-
|
456
|
-
options[:headers]
|
457
|
-
options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
|
563
|
+
def process_headers(options)
|
564
|
+
if options[:headers] && headers.any?
|
565
|
+
options[:headers] = headers.merge(options[:headers])
|
458
566
|
end
|
567
|
+
end
|
568
|
+
|
569
|
+
def process_cookies(options) #:nodoc:
|
570
|
+
return unless options[:cookies] || default_cookies.any?
|
571
|
+
options[:headers] ||= headers.dup
|
572
|
+
options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
|
573
|
+
end
|
459
574
|
|
460
|
-
|
461
|
-
|
462
|
-
|
463
|
-
end
|
575
|
+
def validate_format
|
576
|
+
if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format)
|
577
|
+
raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{parser.supported_formats.map(&:to_s).sort.join(', ')}"
|
464
578
|
end
|
579
|
+
end
|
465
580
|
end
|
466
581
|
|
467
582
|
def self.normalize_base_uri(url) #:nodoc:
|
@@ -499,6 +614,14 @@ module HTTParty
|
|
499
614
|
Basement.delete(*args, &block)
|
500
615
|
end
|
501
616
|
|
617
|
+
def self.move(*args, &block)
|
618
|
+
Basement.move(*args, &block)
|
619
|
+
end
|
620
|
+
|
621
|
+
def self.copy(*args, &block)
|
622
|
+
Basement.copy(*args, &block)
|
623
|
+
end
|
624
|
+
|
502
625
|
def self.head(*args, &block)
|
503
626
|
Basement.head(*args, &block)
|
504
627
|
end
|
@@ -508,7 +631,6 @@ module HTTParty
|
|
508
631
|
end
|
509
632
|
end
|
510
633
|
|
511
|
-
require 'httparty/core_extensions'
|
512
634
|
require 'httparty/hash_conversions'
|
513
635
|
require 'httparty/exceptions'
|
514
636
|
require 'httparty/parser'
|
data/script/release
ADDED
@@ -0,0 +1,42 @@
|
|
1
|
+
#!/bin/sh
|
2
|
+
#/ Usage: release
|
3
|
+
#/
|
4
|
+
#/ Tag the version in the repo and push the gem.
|
5
|
+
#/
|
6
|
+
|
7
|
+
set -e
|
8
|
+
cd $(dirname "$0")/..
|
9
|
+
|
10
|
+
[ "$1" = "--help" -o "$1" = "-h" -o "$1" = "help" ] && {
|
11
|
+
grep '^#/' <"$0"| cut -c4-
|
12
|
+
exit 0
|
13
|
+
}
|
14
|
+
|
15
|
+
gem_name=httparty
|
16
|
+
|
17
|
+
# Build a new gem archive.
|
18
|
+
rm -rf $gem_name-*.gem
|
19
|
+
gem build -q $gem_name.gemspec
|
20
|
+
|
21
|
+
# Make sure we're on the master branch.
|
22
|
+
(git branch | grep -q '* master') || {
|
23
|
+
echo "Only release from the master branch."
|
24
|
+
exit 1
|
25
|
+
}
|
26
|
+
|
27
|
+
# Figure out what version we're releasing.
|
28
|
+
tag=v`ls $gem_name-*.gem | sed "s/^$gem_name-\(.*\)\.gem$/\1/"`
|
29
|
+
|
30
|
+
echo "Releasing $tag"
|
31
|
+
|
32
|
+
# Make sure we haven't released this version before.
|
33
|
+
git fetch -t origin
|
34
|
+
|
35
|
+
(git tag -l | grep -q "$tag") && {
|
36
|
+
echo "Whoops, there's already a '${tag}' tag."
|
37
|
+
exit 1
|
38
|
+
}
|
39
|
+
|
40
|
+
# Tag it and bag it.
|
41
|
+
gem push $gem_name-*.gem && git tag "$tag" &&
|
42
|
+
git push origin master && git push origin "$tag"
|