piko-clean-pkg 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.
Files changed (64) hide show
  1. checksums.yaml +7 -0
  2. data/httparty-0.24.2/CONTRIBUTING.md +23 -0
  3. data/httparty-0.24.2/Changelog.md +624 -0
  4. data/httparty-0.24.2/Gemfile +27 -0
  5. data/httparty-0.24.2/Guardfile +17 -0
  6. data/httparty-0.24.2/MIT-LICENSE +20 -0
  7. data/httparty-0.24.2/README.md +79 -0
  8. data/httparty-0.24.2/Rakefile +10 -0
  9. data/httparty-0.24.2/bin/httparty +123 -0
  10. data/httparty-0.24.2/cucumber.yml +1 -0
  11. data/httparty-0.24.2/docs/README.md +223 -0
  12. data/httparty-0.24.2/examples/README.md +90 -0
  13. data/httparty-0.24.2/examples/aaws.rb +36 -0
  14. data/httparty-0.24.2/examples/basic.rb +28 -0
  15. data/httparty-0.24.2/examples/body_stream.rb +14 -0
  16. data/httparty-0.24.2/examples/crack.rb +19 -0
  17. data/httparty-0.24.2/examples/custom_parsers.rb +68 -0
  18. data/httparty-0.24.2/examples/delicious.rb +37 -0
  19. data/httparty-0.24.2/examples/google.rb +16 -0
  20. data/httparty-0.24.2/examples/headers_and_user_agents.rb +10 -0
  21. data/httparty-0.24.2/examples/idn.rb +10 -0
  22. data/httparty-0.24.2/examples/logging.rb +36 -0
  23. data/httparty-0.24.2/examples/microsoft_graph.rb +52 -0
  24. data/httparty-0.24.2/examples/multipart.rb +35 -0
  25. data/httparty-0.24.2/examples/nokogiri_html_parser.rb +19 -0
  26. data/httparty-0.24.2/examples/party_foul_mode.rb +90 -0
  27. data/httparty-0.24.2/examples/peer_cert.rb +9 -0
  28. data/httparty-0.24.2/examples/rescue_json.rb +17 -0
  29. data/httparty-0.24.2/examples/rubyurl.rb +14 -0
  30. data/httparty-0.24.2/examples/stackexchange.rb +24 -0
  31. data/httparty-0.24.2/examples/stream_download.rb +26 -0
  32. data/httparty-0.24.2/examples/tripit_sign_in.rb +44 -0
  33. data/httparty-0.24.2/examples/twitter.rb +31 -0
  34. data/httparty-0.24.2/examples/whoismyrep.rb +10 -0
  35. data/httparty-0.24.2/httparty.gemspec +32 -0
  36. data/httparty-0.24.2/lib/httparty/connection_adapter.rb +237 -0
  37. data/httparty-0.24.2/lib/httparty/cookie_hash.rb +23 -0
  38. data/httparty-0.24.2/lib/httparty/decompressor.rb +102 -0
  39. data/httparty-0.24.2/lib/httparty/exceptions.rb +66 -0
  40. data/httparty-0.24.2/lib/httparty/hash_conversions.rb +71 -0
  41. data/httparty-0.24.2/lib/httparty/headers_processor.rb +32 -0
  42. data/httparty-0.24.2/lib/httparty/logger/apache_formatter.rb +47 -0
  43. data/httparty-0.24.2/lib/httparty/logger/curl_formatter.rb +93 -0
  44. data/httparty-0.24.2/lib/httparty/logger/logger.rb +30 -0
  45. data/httparty-0.24.2/lib/httparty/logger/logstash_formatter.rb +62 -0
  46. data/httparty-0.24.2/lib/httparty/module_inheritable_attributes.rb +56 -0
  47. data/httparty-0.24.2/lib/httparty/net_digest_auth.rb +135 -0
  48. data/httparty-0.24.2/lib/httparty/parser.rb +157 -0
  49. data/httparty-0.24.2/lib/httparty/request/body.rb +125 -0
  50. data/httparty-0.24.2/lib/httparty/request/multipart_boundary.rb +13 -0
  51. data/httparty-0.24.2/lib/httparty/request/streaming_multipart_body.rb +190 -0
  52. data/httparty-0.24.2/lib/httparty/request.rb +466 -0
  53. data/httparty-0.24.2/lib/httparty/response/headers.rb +35 -0
  54. data/httparty-0.24.2/lib/httparty/response.rb +156 -0
  55. data/httparty-0.24.2/lib/httparty/response_fragment.rb +21 -0
  56. data/httparty-0.24.2/lib/httparty/text_encoder.rb +72 -0
  57. data/httparty-0.24.2/lib/httparty/utils.rb +13 -0
  58. data/httparty-0.24.2/lib/httparty/version.rb +5 -0
  59. data/httparty-0.24.2/lib/httparty.rb +699 -0
  60. data/httparty-0.24.2/script/release +42 -0
  61. data/httparty-0.24.2/website/css/common.css +47 -0
  62. data/httparty-0.24.2/website/index.html +73 -0
  63. data/piko-clean-pkg.gemspec +12 -0
  64. metadata +103 -0
@@ -0,0 +1,699 @@
1
+ # frozen_string_literal: true
2
+
3
+ require 'pathname'
4
+ require 'net/http'
5
+ require 'uri'
6
+
7
+ require 'httparty/module_inheritable_attributes'
8
+ require 'httparty/cookie_hash'
9
+ require 'httparty/net_digest_auth'
10
+ require 'httparty/version'
11
+ require 'httparty/connection_adapter'
12
+ require 'httparty/logger/logger'
13
+ require 'httparty/request/body'
14
+ require 'httparty/response_fragment'
15
+ require 'httparty/decompressor'
16
+ require 'httparty/text_encoder'
17
+ require 'httparty/headers_processor'
18
+
19
+ # @see HTTParty::ClassMethods
20
+ module HTTParty
21
+ def self.included(base)
22
+ base.extend ClassMethods
23
+ base.send :include, ModuleInheritableAttributes
24
+ base.send(:mattr_inheritable, :default_options)
25
+ base.send(:mattr_inheritable, :default_cookies)
26
+ base.instance_variable_set(:@default_options, {})
27
+ base.instance_variable_set(:@default_cookies, CookieHash.new)
28
+ end
29
+
30
+ # == Common Request Options
31
+ # Request methods (get, post, patch, put, delete, head, options) all take a common set of options. These are:
32
+ #
33
+ # [:+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.
34
+ # [:+http_proxyaddr+:] Address of proxy server to use.
35
+ # [:+http_proxyport+:] Port of proxy server to use.
36
+ # [:+http_proxyuser+:] User for proxy server authentication.
37
+ # [:+http_proxypass+:] Password for proxy server authentication.
38
+ # [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
39
+ # [:+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.
40
+ # [:+timeout+:] Timeout for opening connection and reading data.
41
+ # [:+local_host+:] Local address to bind to before connecting.
42
+ # [:+local_port+:] Local port to bind to before connecting.
43
+ # [:+body_stream+:] Allow streaming to a REST server to specify a body_stream.
44
+ # [:+stream_body+:] When downloading with a block, avoids accumulating the response in memory. When uploading files, streams the request body to reduce memory usage (opt-in).
45
+ # [:+multipart+:] Force content-type to be multipart
46
+ #
47
+ # 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:
48
+ # * :+base_uri+: see HTTParty::ClassMethods.base_uri.
49
+ # * :+basic_auth+: see HTTParty::ClassMethods.basic_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.
50
+ # * :+debug_output+: see HTTParty::ClassMethods.debug_output.
51
+ # * :+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.
52
+ # * :+format+: see HTTParty::ClassMethods.format.
53
+ # * :+headers+: see HTTParty::ClassMethods.headers. Must be a an object which responds to #to_hash.
54
+ # * :+maintain_method_across_redirects+: see HTTParty::ClassMethods.maintain_method_across_redirects.
55
+ # * :+no_follow+: see HTTParty::ClassMethods.no_follow.
56
+ # * :+parser+: see HTTParty::ClassMethods.parser.
57
+ # * :+uri_adapter+: see HTTParty::ClassMethods.uri_adapter
58
+ # * :+connection_adapter+: see HTTParty::ClassMethods.connection_adapter.
59
+ # * :+pem+: see HTTParty::ClassMethods.pem.
60
+ # * :+query_string_normalizer+: see HTTParty::ClassMethods.query_string_normalizer
61
+ # * :+ssl_ca_file+: see HTTParty::ClassMethods.ssl_ca_file.
62
+ # * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
63
+
64
+ module ClassMethods
65
+ # Turns on or off the foul option.
66
+ #
67
+ # class Foo
68
+ # include HTTParty
69
+ # foul true
70
+ # end
71
+ def foul(bool)
72
+ default_options[:foul] = bool
73
+ end
74
+
75
+ # Turns on logging
76
+ #
77
+ # class Foo
78
+ # include HTTParty
79
+ # logger Logger.new('http_logger'), :info, :apache
80
+ # end
81
+ def logger(logger, level = :info, format = :apache)
82
+ default_options[:logger] = logger
83
+ default_options[:log_level] = level
84
+ default_options[:log_format] = format
85
+ end
86
+
87
+ # Raises HTTParty::ResponseError if response's code matches this statuses
88
+ #
89
+ # class Foo
90
+ # include HTTParty
91
+ # raise_on [404, 500, '5[0-9]*']
92
+ # end
93
+ def raise_on(codes = [])
94
+ default_options[:raise_on] = *codes
95
+ end
96
+
97
+ # Allows setting http proxy information to be used
98
+ #
99
+ # class Foo
100
+ # include HTTParty
101
+ # http_proxy 'http://foo.com', 80, 'user', 'pass'
102
+ # end
103
+ def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
104
+ default_options[:http_proxyaddr] = addr
105
+ default_options[:http_proxyport] = port
106
+ default_options[:http_proxyuser] = user
107
+ default_options[:http_proxypass] = pass
108
+ end
109
+
110
+ # Allows setting a base uri to be used for each request.
111
+ # Will normalize uri to include http, etc.
112
+ #
113
+ # class Foo
114
+ # include HTTParty
115
+ # base_uri 'twitter.com'
116
+ # end
117
+ def base_uri(uri = nil)
118
+ return default_options[:base_uri] unless uri
119
+ default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
120
+ end
121
+
122
+ # Allows setting basic authentication username and password.
123
+ #
124
+ # class Foo
125
+ # include HTTParty
126
+ # basic_auth 'username', 'password'
127
+ # end
128
+ def basic_auth(u, p)
129
+ default_options[:basic_auth] = {username: u, password: p}
130
+ end
131
+
132
+ # Allows setting digest authentication username and password.
133
+ #
134
+ # class Foo
135
+ # include HTTParty
136
+ # digest_auth 'username', 'password'
137
+ # end
138
+ def digest_auth(u, p)
139
+ default_options[:digest_auth] = {username: u, password: p}
140
+ end
141
+
142
+ # Do not send rails style query strings.
143
+ # Specifically, don't use bracket notation when sending an array
144
+ #
145
+ # For a query:
146
+ # get '/', query: {selected_ids: [1,2,3]}
147
+ #
148
+ # The default query string looks like this:
149
+ # /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
150
+ #
151
+ # Call `disable_rails_query_string_format` to transform the query string
152
+ # into:
153
+ # /?selected_ids=1&selected_ids=2&selected_ids=3
154
+ #
155
+ # @example
156
+ # class Foo
157
+ # include HTTParty
158
+ # disable_rails_query_string_format
159
+ # end
160
+ def disable_rails_query_string_format
161
+ query_string_normalizer Request::NON_RAILS_QUERY_STRING_NORMALIZER
162
+ end
163
+
164
+ # Allows setting default parameters to be appended to each request.
165
+ # Great for api keys and such.
166
+ #
167
+ # class Foo
168
+ # include HTTParty
169
+ # default_params api_key: 'secret', another: 'foo'
170
+ # end
171
+ def default_params(h = {})
172
+ raise ArgumentError, 'Default params must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
173
+ default_options[:default_params] ||= {}
174
+ default_options[:default_params].merge!(h)
175
+ end
176
+
177
+ # Allows setting a default timeout for all HTTP calls
178
+ # Timeout is specified in seconds.
179
+ #
180
+ # class Foo
181
+ # include HTTParty
182
+ # default_timeout 10
183
+ # end
184
+ def default_timeout(value)
185
+ validate_timeout_argument(__method__, value)
186
+ default_options[:timeout] = value
187
+ end
188
+
189
+ # Allows setting a default open_timeout for all HTTP calls in seconds
190
+ #
191
+ # class Foo
192
+ # include HTTParty
193
+ # open_timeout 10
194
+ # end
195
+ def open_timeout(value)
196
+ validate_timeout_argument(__method__, value)
197
+ default_options[:open_timeout] = value
198
+ end
199
+
200
+ # Allows setting a default read_timeout for all HTTP calls in seconds
201
+ #
202
+ # class Foo
203
+ # include HTTParty
204
+ # read_timeout 10
205
+ # end
206
+ def read_timeout(value)
207
+ validate_timeout_argument(__method__, value)
208
+ default_options[:read_timeout] = value
209
+ end
210
+
211
+ # Allows setting a default write_timeout for all HTTP calls in seconds
212
+ # Supported by Ruby > 2.6.0
213
+ #
214
+ # class Foo
215
+ # include HTTParty
216
+ # write_timeout 10
217
+ # end
218
+ def write_timeout(value)
219
+ validate_timeout_argument(__method__, value)
220
+ default_options[:write_timeout] = value
221
+ end
222
+
223
+
224
+ # Set an output stream for debugging, defaults to $stderr.
225
+ # The output stream is passed on to Net::HTTP#set_debug_output.
226
+ #
227
+ # class Foo
228
+ # include HTTParty
229
+ # debug_output $stderr
230
+ # end
231
+ def debug_output(stream = $stderr)
232
+ default_options[:debug_output] = stream
233
+ end
234
+
235
+ # Allows setting HTTP headers to be used for each request.
236
+ #
237
+ # class Foo
238
+ # include HTTParty
239
+ # headers 'Accept' => 'text/html'
240
+ # end
241
+ def headers(h = nil)
242
+ if h
243
+ raise ArgumentError, 'Headers must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
244
+ default_options[:headers] ||= {}
245
+ default_options[:headers].merge!(h.to_hash)
246
+ else
247
+ default_options[:headers] || {}
248
+ end
249
+ end
250
+
251
+ def cookies(h = {})
252
+ raise ArgumentError, 'Cookies must be an object which responds to #to_hash' unless h.respond_to?(:to_hash)
253
+ default_cookies.add_cookies(h)
254
+ end
255
+
256
+ # Proceed to the location header when an HTTP response dictates a redirect.
257
+ # Redirects are always followed by default.
258
+ #
259
+ # @example
260
+ # class Foo
261
+ # include HTTParty
262
+ # base_uri 'http://google.com'
263
+ # follow_redirects true
264
+ # end
265
+ def follow_redirects(value = true)
266
+ default_options[:follow_redirects] = value
267
+ end
268
+
269
+ # Allows setting the format with which to parse.
270
+ # Must be one of the allowed formats ie: json, xml
271
+ #
272
+ # class Foo
273
+ # include HTTParty
274
+ # format :json
275
+ # end
276
+ def format(f = nil)
277
+ if f.nil?
278
+ default_options[:format]
279
+ else
280
+ parser(Parser) if parser.nil?
281
+ default_options[:format] = f
282
+ validate_format
283
+ end
284
+ end
285
+
286
+ # Declare whether or not to follow redirects. When true, an
287
+ # {HTTParty::RedirectionTooDeep} error will raise upon encountering a
288
+ # redirect. You can then gain access to the response object via
289
+ # HTTParty::RedirectionTooDeep#response.
290
+ #
291
+ # @see HTTParty::ResponseError#response
292
+ #
293
+ # @example
294
+ # class Foo
295
+ # include HTTParty
296
+ # base_uri 'http://google.com'
297
+ # no_follow true
298
+ # end
299
+ #
300
+ # begin
301
+ # Foo.get('/')
302
+ # rescue HTTParty::RedirectionTooDeep => e
303
+ # puts e.response.body
304
+ # end
305
+ def no_follow(value = false)
306
+ default_options[:no_follow] = value
307
+ end
308
+
309
+ # Declare that you wish to maintain the chosen HTTP method across redirects.
310
+ # The default behavior is to follow redirects via the GET method, except
311
+ # if you are making a HEAD request, in which case the default is to
312
+ # follow all redirects with HEAD requests.
313
+ # If you wish to maintain the original method, you can set this option to true.
314
+ #
315
+ # @example
316
+ # class Foo
317
+ # include HTTParty
318
+ # base_uri 'http://google.com'
319
+ # maintain_method_across_redirects true
320
+ # end
321
+
322
+ def maintain_method_across_redirects(value = true)
323
+ default_options[:maintain_method_across_redirects] = value
324
+ end
325
+
326
+ # Declare that you wish to resend the full HTTP request across redirects,
327
+ # even on redirects that should logically become GET requests.
328
+ # A 303 redirect in HTTP signifies that the redirected url should normally
329
+ # retrieved using a GET request, for instance, it is the output of a previous
330
+ # POST. maintain_method_across_redirects respects this behavior, but you
331
+ # can force HTTParty to resend_on_redirect even on 303 responses.
332
+ #
333
+ # @example
334
+ # class Foo
335
+ # include HTTParty
336
+ # base_uri 'http://google.com'
337
+ # resend_on_redirect
338
+ # end
339
+
340
+ def resend_on_redirect(value = true)
341
+ default_options[:resend_on_redirect] = value
342
+ end
343
+
344
+ # Allows setting a PEM file to be used
345
+ #
346
+ # class Foo
347
+ # include HTTParty
348
+ # pem File.read('/home/user/my.pem'), "optional password"
349
+ # end
350
+ def pem(pem_contents, password = nil)
351
+ default_options[:pem] = pem_contents
352
+ default_options[:pem_password] = password
353
+ end
354
+
355
+ # Allows setting a PKCS12 file to be used
356
+ #
357
+ # class Foo
358
+ # include HTTParty
359
+ # pkcs12 File.read('/home/user/my.p12'), "password"
360
+ # end
361
+ def pkcs12(p12_contents, password)
362
+ default_options[:p12] = p12_contents
363
+ default_options[:p12_password] = password
364
+ end
365
+
366
+ # Override the way query strings are normalized.
367
+ # Helpful for overriding the default rails normalization of Array queries.
368
+ #
369
+ # For a query:
370
+ # get '/', query: {selected_ids: [1,2,3]}
371
+ #
372
+ # The default query string normalizer returns:
373
+ # /?selected_ids[]=1&selected_ids[]=2&selected_ids[]=3
374
+ #
375
+ # Let's change it to this:
376
+ # /?selected_ids=1&selected_ids=2&selected_ids=3
377
+ #
378
+ # Pass a Proc to the query normalizer which accepts the yielded query.
379
+ #
380
+ # @example Modifying Array query strings
381
+ # class ServiceWrapper
382
+ # include HTTParty
383
+ #
384
+ # query_string_normalizer proc { |query|
385
+ # query.map do |key, value|
386
+ # value.map {|v| "#{key}=#{v}"}
387
+ # end.join('&')
388
+ # }
389
+ # end
390
+ #
391
+ # @param [Proc] normalizer custom query string normalizer.
392
+ # @yield [Hash, String] query string
393
+ # @yieldreturn [Array] an array that will later be joined with '&'
394
+ def query_string_normalizer(normalizer)
395
+ default_options[:query_string_normalizer] = normalizer
396
+ end
397
+
398
+ # Allows setting of SSL version to use. This only works in Ruby 1.9+.
399
+ # You can get a list of valid versions from OpenSSL::SSL::SSLContext::METHODS.
400
+ #
401
+ # class Foo
402
+ # include HTTParty
403
+ # ssl_version :SSLv3
404
+ # end
405
+ def ssl_version(version)
406
+ default_options[:ssl_version] = version
407
+ end
408
+
409
+ # Deactivate automatic decompression of the response body.
410
+ # This will require you to explicitly handle body decompression
411
+ # by inspecting the Content-Encoding response header.
412
+ #
413
+ # Refer to docs/README.md "HTTP Compression" section for
414
+ # further details.
415
+ #
416
+ # @example
417
+ # class Foo
418
+ # include HTTParty
419
+ # skip_decompression
420
+ # end
421
+ def skip_decompression(value = true)
422
+ default_options[:skip_decompression] = !!value
423
+ end
424
+
425
+ # Allows setting of SSL ciphers to use. This only works in Ruby 1.9+.
426
+ # You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
427
+ # You also can specify a cipher suite here, listed here at openssl.org:
428
+ # http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
429
+ #
430
+ # class Foo
431
+ # include HTTParty
432
+ # ciphers "RC4-SHA"
433
+ # end
434
+ def ciphers(cipher_names)
435
+ default_options[:ciphers] = cipher_names
436
+ end
437
+
438
+ # Allows setting an OpenSSL certificate authority file. The file
439
+ # should contain one or more certificates in PEM format.
440
+ #
441
+ # Setting this option enables certificate verification. All
442
+ # certificates along a chain must be available in ssl_ca_file or
443
+ # ssl_ca_path for verification to succeed.
444
+ #
445
+ #
446
+ # class Foo
447
+ # include HTTParty
448
+ # ssl_ca_file '/etc/ssl/certs/ca-certificates.crt'
449
+ # end
450
+ def ssl_ca_file(path)
451
+ default_options[:ssl_ca_file] = path
452
+ end
453
+
454
+ # Allows setting an OpenSSL certificate authority path (directory).
455
+ #
456
+ # Setting this option enables certificate verification. All
457
+ # certificates along a chain must be available in ssl_ca_file or
458
+ # ssl_ca_path for verification to succeed.
459
+ #
460
+ # class Foo
461
+ # include HTTParty
462
+ # ssl_ca_path '/etc/ssl/certs/'
463
+ # end
464
+ def ssl_ca_path(path)
465
+ default_options[:ssl_ca_path] = path
466
+ end
467
+
468
+ # Allows setting a custom parser for the response.
469
+ #
470
+ # class Foo
471
+ # include HTTParty
472
+ # parser Proc.new {|data| ...}
473
+ # end
474
+ def parser(custom_parser = nil)
475
+ if custom_parser.nil?
476
+ default_options[:parser]
477
+ else
478
+ default_options[:parser] = custom_parser
479
+ validate_format
480
+ end
481
+ end
482
+
483
+ # Allows setting a custom URI adapter.
484
+ #
485
+ # class Foo
486
+ # include HTTParty
487
+ # uri_adapter Addressable::URI
488
+ # end
489
+ def uri_adapter(uri_adapter)
490
+ raise ArgumentError, 'The URI adapter should respond to #parse' unless uri_adapter.respond_to?(:parse)
491
+ default_options[:uri_adapter] = uri_adapter
492
+ end
493
+
494
+ # Allows setting a custom connection_adapter for the http connections
495
+ #
496
+ # @example
497
+ # class Foo
498
+ # include HTTParty
499
+ # connection_adapter Proc.new {|uri, options| ... }
500
+ # end
501
+ #
502
+ # @example provide optional configuration for your connection_adapter
503
+ # class Foo
504
+ # include HTTParty
505
+ # connection_adapter Proc.new {|uri, options| ... }, {foo: :bar}
506
+ # end
507
+ #
508
+ # @see HTTParty::ConnectionAdapter
509
+ def connection_adapter(custom_adapter = nil, options = nil)
510
+ if custom_adapter.nil?
511
+ default_options[:connection_adapter]
512
+ else
513
+ default_options[:connection_adapter] = custom_adapter
514
+ default_options[:connection_adapter_options] = options
515
+ end
516
+ end
517
+
518
+ # Allows making a get request to a url.
519
+ #
520
+ # class Foo
521
+ # include HTTParty
522
+ # end
523
+ #
524
+ # # Simple get with full url
525
+ # Foo.get('http://foo.com/resource.json')
526
+ #
527
+ # # Simple get with full url and query parameters
528
+ # # ie: http://foo.com/resource.json?limit=10
529
+ # Foo.get('http://foo.com/resource.json', query: {limit: 10})
530
+ def get(path, options = {}, &block)
531
+ perform_request Net::HTTP::Get, path, options, &block
532
+ end
533
+
534
+ # Allows making a post request to a url.
535
+ #
536
+ # class Foo
537
+ # include HTTParty
538
+ # end
539
+ #
540
+ # # Simple post with full url and setting the body
541
+ # Foo.post('http://foo.com/resources', body: {bar: 'baz'})
542
+ #
543
+ # # Simple post with full url using :query option,
544
+ # # which appends the parameters to the URI.
545
+ # Foo.post('http://foo.com/resources', query: {bar: 'baz'})
546
+ def post(path, options = {}, &block)
547
+ perform_request Net::HTTP::Post, path, options, &block
548
+ end
549
+
550
+ # Perform a PATCH request to a path
551
+ def patch(path, options = {}, &block)
552
+ perform_request Net::HTTP::Patch, path, options, &block
553
+ end
554
+
555
+ # Perform a PUT request to a path
556
+ def put(path, options = {}, &block)
557
+ perform_request Net::HTTP::Put, path, options, &block
558
+ end
559
+
560
+ # Perform a DELETE request to a path
561
+ def delete(path, options = {}, &block)
562
+ perform_request Net::HTTP::Delete, path, options, &block
563
+ end
564
+
565
+ # Perform a MOVE request to a path
566
+ def move(path, options = {}, &block)
567
+ perform_request Net::HTTP::Move, path, options, &block
568
+ end
569
+
570
+ # Perform a COPY request to a path
571
+ def copy(path, options = {}, &block)
572
+ perform_request Net::HTTP::Copy, path, options, &block
573
+ end
574
+
575
+ # Perform a HEAD request to a path
576
+ def head(path, options = {}, &block)
577
+ ensure_method_maintained_across_redirects options
578
+ perform_request Net::HTTP::Head, path, options, &block
579
+ end
580
+
581
+ # Perform an OPTIONS request to a path
582
+ def options(path, options = {}, &block)
583
+ perform_request Net::HTTP::Options, path, options, &block
584
+ end
585
+
586
+ # Perform a MKCOL request to a path
587
+ def mkcol(path, options = {}, &block)
588
+ perform_request Net::HTTP::Mkcol, path, options, &block
589
+ end
590
+
591
+ def lock(path, options = {}, &block)
592
+ perform_request Net::HTTP::Lock, path, options, &block
593
+ end
594
+
595
+ def unlock(path, options = {}, &block)
596
+ perform_request Net::HTTP::Unlock, path, options, &block
597
+ end
598
+
599
+ def build_request(http_method, path, options = {})
600
+ options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
601
+ HeadersProcessor.new(headers, options).call
602
+ process_cookies(options)
603
+ Request.new(http_method, path, options)
604
+ end
605
+
606
+ attr_reader :default_options
607
+
608
+ private
609
+
610
+ def validate_timeout_argument(timeout_type, value)
611
+ raise ArgumentError, "#{ timeout_type } must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
612
+ end
613
+
614
+ def ensure_method_maintained_across_redirects(options)
615
+ unless options.key?(:maintain_method_across_redirects)
616
+ options[:maintain_method_across_redirects] = true
617
+ end
618
+ end
619
+
620
+ def perform_request(http_method, path, options, &block) #:nodoc:
621
+ build_request(http_method, path, options).perform(&block)
622
+ end
623
+
624
+ def process_cookies(options) #:nodoc:
625
+ return unless options[:cookies] || default_cookies.any?
626
+ options[:headers] ||= headers.dup
627
+ options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
628
+ end
629
+
630
+ def validate_format
631
+ if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format)
632
+ supported_format_names = parser.supported_formats.map(&:to_s).sort.join(', ')
633
+ raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{supported_format_names}"
634
+ end
635
+ end
636
+ end
637
+
638
+ def self.normalize_base_uri(url) #:nodoc:
639
+ normalized_url = url.dup
640
+ use_ssl = (normalized_url =~ /^https/) || (normalized_url =~ /:443\b/)
641
+ ends_with_slash = normalized_url =~ /\/$/
642
+
643
+ normalized_url.chop! if ends_with_slash
644
+ normalized_url.gsub!(/^https?:\/\//i, '')
645
+
646
+ "http#{'s' if use_ssl}://#{normalized_url}"
647
+ end
648
+
649
+ class Basement #:nodoc:
650
+ include HTTParty
651
+ end
652
+
653
+ def self.get(*args, &block)
654
+ Basement.get(*args, &block)
655
+ end
656
+
657
+ def self.post(*args, &block)
658
+ Basement.post(*args, &block)
659
+ end
660
+
661
+ def self.patch(*args, &block)
662
+ Basement.patch(*args, &block)
663
+ end
664
+
665
+ def self.put(*args, &block)
666
+ Basement.put(*args, &block)
667
+ end
668
+
669
+ def self.delete(*args, &block)
670
+ Basement.delete(*args, &block)
671
+ end
672
+
673
+ def self.move(*args, &block)
674
+ Basement.move(*args, &block)
675
+ end
676
+
677
+ def self.copy(*args, &block)
678
+ Basement.copy(*args, &block)
679
+ end
680
+
681
+ def self.head(*args, &block)
682
+ Basement.head(*args, &block)
683
+ end
684
+
685
+ def self.options(*args, &block)
686
+ Basement.options(*args, &block)
687
+ end
688
+
689
+ def self.build_request(*args, &block)
690
+ Basement.build_request(*args, &block)
691
+ end
692
+ end
693
+
694
+ require 'httparty/hash_conversions'
695
+ require 'httparty/utils'
696
+ require 'httparty/exceptions'
697
+ require 'httparty/parser'
698
+ require 'httparty/request'
699
+ require 'httparty/response'