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.

Files changed (79) hide show
  1. checksums.yaml +7 -0
  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/.travis.yml +5 -4
  7. data/CONTRIBUTING.md +23 -0
  8. data/Gemfile +9 -5
  9. data/Guardfile +3 -3
  10. data/History +109 -8
  11. data/README.md +21 -21
  12. data/Rakefile +5 -10
  13. data/bin/httparty +21 -14
  14. data/docs/README.md +100 -0
  15. data/examples/README.md +67 -0
  16. data/examples/aaws.rb +9 -9
  17. data/examples/basic.rb +6 -10
  18. data/examples/crack.rb +3 -3
  19. data/examples/custom_parsers.rb +1 -4
  20. data/examples/delicious.rb +12 -12
  21. data/examples/google.rb +2 -2
  22. data/examples/headers_and_user_agents.rb +2 -2
  23. data/examples/logging.rb +36 -0
  24. data/examples/nokogiri_html_parser.rb +0 -3
  25. data/examples/rescue_json.rb +17 -0
  26. data/examples/rubyurl.rb +3 -3
  27. data/examples/stackexchange.rb +24 -0
  28. data/examples/tripit_sign_in.rb +20 -9
  29. data/examples/twitter.rb +11 -11
  30. data/examples/whoismyrep.rb +2 -2
  31. data/features/command_line.feature +90 -2
  32. data/features/digest_authentication.feature +10 -0
  33. data/features/handles_compressed_responses.feature +8 -0
  34. data/features/handles_multiple_formats.feature +23 -0
  35. data/features/steps/env.rb +16 -11
  36. data/features/steps/httparty_response_steps.rb +40 -10
  37. data/features/steps/httparty_steps.rb +19 -3
  38. data/features/steps/mongrel_helper.rb +35 -2
  39. data/features/steps/remote_service_steps.rb +31 -8
  40. data/features/supports_read_timeout_option.feature +13 -0
  41. data/httparty.gemspec +9 -6
  42. data/lib/httparty/connection_adapter.rb +76 -11
  43. data/lib/httparty/cookie_hash.rb +3 -4
  44. data/lib/httparty/exceptions.rb +10 -4
  45. data/lib/httparty/hash_conversions.rb +19 -17
  46. data/lib/httparty/logger/apache_formatter.rb +22 -0
  47. data/lib/httparty/logger/curl_formatter.rb +91 -0
  48. data/lib/httparty/logger/logger.rb +26 -0
  49. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  50. data/lib/httparty/net_digest_auth.rb +69 -18
  51. data/lib/httparty/parser.rb +15 -11
  52. data/lib/httparty/request.rb +186 -47
  53. data/lib/httparty/response/headers.rb +2 -2
  54. data/lib/httparty/response.rb +44 -9
  55. data/lib/httparty/version.rb +1 -1
  56. data/lib/httparty.rb +187 -65
  57. data/script/release +42 -0
  58. data/spec/fixtures/twitter.csv +2 -0
  59. data/spec/httparty/connection_adapter_spec.rb +334 -62
  60. data/spec/httparty/cookie_hash_spec.rb +53 -23
  61. data/spec/httparty/exception_spec.rb +45 -0
  62. data/spec/httparty/hash_conversions_spec.rb +49 -0
  63. data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
  64. data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
  65. data/spec/httparty/logger/logger_spec.rb +38 -0
  66. data/spec/httparty/net_digest_auth_spec.rb +148 -23
  67. data/spec/httparty/parser_spec.rb +48 -41
  68. data/spec/httparty/request_spec.rb +845 -151
  69. data/spec/httparty/response_spec.rb +147 -70
  70. data/spec/httparty/ssl_spec.rb +33 -21
  71. data/spec/httparty_spec.rb +337 -186
  72. data/spec/spec_helper.rb +38 -9
  73. data/spec/support/ssl_test_helper.rb +10 -10
  74. data/spec/support/ssl_test_server.rb +21 -21
  75. data/spec/support/stub_response.rb +20 -14
  76. data/website/index.html +3 -3
  77. metadata +46 -37
  78. data/lib/httparty/core_extensions.rb +0 -32
  79. data/spec/spec.opts +0 -2
data/docs/README.md ADDED
@@ -0,0 +1,100 @@
1
+ # httparty
2
+
3
+ Makes http fun again!
4
+
5
+ ## Table of contents
6
+ - [Working with SSL](#working-with-ssl)
7
+
8
+ ## Working with SSL
9
+
10
+ You can use this guide to work with SSL certificates.
11
+
12
+ #### Using `pem` option
13
+
14
+ ```ruby
15
+ # Use this example if you are using a pem file
16
+
17
+ class Client
18
+ include HTTParty
19
+
20
+ base_uri "https://example.com"
21
+ pem File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456"
22
+
23
+ end
24
+ ```
25
+
26
+ #### Using `pkcs12` option
27
+
28
+ ```ruby
29
+ # Use this example if you are using a pkcs12 file
30
+
31
+ class Client
32
+ include HTTParty
33
+
34
+ base_uri "https://example.com"
35
+ pkcs12 File.read("#{File.expand_path('.')}/path/to/certs/cert.p12"), "123456"
36
+
37
+ end
38
+ ```
39
+
40
+ #### Using `ssl_ca_file` option
41
+
42
+ ```ruby
43
+ # Use this example if you are using a pkcs12 file
44
+
45
+ class Client
46
+ include HTTParty
47
+
48
+ base_uri "https://example.com"
49
+ ssl_ca_file "#{File.expand_path('.')}/path/to/certs/cert.pem"
50
+
51
+ end
52
+ ```
53
+
54
+ #### Using `ssl_ca_path` option
55
+
56
+ ```ruby
57
+ # Use this example if you are using a pkcs12 file
58
+
59
+ class Client
60
+ include HTTParty
61
+
62
+ base_uri "https://example.com"
63
+ ssl_ca_path '/path/to/certs'
64
+ end
65
+ ```
66
+
67
+ You can also include this options with the call:
68
+
69
+ ```ruby
70
+ class Client
71
+ include HTTParty
72
+
73
+ base_uri "https://example.com"
74
+
75
+ def self.fetch
76
+ get("/resources", pem: (File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456")
77
+ end
78
+ end
79
+ ```
80
+
81
+ ### Avoid SSL verification
82
+
83
+ In some cases you may want to skip SSL verification, because the entity that issue the certificate is not a valid one, but you still want to work with it. You can achieve this through:
84
+
85
+ ```ruby
86
+ #Skips SSL certificate verification
87
+
88
+ class Client
89
+ include HTTParty
90
+
91
+ base_uri "https://example.com"
92
+ pem File.read("#{File.expand_path('.')}/path/to/certs/cert.pem"), "123456"
93
+
94
+ def self.fetch
95
+ get("/resources", verify: false)
96
+ # You can also use something like:
97
+ # get("resources", verify_peer: false)
98
+ end
99
+ end
100
+ ```
@@ -0,0 +1,67 @@
1
+ ## Examples
2
+
3
+ * [Amazon Book Search](aaws.rb)
4
+ * Httparty included into poro class
5
+ * Uses `get` requests
6
+ * Transforms query params to uppercased params
7
+
8
+ * [Google Search](google.rb)
9
+ * Httparty included into poro class
10
+ * Uses `get` requests
11
+
12
+ * [Crack Custom Parser](crack.rb)
13
+ * Creates a custom parser for XML using crack gem
14
+ * Uses `get` request
15
+
16
+ * [Create HTML Nokogiri parser](nokogiri_html_parser.rb)
17
+ * Adds Html as a format
18
+ * passed the body of request to Nokogiri
19
+
20
+ * [More Custom Parsers](custom_parsers.rb)
21
+ * Create an additional parser for atom or make it the ONLY parser
22
+
23
+ * [Basic Auth, Delicious](delicious.rb)
24
+ * Basic Auth, shows how to merge those into options
25
+ * Uses `get` requests
26
+
27
+ * [Passing Headers, User Agent](headers_and_user_agents.rb)
28
+ * Use the class method of Httparty
29
+ * Pass the User-Agent in the headers
30
+ * Uses `get` requests
31
+
32
+ * [Basic Post Request](basic.rb)
33
+ * Httparty included into poro class
34
+ * Uses `post` requests
35
+
36
+ * [Access Rubyurl Shortener](rubyurl.rb)
37
+ * Httparty included into poro class
38
+ * Uses `post` requests
39
+
40
+ * [Add a custom log file](logging.rb)
41
+ * create a log file and have httparty log requests
42
+
43
+ * [Accessing StackExchange](stackexchange.rb)
44
+ * Httparty included into poro class
45
+ * Creates methods for different endpoints
46
+ * Uses `get` requests
47
+
48
+ * [Accessing Tripit](tripit_sign_in.rb)
49
+ * Httparty included into poro class
50
+ * Example of using `debug_output` to see headers/urls passed
51
+ * Getting and using Cookies
52
+ * Uses `get` requests
53
+
54
+ * [Accessing Twitter](twitter.rb)
55
+ * Httparty included into poro class
56
+ * Basic Auth
57
+ * Loads settings from a config file
58
+ * Uses `get` requests
59
+ * Uses `post` requests
60
+
61
+ * [Accessing WhoIsMyRep](whoismyrep.rb)
62
+ * Httparty included into poro class
63
+ * Uses `get` requests
64
+ * Two ways to pass params to get, inline on the url or in query hash
65
+
66
+ * [Rescue Json Error](rescue_json.rb)
67
+ * Rescue errors due to parsing response
data/examples/aaws.rb CHANGED
@@ -4,24 +4,24 @@ require 'active_support'
4
4
  dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
5
5
  require File.join(dir, 'httparty')
6
6
  require 'pp'
7
- config = YAML::load(File.read(File.join(ENV['HOME'], '.aaws')))
7
+ config = YAML.load(File.read(File.join(ENV['HOME'], '.aaws')))
8
8
 
9
9
  module AAWS
10
10
  class Book
11
11
  include HTTParty
12
12
  base_uri 'http://ecs.amazonaws.com'
13
- default_params :Service => 'AWSECommerceService', :Operation => 'ItemSearch', :SearchIndex => 'Books'
14
-
13
+ default_params Service: 'AWSECommerceService', Operation: 'ItemSearch', SearchIndex: 'Books'
14
+
15
15
  def initialize(key)
16
- self.class.default_params :AWSAccessKeyId => key
16
+ self.class.default_params AWSAccessKeyId: key
17
17
  end
18
-
19
- def search(options={})
18
+
19
+ def search(options = {})
20
20
  raise ArgumentError, 'You must search for something' if options[:query].blank?
21
-
21
+
22
22
  # amazon uses nasty camelized query params
23
23
  options[:query] = options[:query].inject({}) { |h, q| h[q[0].to_s.camelize] = q[1]; h }
24
-
24
+
25
25
  # make a request and return the items (NOTE: this doesn't handle errors at this point)
26
26
  self.class.get('/onca/xml', options)['ItemSearchResponse']['Items']
27
27
  end
@@ -29,4 +29,4 @@ module AAWS
29
29
  end
30
30
 
31
31
  aaws = AAWS::Book.new(config[:access_key])
32
- pp aaws.search(:query => {:title => 'Ruby On Rails'})
32
+ pp aaws.search(query: {title: 'Ruby On Rails'})
data/examples/basic.rb CHANGED
@@ -3,13 +3,9 @@ require File.join(dir, 'httparty')
3
3
  require 'pp'
4
4
 
5
5
  # You can also use post, put, delete, head, options in the same fashion
6
- response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
6
+ response = HTTParty.get('https://api.stackexchange.com/2.2/questions?site=stackoverflow')
7
7
  puts response.body, response.code, response.message, response.headers.inspect
8
8
 
9
- response.each do |item|
10
- puts item['user']['screen_name']
11
- end
12
-
13
9
  # An example post to a minimal rails app in the development environment
14
10
  # Note that "skip_before_filter :verify_authenticity_token" must be set in the
15
11
  # "pears" controller for this example
@@ -20,11 +16,11 @@ class Partay
20
16
  end
21
17
 
22
18
  options = {
23
- :body => {
24
- :pear => { # your resource
25
- :foo => '123', # your columns/data
26
- :bar => 'second',
27
- :baz => 'last thing'
19
+ body: {
20
+ pear: { # your resource
21
+ foo: '123', # your columns/data
22
+ bar: 'second',
23
+ baz: 'last thing'
28
24
  }
29
25
  }
30
26
  }
data/examples/crack.rb CHANGED
@@ -9,11 +9,11 @@ class Rep
9
9
  include HTTParty
10
10
 
11
11
  parser(
12
- Proc.new do |body, format|
12
+ proc do |body, format|
13
13
  Crack::XML.parse(body)
14
14
  end
15
15
  )
16
16
  end
17
17
 
18
- pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
19
- pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})
18
+ pp Rep.get('http://whoismyrepresentative.com/getall_mems.php?zip=46544')
19
+ pp Rep.get('http://whoismyrepresentative.com/getall_mems.php', query: {zip: 46544})
@@ -16,7 +16,6 @@ class ParseAtom
16
16
  parser Parser::Atom
17
17
  end
18
18
 
19
-
20
19
  class OnlyParseAtom
21
20
  include HTTParty
22
21
 
@@ -35,7 +34,6 @@ class OnlyParseAtom
35
34
  parser Parser::OnlyAtom
36
35
  end
37
36
 
38
-
39
37
  class SkipParsing
40
38
  include HTTParty
41
39
 
@@ -49,11 +47,10 @@ class SkipParsing
49
47
  parser Parser::Simple
50
48
  end
51
49
 
52
-
53
50
  class AdHocParsing
54
51
  include HTTParty
55
52
  parser(
56
- Proc.new do |body, format|
53
+ proc do |body, format|
57
54
  case format
58
55
  when :json
59
56
  body.to_json
@@ -1,37 +1,37 @@
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'], '.delicious')))
4
+ config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
5
5
 
6
6
  class Delicious
7
7
  include HTTParty
8
8
  base_uri 'https://api.del.icio.us/v1'
9
-
9
+
10
10
  def initialize(u, p)
11
- @auth = {:username => u, :password => p}
11
+ @auth = {username: u, password: p}
12
12
  end
13
-
13
+
14
14
  # query params that filter the posts are:
15
15
  # tag (optional). Filter by this tag.
16
16
  # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
17
17
  # url (optional). Filter by this url.
18
- # ie: posts(:query => {:tag => 'ruby'})
19
- def posts(options={})
20
- options.merge!({:basic_auth => @auth})
18
+ # ie: posts(query: {tag: 'ruby'})
19
+ def posts(options = {})
20
+ options.merge!({basic_auth: @auth})
21
21
  self.class.get('/posts/get', options)
22
22
  end
23
-
23
+
24
24
  # query params that filter the posts are:
25
25
  # tag (optional). Filter by this tag.
26
26
  # count (optional). Number of items to retrieve (Default:15, Maximum:100).
27
- def recent(options={})
28
- options.merge!({:basic_auth => @auth})
27
+ def recent(options = {})
28
+ options.merge!({basic_auth: @auth})
29
29
  self.class.get('/posts/recent', options)
30
30
  end
31
31
  end
32
32
 
33
33
  delicious = Delicious.new(config['username'], config['password'])
34
- pp delicious.posts(:query => {:tag => 'ruby'})
34
+ pp delicious.posts(query: {tag: 'ruby'})
35
35
  pp delicious.recent
36
36
 
37
- delicious.recent['posts']['post'].each { |post| puts post['href'] }
37
+ delicious.recent['posts']['post'].each { |post| puts post['href'] }
data/examples/google.rb CHANGED
@@ -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')
@@ -2,5 +2,5 @@
2
2
 
3
3
  require 'httparty'
4
4
 
5
- APPLICATION_NAME = "Httparty"
6
- response = HTTParty.get('http://example.com', :headers => {"User-Agent" => APPLICATION_NAME})
5
+ APPLICATION_NAME = "Httparty"
6
+ response = HTTParty.get('http://example.com', headers: {"User-Agent" => APPLICATION_NAME})
@@ -0,0 +1,36 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+ require 'logger'
4
+ require 'pp'
5
+
6
+ my_logger = Logger.new "httparty.log"
7
+
8
+ my_logger.info "Logging can be used on the main HTTParty class. It logs redirects too."
9
+ HTTParty.get "http://google.com", logger: my_logger
10
+
11
+ my_logger.info '*' * 70
12
+
13
+ my_logger.info "It can be used also on a custom class."
14
+
15
+ class Google
16
+ include HTTParty
17
+ logger ::Logger.new "httparty.log"
18
+ end
19
+
20
+ Google.get "http://google.com"
21
+
22
+ my_logger.info '*' * 70
23
+
24
+ my_logger.info "The default formatter is :apache. The :curl formatter can also be used."
25
+ my_logger.info "You can tell wich method to call on the logger too. It is info by default."
26
+ HTTParty.get "http://google.com", logger: my_logger, log_level: :debug, log_format: :curl
27
+
28
+ my_logger.info '*' * 70
29
+
30
+ my_logger.info "These configs are also available on custom classes."
31
+ class Google
32
+ include HTTParty
33
+ logger ::Logger.new("httparty.log"), :debug, :curl
34
+ end
35
+
36
+ Google.get "http://google.com"
@@ -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
data/examples/rubyurl.rb CHANGED
@@ -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/')
@@ -0,0 +1,24 @@
1
+ dir = File.expand_path(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require File.join(dir, 'httparty')
3
+ require 'pp'
4
+
5
+ class StackExchange
6
+ include HTTParty
7
+ base_uri 'api.stackexchange.com'
8
+
9
+ def initialize(service, page)
10
+ @options = { query: {site: service, page: page} }
11
+ end
12
+
13
+ def questions
14
+ self.class.get("/2.2/questions", @options)
15
+ end
16
+
17
+ def users
18
+ self.class.get("/2.2/users", @options)
19
+ end
20
+ end
21
+
22
+ stack_exchange = StackExchange.new("stackoverflow", 1)
23
+ pp stack_exchange.questions
24
+ pp stack_exchange.users
@@ -3,30 +3,41 @@ require File.join(dir, 'httparty')
3
3
 
4
4
  class TripIt
5
5
  include HTTParty
6
- base_uri 'http://www.tripit.com'
6
+ base_uri 'https://www.tripit.com'
7
7
  debug_output
8
8
 
9
9
  def initialize(email, password)
10
10
  @email = email
11
- response = self.class.get('/account/login')
12
- response = self.class.post(
11
+ get_response = self.class.get('/account/login')
12
+ get_response_cookie = parse_cookie(get_response.headers['Set-Cookie'])
13
+
14
+ post_response = self.class.post(
13
15
  '/account/login',
14
- :body => {
15
- :login_email_address => email,
16
- :login_password => password
16
+ body: {
17
+ login_email_address: email,
18
+ login_password: password
17
19
  },
18
- :headers => {'Cookie' => response.headers['Set-Cookie']}
20
+ headers: {'Cookie' => get_response_cookie.to_cookie_string }
19
21
  )
20
- @cookie = response.request.options[:headers]['Cookie']
22
+
23
+ @cookie = parse_cookie(post_response.headers['Set-Cookie'])
21
24
  end
22
25
 
23
26
  def account_settings
24
- self.class.get('/account/edit', :headers => {'Cookie' => @cookie})
27
+ self.class.get('/account/edit', headers: {'Cookie' => @cookie.to_cookie_string})
25
28
  end
26
29
 
27
30
  def logged_in?
28
31
  account_settings.include? "You're logged in as #{@email}"
29
32
  end
33
+
34
+ private
35
+
36
+ def parse_cookie(resp)
37
+ cookie_hash = CookieHash.new
38
+ resp.get_fields('Set-Cookie').each { |c| cookie_hash.add_cookies(c) }
39
+ cookie_hash
40
+ end
30
41
  end
31
42
 
32
43
  tripit = TripIt.new('email', 'password')
data/examples/twitter.rb CHANGED
@@ -1,31 +1,31 @@
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
8
8
  base_uri 'twitter.com'
9
-
9
+
10
10
  def initialize(u, p)
11
- @auth = {:username => u, :password => p}
11
+ @auth = {username: u, password: p}
12
12
  end
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={})
17
- options.merge!({:basic_auth => @auth})
16
+ def timeline(which = :friends, options = {})
17
+ options.merge!({basic_auth: @auth})
18
18
  self.class.get("/statuses/#{which}_timeline.json", options)
19
19
  end
20
-
20
+
21
21
  def post(text)
22
- options = { :query => {:status => text}, :basic_auth => @auth }
22
+ options = { query: {status: text}, basic_auth: @auth }
23
23
  self.class.post('/statuses/update.json', options)
24
24
  end
25
25
  end
26
26
 
27
27
  twitter = Twitter.new(config['email'], config['password'])
28
28
  pp twitter.timeline
29
- # pp twitter.timeline(:friends, :query => {:since_id => 868482746})
30
- # pp twitter.timeline(:friends, :query => 'since_id=868482746')
31
- # pp twitter.post('this is a test of 0.2.0')
29
+ # pp twitter.timeline(:friends, query: {since_id: 868482746})
30
+ # pp twitter.timeline(:friends, query: 'since_id=868482746')
31
+ # pp twitter.post('this is a test of 0.2.0')
@@ -6,5 +6,5 @@ class Rep
6
6
  include HTTParty
7
7
  end
8
8
 
9
- pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php?zip=46544')
10
- pp Rep.get('http://whoismyrepresentative.com/whoismyrep.php', :query => {:zip => 46544})
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})
@@ -1,7 +1,95 @@
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: Show current version
13
+ When I run `httparty --version`
14
+ Then the output should contain "Version:"
15
+ And the output should not contain "You need to provide a URL"
16
+
17
+ Scenario: Make a get request
18
+ Given a remote deflate service on port '4001'
19
+ And the response from the service has a body of 'GET request'
20
+ And that service is accessed at the path '/fun'
21
+ When I run `httparty http://0.0.0.0:4001/fun`
22
+ Then the output should contain "GET request"
23
+
24
+ Scenario: Make a post request
25
+ Given a remote deflate service on port '4002'
26
+ And the response from the service has a body of 'POST request'
27
+ And that service is accessed at the path '/fun'
28
+ When I run `httparty http://0.0.0.0:4002/fun --action post --data "a=1&b=2"`
29
+ Then the output should contain "POST request"
30
+
31
+ Scenario: Make a put request
32
+ Given a remote deflate service on port '4003'
33
+ And the response from the service has a body of 'PUT request'
34
+ And that service is accessed at the path '/fun'
35
+ When I run `httparty http://0.0.0.0:4003/fun --action put --data "a=1&b=2"`
36
+ Then the output should contain "PUT request"
37
+
38
+ Scenario: Make a delete request
39
+ Given a remote deflate service on port '4004'
40
+ And the response from the service has a body of 'DELETE request'
41
+ And that service is accessed at the path '/fun'
42
+ When I run `httparty http://0.0.0.0:4004/fun --action delete`
43
+ Then the output should contain "DELETE request"
44
+
45
+ Scenario: Set a verbose mode
46
+ Given a remote deflate service on port '4005'
47
+ And the response from the service has a body of 'Some request'
48
+ And that service is accessed at the path '/fun'
49
+ When I run `httparty http://0.0.0.0:4005/fun --verbose`
50
+ Then the output should contain "content-length"
51
+
52
+ Scenario: Use service with basic authentication
53
+ Given a remote deflate service on port '4006'
54
+ And the response from the service has a body of 'Successfull authentication'
55
+ And that service is accessed at the path '/fun'
56
+ And that service is protected by Basic Authentication
57
+ And that service requires the username 'user' with the password 'pass'
58
+ When I run `httparty http://0.0.0.0:4006/fun --user 'user:pass'`
59
+ Then the output should contain "Successfull authentication"
60
+
61
+ Scenario: Get response in plain format
62
+ Given a remote deflate service on port '4007'
63
+ And the response from the service has a body of 'Some request'
64
+ And that service is accessed at the path '/fun'
65
+ When I run `httparty http://0.0.0.0:4007/fun --format plain`
66
+ Then the output should contain "Some request"
67
+
68
+ Scenario: Get response in json format
69
+ Given a remote deflate service on port '4008'
70
+ Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
71
+ And that service is accessed at the path '/service.json'
72
+ And the response from the service has a Content-Type of 'application/json'
73
+ When I run `httparty http://0.0.0.0:4008/service.json --format json`
74
+ Then the output should contain '"jennings": "waylon"'
75
+
76
+ Scenario: Get response in xml format
77
+ Given a remote deflate service on port '4009'
78
+ Given a remote service that returns '<singer>waylon jennings</singer>'
79
+ And that service is accessed at the path '/service.xml'
80
+ And the response from the service has a Content-Type of 'text/xml'
81
+ When I run `httparty http://0.0.0.0:4009/service.xml --format xml`
82
+ Then the output should contain "<singer>"
83
+
84
+ Scenario: Get response in csv format
85
+ Given a remote deflate service on port '4010'
86
+ Given a remote service that returns:
87
+ """
88
+ "Last Name","Name"
89
+ "jennings","waylon"
90
+ "cash","johnny"
91
+ """
92
+ And that service is accessed at the path '/service.csv'
93
+ And the response from the service has a Content-Type of 'application/csv'
94
+ When I run `httparty http://0.0.0.0:4010/service.csv --format csv`
95
+ Then the output should contain '["Last Name", "Name"]'