httparty 0.13.3 → 0.13.4

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.

Files changed (58) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +1 -0
  3. data/.rubocop.yml +92 -0
  4. data/.rubocop_todo.yml +124 -0
  5. data/.simplecov +1 -0
  6. data/Gemfile +8 -3
  7. data/Guardfile +1 -1
  8. data/README.md +1 -0
  9. data/Rakefile +4 -5
  10. data/bin/httparty +9 -10
  11. data/examples/README.md +3 -0
  12. data/examples/aaws.rb +2 -2
  13. data/examples/crack.rb +1 -1
  14. data/examples/custom_parsers.rb +1 -4
  15. data/examples/delicious.rb +3 -3
  16. data/examples/google.rb +2 -2
  17. data/examples/logging.rb +5 -7
  18. data/examples/nokogiri_html_parser.rb +0 -3
  19. data/examples/rescue_json.rb +17 -0
  20. data/examples/rubyurl.rb +3 -3
  21. data/examples/twitter.rb +2 -2
  22. data/examples/whoismyrep.rb +1 -1
  23. data/features/command_line.feature +85 -2
  24. data/features/steps/env.rb +16 -11
  25. data/features/steps/httparty_response_steps.rb +13 -13
  26. data/features/steps/mongrel_helper.rb +2 -2
  27. data/features/steps/remote_service_steps.rb +18 -6
  28. data/httparty.gemspec +4 -4
  29. data/lib/httparty.rb +37 -56
  30. data/lib/httparty/connection_adapter.rb +3 -4
  31. data/lib/httparty/cookie_hash.rb +2 -3
  32. data/lib/httparty/hash_conversions.rb +3 -5
  33. data/lib/httparty/logger/apache_logger.rb +1 -1
  34. data/lib/httparty/logger/logger.rb +1 -1
  35. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  36. data/lib/httparty/net_digest_auth.rb +46 -16
  37. data/lib/httparty/request.rb +16 -16
  38. data/lib/httparty/response.rb +9 -4
  39. data/lib/httparty/version.rb +1 -1
  40. data/spec/httparty/connection_adapter_spec.rb +184 -100
  41. data/spec/httparty/cookie_hash_spec.rb +21 -21
  42. data/spec/httparty/exception_spec.rb +22 -7
  43. data/spec/httparty/hash_conversions_spec.rb +41 -0
  44. data/spec/httparty/logger/apache_logger_spec.rb +3 -3
  45. data/spec/httparty/logger/curl_logger_spec.rb +2 -2
  46. data/spec/httparty/logger/logger_spec.rb +7 -7
  47. data/spec/httparty/net_digest_auth_spec.rb +60 -32
  48. data/spec/httparty/parser_spec.rb +37 -35
  49. data/spec/httparty/request_spec.rb +249 -193
  50. data/spec/httparty/response_spec.rb +37 -29
  51. data/spec/httparty/ssl_spec.rb +21 -21
  52. data/spec/httparty_spec.rb +153 -164
  53. data/spec/spec_helper.rb +34 -12
  54. data/spec/support/ssl_test_helper.rb +2 -2
  55. data/spec/support/ssl_test_server.rb +21 -21
  56. data/spec/support/stub_response.rb +10 -10
  57. metadata +9 -4
  58. data/lib/httparty/core_extensions.rb +0 -32
@@ -10,7 +10,7 @@ end
10
10
  # google.com redirects to www.google.com so this is live test for redirection
11
11
  pp Google.get('http://google.com')
12
12
 
13
- puts '', '*'*70, ''
13
+ puts '', '*' * 70, ''
14
14
 
15
15
  # check that ssl is requesting right
16
- pp Google.get('https://www.google.com')
16
+ pp Google.get('https://www.google.com')
@@ -8,31 +8,29 @@ my_logger = Logger.new "httparty.log"
8
8
  my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
9
9
  HTTParty.get "http://google.com", logger: my_logger
10
10
 
11
- my_logger.info '*'*70
11
+ my_logger.info '*' * 70
12
12
 
13
13
  my_logger.info "It can be used also on a custom class."
14
14
 
15
15
  class Google
16
16
  include HTTParty
17
- logger ::Logger.new "httparty.log"
17
+ logger ::Logger.new "httparty.log"
18
18
  end
19
19
 
20
20
  Google.get "http://google.com"
21
21
 
22
- my_logger.info '*'*70
22
+ my_logger.info '*' * 70
23
23
 
24
24
  my_logger.info "The default formatter is :apache. The :curl formatter can also be used."
25
25
  my_logger.info "You can tell wich method to call on the logger too. It is info by default."
26
26
  HTTParty.get "http://google.com", logger: my_logger, log_level: :debug, log_format: :curl
27
27
 
28
-
29
- my_logger.info '*'*70
28
+ my_logger.info '*' * 70
30
29
 
31
30
  my_logger.info "These configs are also available on custom classes."
32
31
  class Google
33
32
  include HTTParty
34
- logger ::Logger.new("httparty.log"), :debug, :curl
33
+ logger ::Logger.new("httparty.log"), :debug, :curl
35
34
  end
36
35
 
37
36
  Google.get "http://google.com"
38
-
@@ -1,14 +1,11 @@
1
1
  require 'rubygems'
2
2
  require 'nokogiri'
3
3
 
4
-
5
4
  dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
6
5
  require File.join(dir, 'httparty')
7
6
  require 'pp'
8
7
 
9
8
  class HtmlParserIncluded < HTTParty::Parser
10
- SupportedFormats.merge!('text/html' => :html)
11
-
12
9
  def html
13
10
  Nokogiri::HTML(body)
14
11
  end
@@ -0,0 +1,17 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+
4
+ # Take note of the "; 1" at the end of the following line. It's required only if
5
+ # running this in IRB, because IRB will try to inspect the variable named
6
+ # "request", triggering the exception.
7
+ request = HTTParty.get 'https://rubygems.org/api/v1/versions/doesnotexist.json' ; 1
8
+
9
+ # Check an exception due to parsing the response
10
+ # because HTTParty evaluate the response lazily
11
+ begin
12
+ request.inspect
13
+ # This would also suffice by forcing the request to be parsed:
14
+ # request.parsed_response
15
+ rescue => e
16
+ puts "Rescued #{e.inspect}"
17
+ end
@@ -6,9 +6,9 @@ class Rubyurl
6
6
  include HTTParty
7
7
  base_uri 'rubyurl.com'
8
8
 
9
- def self.shorten( website_url )
10
- post( '/api/links.json', query: { link: { website_url: website_url } } )
9
+ def self.shorten(website_url)
10
+ post('/api/links.json', query: { link: { website_url: website_url } })
11
11
  end
12
12
  end
13
13
 
14
- pp Rubyurl.shorten( 'http://istwitterdown.com/')
14
+ pp Rubyurl.shorten('http://istwitterdown.com/')
@@ -1,7 +1,7 @@
1
1
  dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
2
  require File.join(dir, 'httparty')
3
3
  require 'pp'
4
- config = YAML::load(File.read(File.join(ENV['HOME'], '.twitter')))
4
+ config = YAML.load(File.read(File.join(ENV['HOME'], '.twitter')))
5
5
 
6
6
  class Twitter
7
7
  include HTTParty
@@ -13,7 +13,7 @@ class Twitter
13
13
 
14
14
  # which can be :friends, :user or :public
15
15
  # options[:query] can be things like since, since_id, count, etc.
16
- def timeline(which=:friends, options={})
16
+ def timeline(which = :friends, options = {})
17
17
  options.merge!({basic_auth: @auth})
18
18
  self.class.get("/statuses/#{which}_timeline.json", options)
19
19
  end
@@ -7,4 +7,4 @@ class Rep
7
7
  end
8
8
 
9
9
  pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
10
- pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: {zip: 46544})
10
+ pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: {zip: 46544})
@@ -1,7 +1,90 @@
1
+ @command_line
1
2
  Feature: Command Line
2
3
 
3
4
  As a developer
4
5
  I want to be able to harness the power of HTTParty from the command line
5
6
  Because that would make quick testing and debugging easy
6
- And 'easy' is my middle name
7
- And I'm kidding it's actually 'Danger'!
7
+
8
+ Scenario: Show help information
9
+ When I run `httparty --help`
10
+ Then the output should contain "-f, --format [FORMAT]"
11
+
12
+ Scenario: Make a get request
13
+ Given a remote deflate service on port '4001'
14
+ And the response from the service has a body of 'GET request'
15
+ And that service is accessed at the path '/fun'
16
+ When I run `httparty http://0.0.0.0:4001/fun`
17
+ Then the output should contain "GET request"
18
+
19
+ Scenario: Make a post request
20
+ Given a remote deflate service on port '4002'
21
+ And the response from the service has a body of 'POST request'
22
+ And that service is accessed at the path '/fun'
23
+ When I run `httparty http://0.0.0.0:4002/fun --action post --data "a=1&b=2"`
24
+ Then the output should contain "POST request"
25
+
26
+ Scenario: Make a put request
27
+ Given a remote deflate service on port '4003'
28
+ And the response from the service has a body of 'PUT request'
29
+ And that service is accessed at the path '/fun'
30
+ When I run `httparty http://0.0.0.0:4003/fun --action put --data "a=1&b=2"`
31
+ Then the output should contain "PUT request"
32
+
33
+ Scenario: Make a delete request
34
+ Given a remote deflate service on port '4004'
35
+ And the response from the service has a body of 'DELETE request'
36
+ And that service is accessed at the path '/fun'
37
+ When I run `httparty http://0.0.0.0:4004/fun --action delete`
38
+ Then the output should contain "DELETE request"
39
+
40
+ Scenario: Set a verbose mode
41
+ Given a remote deflate service on port '4005'
42
+ And the response from the service has a body of 'Some request'
43
+ And that service is accessed at the path '/fun'
44
+ When I run `httparty http://0.0.0.0:4005/fun --verbose`
45
+ Then the output should contain "content-length"
46
+
47
+ Scenario: Use service with basic authentication
48
+ Given a remote deflate service on port '4006'
49
+ And the response from the service has a body of 'Successfull authentication'
50
+ And that service is accessed at the path '/fun'
51
+ And that service is protected by Basic Authentication
52
+ And that service requires the username 'user' with the password 'pass'
53
+ When I run `httparty http://0.0.0.0:4006/fun --user 'user:pass'`
54
+ Then the output should contain "Successfull authentication"
55
+
56
+ Scenario: Get response in plain format
57
+ Given a remote deflate service on port '4007'
58
+ And the response from the service has a body of 'Some request'
59
+ And that service is accessed at the path '/fun'
60
+ When I run `httparty http://0.0.0.0:4007/fun --format plain`
61
+ Then the output should contain "Some request"
62
+
63
+ Scenario: Get response in json format
64
+ Given a remote deflate service on port '4008'
65
+ Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
66
+ And that service is accessed at the path '/service.json'
67
+ And the response from the service has a Content-Type of 'application/json'
68
+ When I run `httparty http://0.0.0.0:4008/service.json --format json`
69
+ Then the output should contain '"jennings": "waylon"'
70
+
71
+ Scenario: Get response in xml format
72
+ Given a remote deflate service on port '4009'
73
+ Given a remote service that returns '<singer>waylon jennings</singer>'
74
+ And that service is accessed at the path '/service.xml'
75
+ And the response from the service has a Content-Type of 'text/xml'
76
+ When I run `httparty http://0.0.0.0:4009/service.xml --format xml`
77
+ Then the output should contain "<singer>"
78
+
79
+ Scenario: Get response in csv format
80
+ Given a remote deflate service on port '4010'
81
+ Given a remote service that returns:
82
+ """
83
+ "Last Name","Name"
84
+ "jennings","waylon"
85
+ "cash","johnny"
86
+ """
87
+ And that service is accessed at the path '/service.csv'
88
+ And the response from the service has a Content-Type of 'application/csv'
89
+ When I run `httparty http://0.0.0.0:4010/service.csv --format csv`
90
+ Then the output should contain '["Last Name", "Name"]'
@@ -1,22 +1,27 @@
1
1
  require 'mongrel'
2
2
  require './lib/httparty'
3
- require 'spec/expectations'
3
+ require 'rspec/expectations'
4
+ require 'aruba/cucumber'
4
5
 
5
- Before do
6
- def new_port
7
- server = TCPServer.new('0.0.0.0', nil)
8
- port = server.addr[1]
9
- ensure
10
- server.close
11
- end
12
-
13
- port = ENV["HTTPARTY_PORT"] || new_port
6
+ def run_server(port)
14
7
  @host_and_port = "0.0.0.0:#{port}"
15
8
  @server = Mongrel::HttpServer.new("0.0.0.0", port)
16
9
  @server.run
17
10
  @request_options = {}
18
11
  end
19
12
 
13
+ def new_port
14
+ server = TCPServer.new('0.0.0.0', nil)
15
+ port = server.addr[1]
16
+ ensure
17
+ server.close
18
+ end
19
+
20
+ Before('~@command_line') do
21
+ port = ENV["HTTPARTY_PORT"] || new_port
22
+ run_server(port)
23
+ end
24
+
20
25
  After do
21
- @server.stop
26
+ @server.stop if @server
22
27
  end
@@ -12,41 +12,41 @@ def constantize(camel_cased_word)
12
12
  end
13
13
 
14
14
  Then /it should return an? (\w+)$/ do |class_string|
15
- @response_from_httparty.should be_an_instance_of(class_string.class)
15
+ expect(@response_from_httparty).to be_a(class_string.class)
16
16
  end
17
17
 
18
18
  Then /the return value should match '(.*)'/ do |expected_text|
19
- @response_from_httparty.should eql(expected_text)
19
+ expect(@response_from_httparty.parsed_response).to eq(expected_text)
20
20
  end
21
21
 
22
22
  Then /it should return a Hash equaling:/ do |hash_table|
23
- @response_from_httparty.should be_an_instance_of(Hash)
24
- @response_from_httparty.keys.length.should eql(hash_table.rows.length)
23
+ expect(@response_from_httparty).to be_a(Hash)
24
+ expect(@response_from_httparty.keys.length).to eq(hash_table.rows.length)
25
25
  hash_table.hashes.each do |pair|
26
26
  key, value = pair["key"], pair["value"]
27
- @response_from_httparty.keys.should include(key)
28
- @response_from_httparty[key].should eql(value)
27
+ expect(@response_from_httparty.keys).to include(key)
28
+ expect(@response_from_httparty[key]).to eq(value)
29
29
  end
30
30
  end
31
31
 
32
32
  Then /it should return an Array equaling:/ do |array|
33
- @response_from_httparty.should be_an_instance_of(Array)
34
- @response_from_httparty.should eql array.raw
33
+ expect(@response_from_httparty).to be_a(Array)
34
+ expect(@response_from_httparty.parsed_response).to eq(array.raw)
35
35
  end
36
36
 
37
37
  Then /it should return a response with a (\d+) response code/ do |code|
38
- @response_from_httparty.code.should eql(code.to_i)
38
+ expect(@response_from_httparty.code).to eq(code.to_i)
39
39
  end
40
40
 
41
41
  Then /it should return a response with a (.*) content\-encoding$/ do |content_type|
42
- @response_from_httparty.headers['content-encoding'].should eql('gzip')
42
+ expect(@response_from_httparty.headers['content-encoding']).to eq('gzip')
43
43
  end
44
44
 
45
45
  Then /it should return a response with a blank body$/ do
46
- @response_from_httparty.body.should be(nil)
46
+ expect(@response_from_httparty.body).to be_nil
47
47
  end
48
48
 
49
49
  Then /it should raise (?:an|a) ([\w:]+) exception/ do |exception|
50
- @exception_from_httparty.should_not be_nil
51
- @exception_from_httparty.should be_a constantize(exception)
50
+ expect(@exception_from_httparty).to_not be_nil
51
+ expect(@exception_from_httparty).to be_a constantize(exception)
52
52
  end
@@ -10,14 +10,14 @@ class BasicMongrelHandler < Mongrel::HttpHandler
10
10
  end
11
11
 
12
12
  def process(request, response)
13
- instance_eval &preprocessor if preprocessor
13
+ instance_eval(&preprocessor) if preprocessor
14
14
  reply_with(response, response_code, response_body)
15
15
  end
16
16
 
17
17
  def reply_with(response, code, response_body)
18
18
  response.start(code) do |head, body|
19
19
  head["Content-Type"] = content_type
20
- custom_headers.each { |k,v| head[k] = v }
20
+ custom_headers.each { |k, v| head[k] = v }
21
21
  body.write(response_body)
22
22
  end
23
23
  end
@@ -1,6 +1,6 @@
1
1
  Given /a remote service that returns '(.*)'/ do |response_body|
2
2
  @handler = BasicMongrelHandler.new
3
- Given "the response from the service has a body of '#{response_body}'"
3
+ step "the response from the service has a body of '#{response_body}'"
4
4
  end
5
5
 
6
6
  Given /^a remote service that returns:$/ do |response_body|
@@ -19,13 +19,18 @@ end
19
19
 
20
20
  Given /^that service takes (\d+) seconds to generate a response$/ do |time|
21
21
  @server_response_time = time.to_i
22
- @handler.preprocessor = Proc.new { sleep time.to_i }
22
+ @handler.preprocessor = proc { sleep time.to_i }
23
23
  end
24
24
 
25
25
  Given /^a remote deflate service$/ do
26
26
  @handler = DeflateHandler.new
27
27
  end
28
28
 
29
+ Given /^a remote deflate service on port '(\d+)'/ do |port|
30
+ run_server(port)
31
+ @handler = DeflateHandler.new
32
+ end
33
+
29
34
  Given /^a remote gzip service$/ do
30
35
  @handler = GzipHandler.new
31
36
  end
@@ -55,11 +60,18 @@ Given /that service requires the username '(.*)' with the password '(.*)'/ do |u
55
60
  @handler.password = password
56
61
  end
57
62
 
63
+ # customize aruba cucumber step
64
+ Then /^the output should contain '(.*)'$/ do |expected|
65
+ assert_partial_output(expected, all_output)
66
+ end
67
+
58
68
  Given /a restricted page at '(.*)'/ do |url|
59
- Given "a remote service that returns 'A response I will never see'"
60
- And "that service is accessed at the path '#{url}'"
61
- And "that service is protected by Basic Authentication"
62
- And "that service requires the username 'something' with the password 'secret'"
69
+ steps "
70
+ Given a remote service that returns 'A response I will never see'
71
+ And that service is accessed at the path '#{url}'
72
+ And that service is protected by Basic Authentication
73
+ And that service requires the username 'something' with the password 'secret'
74
+ "
63
75
  end
64
76
 
65
77
  # This joins the server thread, and halts cucumber, so you can actually hit the
@@ -1,5 +1,5 @@
1
1
  # -*- encoding: utf-8 -*-
2
- $:.push File.expand_path("../lib", __FILE__)
2
+ $LOAD_PATH.push File.expand_path("../lib", __FILE__)
3
3
  require "httparty/version"
4
4
 
5
5
  Gem::Specification.new do |s|
@@ -10,8 +10,8 @@ Gem::Specification.new do |s|
10
10
  s.authors = ["John Nunemaker", "Sandro Turriate"]
11
11
  s.email = ["nunemaker@gmail.com"]
12
12
  s.homepage = "http://jnunemaker.github.com/httparty"
13
- s.summary = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
14
- s.description = %q{Makes http fun! Also, makes consuming restful web services dead easy.}
13
+ s.summary = 'Makes http fun! Also, makes consuming restful web services dead easy.'
14
+ s.description = 'Makes http fun! Also, makes consuming restful web services dead easy.'
15
15
 
16
16
  s.required_ruby_version = '>= 1.9.3'
17
17
 
@@ -23,6 +23,6 @@ Gem::Specification.new do |s|
23
23
 
24
24
  s.files = `git ls-files`.split("\n")
25
25
  s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
26
- s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
26
+ s.executables = `git ls-files -- bin/*`.split("\n").map { |f| File.basename(f) }
27
27
  s.require_paths = ["lib"]
28
28
  end
@@ -16,22 +16,9 @@ require 'httparty/logger/logger'
16
16
 
17
17
  # @see HTTParty::ClassMethods
18
18
  module HTTParty
19
- module AllowedFormatsDeprecation
20
- def const_missing(const)
21
- if const.to_s =~ /AllowedFormats$/
22
- Kernel.warn("Deprecated: Use HTTParty::Parser::SupportedFormats")
23
- HTTParty::Parser::SupportedFormats
24
- else
25
- super
26
- end
27
- end
28
- end
29
-
30
- extend AllowedFormatsDeprecation
31
-
32
19
  def self.included(base)
33
20
  base.extend ClassMethods
34
- base.send :include, HTTParty::ModuleInheritableAttributes
21
+ base.send :include, ModuleInheritableAttributes
35
22
  base.send(:mattr_inheritable, :default_options)
36
23
  base.send(:mattr_inheritable, :default_cookies)
37
24
  base.instance_variable_set("@default_options", {})
@@ -69,16 +56,13 @@ module HTTParty
69
56
  # * :+ssl_ca_path+: see HTTParty::ClassMethods.ssl_ca_path.
70
57
 
71
58
  module ClassMethods
72
-
73
- extend AllowedFormatsDeprecation
74
-
75
59
  # Turns on logging
76
60
  #
77
61
  # class Foo
78
62
  # include HTTParty
79
63
  # logger Logger.new('http_logger'), :info, :apache
80
64
  # end
81
- def logger(logger, level=:info, format=:apache)
65
+ def logger(logger, level = :info, format = :apache)
82
66
  default_options[:logger] = logger
83
67
  default_options[:log_level] = level
84
68
  default_options[:log_format] = format
@@ -90,7 +74,7 @@ module HTTParty
90
74
  # include HTTParty
91
75
  # http_proxy 'http://foo.com', 80, 'user', 'pass'
92
76
  # end
93
- def http_proxy(addr=nil, port=nil, user=nil, pass=nil)
77
+ def http_proxy(addr = nil, port = nil, user = nil, pass = nil)
94
78
  default_options[:http_proxyaddr] = addr
95
79
  default_options[:http_proxyport] = port
96
80
  default_options[:http_proxyuser] = user
@@ -104,7 +88,7 @@ module HTTParty
104
88
  # include HTTParty
105
89
  # base_uri 'twitter.com'
106
90
  # end
107
- def base_uri(uri=nil)
91
+ def base_uri(uri = nil)
108
92
  return default_options[:base_uri] unless uri
109
93
  default_options[:base_uri] = HTTParty.normalize_base_uri(uri)
110
94
  end
@@ -158,7 +142,7 @@ module HTTParty
158
142
  # include HTTParty
159
143
  # default_params api_key: 'secret', another: 'foo'
160
144
  # end
161
- def default_params(h={})
145
+ def default_params(h = {})
162
146
  raise ArgumentError, 'Default params must an object which respond to #to_hash' unless h.respond_to?(:to_hash)
163
147
  default_options[:default_params] ||= {}
164
148
  default_options[:default_params].merge!(h)
@@ -215,13 +199,13 @@ module HTTParty
215
199
  # include HTTParty
216
200
  # headers 'Accept' => 'text/html'
217
201
  # end
218
- def headers(h={})
202
+ def headers(h = {})
219
203
  raise ArgumentError, 'Headers must an object which responds to #to_hash' unless h.respond_to?(:to_hash)
220
204
  default_options[:headers] ||= {}
221
205
  default_options[:headers].merge!(h.to_hash)
222
206
  end
223
207
 
224
- def cookies(h={})
208
+ def cookies(h = {})
225
209
  raise ArgumentError, 'Cookies must an object which respond to #to_hash' unless h.respond_to?(:to_hash)
226
210
  default_cookies.add_cookies(h)
227
211
  end
@@ -318,7 +302,7 @@ module HTTParty
318
302
  # include HTTParty
319
303
  # pem File.read('/home/user/my.pem'), "optional password"
320
304
  # end
321
- def pem(pem_contents, password=nil)
305
+ def pem(pem_contents, password = nil)
322
306
  default_options[:pem] = pem_contents
323
307
  default_options[:pem_password] = password
324
308
  end
@@ -471,7 +455,7 @@ module HTTParty
471
455
  # # Simple get with full url and query parameters
472
456
  # # ie: http://foo.com/resource.json?limit=10
473
457
  # Foo.get('http://foo.com/resource.json', query: {limit: 10})
474
- def get(path, options={}, &block)
458
+ def get(path, options = {}, &block)
475
459
  perform_request Net::HTTP::Get, path, options, &block
476
460
  end
477
461
 
@@ -487,75 +471,73 @@ module HTTParty
487
471
  # # Simple post with full url using :query option,
488
472
  # # which gets set as form data on the request.
489
473
  # Foo.post('http://foo.com/resources', query: {bar: 'baz'})
490
- def post(path, options={}, &block)
474
+ def post(path, options = {}, &block)
491
475
  perform_request Net::HTTP::Post, path, options, &block
492
476
  end
493
477
 
494
478
  # Perform a PATCH request to a path
495
- def patch(path, options={}, &block)
479
+ def patch(path, options = {}, &block)
496
480
  perform_request Net::HTTP::Patch, path, options, &block
497
481
  end
498
482
 
499
483
  # Perform a PUT request to a path
500
- def put(path, options={}, &block)
484
+ def put(path, options = {}, &block)
501
485
  perform_request Net::HTTP::Put, path, options, &block
502
486
  end
503
487
 
504
488
  # Perform a DELETE request to a path
505
- def delete(path, options={}, &block)
489
+ def delete(path, options = {}, &block)
506
490
  perform_request Net::HTTP::Delete, path, options, &block
507
491
  end
508
492
 
509
493
  # Perform a MOVE request to a path
510
- def move(path, options={}, &block)
494
+ def move(path, options = {}, &block)
511
495
  perform_request Net::HTTP::Move, path, options, &block
512
496
  end
513
497
 
514
498
  # Perform a COPY request to a path
515
- def copy(path, options={}, &block)
499
+ def copy(path, options = {}, &block)
516
500
  perform_request Net::HTTP::Copy, path, options, &block
517
501
  end
518
502
 
519
503
  # Perform a HEAD request to a path
520
- def head(path, options={}, &block)
504
+ def head(path, options = {}, &block)
521
505
  perform_request Net::HTTP::Head, path, options, &block
522
506
  end
523
507
 
524
508
  # Perform an OPTIONS request to a path
525
- def options(path, options={}, &block)
509
+ def options(path, options = {}, &block)
526
510
  perform_request Net::HTTP::Options, path, options, &block
527
511
  end
528
512
 
529
- def default_options #:nodoc:
530
- @default_options
531
- end
513
+ attr_reader :default_options
532
514
 
533
515
  private
534
516
 
535
- def perform_request(http_method, path, options, &block) #:nodoc:
536
- options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
537
- process_headers(options)
538
- process_cookies(options)
539
- Request.new(http_method, path, options).perform(&block)
540
- end
517
+ def perform_request(http_method, path, options, &block) #:nodoc:
518
+ options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
519
+ process_headers(options)
520
+ process_cookies(options)
521
+ Request.new(http_method, path, options).perform(&block)
522
+ end
541
523
 
542
- def process_headers(options)
543
- if options[:headers] && headers.any?
544
- options[:headers] = headers.merge(options[:headers])
545
- end
524
+ def process_headers(options)
525
+ if options[:headers] && headers.any?
526
+ options[:headers] = headers.merge(options[:headers])
546
527
  end
528
+ end
547
529
 
548
- def process_cookies(options) #:nodoc:
549
- return unless options[:cookies] || default_cookies.any?
550
- options[:headers] ||= headers.dup
551
- options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
552
- end
530
+ def process_cookies(options) #:nodoc:
531
+ return unless options[:cookies] || default_cookies.any?
532
+ options[:headers] ||= headers.dup
533
+ options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
534
+ end
553
535
 
554
- def validate_format
555
- if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format)
556
- raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{parser.supported_formats.map{|f| f.to_s}.sort.join(', ')}"
557
- end
536
+ def validate_format
537
+ if format && parser.respond_to?(:supports_format?) && !parser.supports_format?(format)
538
+ raise UnsupportedFormat, "'#{format.inspect}' Must be one of: #{parser.supported_formats.map(&:to_s).sort.join(', ')}"
558
539
  end
540
+ end
559
541
  end
560
542
 
561
543
  def self.normalize_base_uri(url) #:nodoc:
@@ -610,7 +592,6 @@ module HTTParty
610
592
  end
611
593
  end
612
594
 
613
- require 'httparty/core_extensions'
614
595
  require 'httparty/hash_conversions'
615
596
  require 'httparty/exceptions'
616
597
  require 'httparty/parser'