httparty 0.16.4 → 0.20.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 (87) hide show
  1. checksums.yaml +5 -5
  2. data/.github/workflows/ci.yml +23 -0
  3. data/.rubocop_todo.yml +1 -1
  4. data/Changelog.md +55 -0
  5. data/Gemfile +5 -0
  6. data/README.md +4 -4
  7. data/docs/README.md +70 -5
  8. data/examples/README.md +6 -0
  9. data/examples/aaws.rb +6 -2
  10. data/examples/idn.rb +10 -0
  11. data/examples/peer_cert.rb +9 -0
  12. data/httparty.gemspec +1 -2
  13. data/lib/httparty/connection_adapter.rb +41 -10
  14. data/lib/httparty/cookie_hash.rb +10 -8
  15. data/lib/httparty/decompressor.rb +92 -0
  16. data/lib/httparty/exceptions.rb +3 -1
  17. data/lib/httparty/hash_conversions.rb +4 -2
  18. data/lib/httparty/headers_processor.rb +32 -0
  19. data/lib/httparty/logger/apache_formatter.rb +4 -2
  20. data/lib/httparty/logger/curl_formatter.rb +6 -4
  21. data/lib/httparty/logger/logger.rb +2 -0
  22. data/lib/httparty/logger/logstash_formatter.rb +4 -2
  23. data/lib/httparty/module_inheritable_attributes.rb +3 -1
  24. data/lib/httparty/net_digest_auth.rb +9 -10
  25. data/lib/httparty/parser.rb +9 -5
  26. data/lib/httparty/request/body.rb +24 -10
  27. data/lib/httparty/request/multipart_boundary.rb +2 -0
  28. data/lib/httparty/request.rb +67 -96
  29. data/lib/httparty/response/headers.rb +2 -0
  30. data/lib/httparty/response.rb +24 -4
  31. data/lib/httparty/{fragment_with_response.rb → response_fragment.rb} +6 -5
  32. data/lib/httparty/text_encoder.rb +72 -0
  33. data/lib/httparty/utils.rb +2 -0
  34. data/lib/httparty/version.rb +3 -1
  35. data/lib/httparty.rb +58 -35
  36. metadata +12 -108
  37. data/.travis.yml +0 -11
  38. data/features/basic_authentication.feature +0 -20
  39. data/features/command_line.feature +0 -95
  40. data/features/deals_with_http_error_codes.feature +0 -26
  41. data/features/digest_authentication.feature +0 -30
  42. data/features/handles_compressed_responses.feature +0 -27
  43. data/features/handles_multiple_formats.feature +0 -57
  44. data/features/steps/env.rb +0 -27
  45. data/features/steps/httparty_response_steps.rb +0 -56
  46. data/features/steps/httparty_steps.rb +0 -43
  47. data/features/steps/mongrel_helper.rb +0 -127
  48. data/features/steps/remote_service_steps.rb +0 -92
  49. data/features/supports_read_timeout_option.feature +0 -13
  50. data/features/supports_redirection.feature +0 -22
  51. data/features/supports_timeout_option.feature +0 -13
  52. data/spec/fixtures/delicious.xml +0 -23
  53. data/spec/fixtures/empty.xml +0 -0
  54. data/spec/fixtures/example.html +0 -10
  55. data/spec/fixtures/ssl/generate.sh +0 -29
  56. data/spec/fixtures/ssl/generated/bogushost.crt +0 -13
  57. data/spec/fixtures/ssl/generated/ca.crt +0 -16
  58. data/spec/fixtures/ssl/generated/ca.key +0 -15
  59. data/spec/fixtures/ssl/generated/selfsigned.crt +0 -14
  60. data/spec/fixtures/ssl/generated/server.crt +0 -13
  61. data/spec/fixtures/ssl/generated/server.key +0 -15
  62. data/spec/fixtures/ssl/openssl-exts.cnf +0 -9
  63. data/spec/fixtures/tiny.gif +0 -0
  64. data/spec/fixtures/twitter.csv +0 -2
  65. data/spec/fixtures/twitter.json +0 -1
  66. data/spec/fixtures/twitter.xml +0 -403
  67. data/spec/fixtures/undefined_method_add_node_for_nil.xml +0 -2
  68. data/spec/httparty/connection_adapter_spec.rb +0 -502
  69. data/spec/httparty/cookie_hash_spec.rb +0 -100
  70. data/spec/httparty/exception_spec.rb +0 -45
  71. data/spec/httparty/fragment_with_response_spec.rb +0 -14
  72. data/spec/httparty/hash_conversions_spec.rb +0 -58
  73. data/spec/httparty/logger/apache_formatter_spec.rb +0 -40
  74. data/spec/httparty/logger/curl_formatter_spec.rb +0 -119
  75. data/spec/httparty/logger/logger_spec.rb +0 -43
  76. data/spec/httparty/logger/logstash_formatter_spec.rb +0 -44
  77. data/spec/httparty/net_digest_auth_spec.rb +0 -270
  78. data/spec/httparty/parser_spec.rb +0 -190
  79. data/spec/httparty/request/body_spec.rb +0 -165
  80. data/spec/httparty/request_spec.rb +0 -1367
  81. data/spec/httparty/response_spec.rb +0 -368
  82. data/spec/httparty/ssl_spec.rb +0 -74
  83. data/spec/httparty_spec.rb +0 -923
  84. data/spec/spec_helper.rb +0 -56
  85. data/spec/support/ssl_test_helper.rb +0 -47
  86. data/spec/support/ssl_test_server.rb +0 -80
  87. data/spec/support/stub_response.rb +0 -49
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
4
  module Utils
3
5
  def self.stringify_keys(hash)
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  module HTTParty
2
- VERSION = "0.16.4"
4
+ VERSION = '0.20.0'
3
5
  end
data/lib/httparty.rb CHANGED
@@ -1,3 +1,5 @@
1
+ # frozen_string_literal: true
2
+
1
3
  require 'pathname'
2
4
  require 'net/http'
3
5
  require 'net/https'
@@ -14,6 +16,11 @@ require 'httparty/net_digest_auth'
14
16
  require 'httparty/version'
15
17
  require 'httparty/connection_adapter'
16
18
  require 'httparty/logger/logger'
19
+ require 'httparty/request/body'
20
+ require 'httparty/response_fragment'
21
+ require 'httparty/decompressor'
22
+ require 'httparty/text_encoder'
23
+ require 'httparty/headers_processor'
17
24
 
18
25
  # @see HTTParty::ClassMethods
19
26
  module HTTParty
@@ -22,8 +29,8 @@ module HTTParty
22
29
  base.send :include, ModuleInheritableAttributes
23
30
  base.send(:mattr_inheritable, :default_options)
24
31
  base.send(:mattr_inheritable, :default_cookies)
25
- base.instance_variable_set("@default_options", {})
26
- base.instance_variable_set("@default_cookies", CookieHash.new)
32
+ base.instance_variable_set(:@default_options, {})
33
+ base.instance_variable_set(:@default_cookies, CookieHash.new)
27
34
  end
28
35
 
29
36
  # == Common Request Options
@@ -37,11 +44,11 @@ module HTTParty
37
44
  # [:+limit+:] Maximum number of redirects to follow. Takes precedences over :+no_follow+.
38
45
  # [:+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.
39
46
  # [:+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_stream:] Allow streaming to a REST server to specify a body_stream.
43
- # [:+stream_body:] Allow for streaming large files without loading them into memory.
44
- # [:+multipart:] Force content-type to be multipart
47
+ # [:+local_host+:] Local address to bind to before connecting.
48
+ # [:+local_port+:] Local port to bind to before connecting.
49
+ # [:+body_stream+:] Allow streaming to a REST server to specify a body_stream.
50
+ # [:+stream_body+:] Allow for streaming large files without loading them into memory.
51
+ # [:+multipart+:] Force content-type to be multipart
45
52
  #
46
53
  # 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:
47
54
  # * :+base_uri+: see HTTParty::ClassMethods.base_uri.
@@ -170,9 +177,9 @@ module HTTParty
170
177
  # include HTTParty
171
178
  # default_timeout 10
172
179
  # end
173
- def default_timeout(t)
174
- raise ArgumentError, 'Timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float))
175
- default_options[:timeout] = t
180
+ def default_timeout(value)
181
+ validate_timeout_argument(__method__, value)
182
+ default_options[:timeout] = value
176
183
  end
177
184
 
178
185
  # Allows setting a default open_timeout for all HTTP calls in seconds
@@ -181,9 +188,9 @@ module HTTParty
181
188
  # include HTTParty
182
189
  # open_timeout 10
183
190
  # end
184
- def open_timeout(t)
185
- raise ArgumentError, 'open_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float))
186
- default_options[:open_timeout] = t
191
+ def open_timeout(value)
192
+ validate_timeout_argument(__method__, value)
193
+ default_options[:open_timeout] = value
187
194
  end
188
195
 
189
196
  # Allows setting a default read_timeout for all HTTP calls in seconds
@@ -192,11 +199,24 @@ module HTTParty
192
199
  # include HTTParty
193
200
  # read_timeout 10
194
201
  # end
195
- def read_timeout(t)
196
- raise ArgumentError, 'read_timeout must be an integer or float' unless t && (t.is_a?(Integer) || t.is_a?(Float))
197
- default_options[:read_timeout] = t
202
+ def read_timeout(value)
203
+ validate_timeout_argument(__method__, value)
204
+ default_options[:read_timeout] = value
205
+ end
206
+
207
+ # Allows setting a default write_timeout for all HTTP calls in seconds
208
+ # Supported by Ruby > 2.6.0
209
+ #
210
+ # class Foo
211
+ # include HTTParty
212
+ # write_timeout 10
213
+ # end
214
+ def write_timeout(value)
215
+ validate_timeout_argument(__method__, value)
216
+ default_options[:write_timeout] = value
198
217
  end
199
218
 
219
+
200
220
  # Set an output stream for debugging, defaults to $stderr.
201
221
  # The output stream is passed on to Net::HTTP#set_debug_output.
202
222
  #
@@ -382,6 +402,22 @@ module HTTParty
382
402
  default_options[:ssl_version] = version
383
403
  end
384
404
 
405
+ # Deactivate automatic decompression of the response body.
406
+ # This will require you to explicitly handle body decompression
407
+ # by inspecting the Content-Encoding response header.
408
+ #
409
+ # Refer to docs/README.md "HTTP Compression" section for
410
+ # further details.
411
+ #
412
+ # @example
413
+ # class Foo
414
+ # include HTTParty
415
+ # skip_decompression
416
+ # end
417
+ def skip_decompression(value = true)
418
+ default_options[:skip_decompression] = !!value
419
+ end
420
+
385
421
  # Allows setting of SSL ciphers to use. This only works in Ruby 1.9+.
386
422
  # You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
387
423
  # You also can specify a cipher suite here, listed here at openssl.org:
@@ -560,6 +596,10 @@ module HTTParty
560
596
 
561
597
  private
562
598
 
599
+ def validate_timeout_argument(timeout_type, value)
600
+ raise ArgumentError, "#{ timeout_type } must be an integer or float" unless value && (value.is_a?(Integer) || value.is_a?(Float))
601
+ end
602
+
563
603
  def ensure_method_maintained_across_redirects(options)
564
604
  unless options.key?(:maintain_method_across_redirects)
565
605
  options[:maintain_method_across_redirects] = true
@@ -568,32 +608,15 @@ module HTTParty
568
608
 
569
609
  def perform_request(http_method, path, options, &block) #:nodoc:
570
610
  options = ModuleInheritableAttributes.hash_deep_dup(default_options).merge(options)
571
- process_headers(options)
611
+ HeadersProcessor.new(headers, options).call
572
612
  process_cookies(options)
573
613
  Request.new(http_method, path, options).perform(&block)
574
614
  end
575
615
 
576
- def process_headers(options)
577
- if options[:headers]
578
- if headers.any?
579
- options[:headers] = headers.merge(options[:headers])
580
- end
581
-
582
- options[:headers] = Utils.stringify_keys(process_dynamic_headers(options[:headers]))
583
- end
584
- end
585
-
586
- def process_dynamic_headers(headers)
587
- headers.each_with_object({}) do |header, processed_headers|
588
- key, value = header
589
- processed_headers[key] = value.respond_to?(:call) ? value.call : value
590
- end
591
- end
592
-
593
616
  def process_cookies(options) #:nodoc:
594
617
  return unless options[:cookies] || default_cookies.any?
595
618
  options[:headers] ||= headers.dup
596
- options[:headers]["cookie"] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
619
+ options[:headers]['cookie'] = cookies.merge(options.delete(:cookies) || {}).to_cookie_string
597
620
  end
598
621
 
599
622
  def validate_format
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: httparty
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.16.4
4
+ version: 0.20.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - John Nunemaker
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2019-02-05 00:00:00.000000000 Z
12
+ date: 2021-09-29 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: multi_xml
@@ -48,11 +48,11 @@ extensions: []
48
48
  extra_rdoc_files: []
49
49
  files:
50
50
  - ".editorconfig"
51
+ - ".github/workflows/ci.yml"
51
52
  - ".gitignore"
52
53
  - ".rubocop.yml"
53
54
  - ".rubocop_todo.yml"
54
55
  - ".simplecov"
55
- - ".travis.yml"
56
56
  - CONTRIBUTING.md
57
57
  - Changelog.md
58
58
  - Gemfile
@@ -72,10 +72,12 @@ files:
72
72
  - examples/delicious.rb
73
73
  - examples/google.rb
74
74
  - examples/headers_and_user_agents.rb
75
+ - examples/idn.rb
75
76
  - examples/logging.rb
76
77
  - examples/microsoft_graph.rb
77
78
  - examples/multipart.rb
78
79
  - examples/nokogiri_html_parser.rb
80
+ - examples/peer_cert.rb
79
81
  - examples/rescue_json.rb
80
82
  - examples/rubyurl.rb
81
83
  - examples/stackexchange.rb
@@ -83,27 +85,14 @@ files:
83
85
  - examples/tripit_sign_in.rb
84
86
  - examples/twitter.rb
85
87
  - examples/whoismyrep.rb
86
- - features/basic_authentication.feature
87
- - features/command_line.feature
88
- - features/deals_with_http_error_codes.feature
89
- - features/digest_authentication.feature
90
- - features/handles_compressed_responses.feature
91
- - features/handles_multiple_formats.feature
92
- - features/steps/env.rb
93
- - features/steps/httparty_response_steps.rb
94
- - features/steps/httparty_steps.rb
95
- - features/steps/mongrel_helper.rb
96
- - features/steps/remote_service_steps.rb
97
- - features/supports_read_timeout_option.feature
98
- - features/supports_redirection.feature
99
- - features/supports_timeout_option.feature
100
88
  - httparty.gemspec
101
89
  - lib/httparty.rb
102
90
  - lib/httparty/connection_adapter.rb
103
91
  - lib/httparty/cookie_hash.rb
92
+ - lib/httparty/decompressor.rb
104
93
  - lib/httparty/exceptions.rb
105
- - lib/httparty/fragment_with_response.rb
106
94
  - lib/httparty/hash_conversions.rb
95
+ - lib/httparty/headers_processor.rb
107
96
  - lib/httparty/logger/apache_formatter.rb
108
97
  - lib/httparty/logger/curl_formatter.rb
109
98
  - lib/httparty/logger/logger.rb
@@ -116,45 +105,11 @@ files:
116
105
  - lib/httparty/request/multipart_boundary.rb
117
106
  - lib/httparty/response.rb
118
107
  - lib/httparty/response/headers.rb
108
+ - lib/httparty/response_fragment.rb
109
+ - lib/httparty/text_encoder.rb
119
110
  - lib/httparty/utils.rb
120
111
  - lib/httparty/version.rb
121
112
  - script/release
122
- - spec/fixtures/delicious.xml
123
- - spec/fixtures/empty.xml
124
- - spec/fixtures/example.html
125
- - spec/fixtures/ssl/generate.sh
126
- - spec/fixtures/ssl/generated/bogushost.crt
127
- - spec/fixtures/ssl/generated/ca.crt
128
- - spec/fixtures/ssl/generated/ca.key
129
- - spec/fixtures/ssl/generated/selfsigned.crt
130
- - spec/fixtures/ssl/generated/server.crt
131
- - spec/fixtures/ssl/generated/server.key
132
- - spec/fixtures/ssl/openssl-exts.cnf
133
- - spec/fixtures/tiny.gif
134
- - spec/fixtures/twitter.csv
135
- - spec/fixtures/twitter.json
136
- - spec/fixtures/twitter.xml
137
- - spec/fixtures/undefined_method_add_node_for_nil.xml
138
- - spec/httparty/connection_adapter_spec.rb
139
- - spec/httparty/cookie_hash_spec.rb
140
- - spec/httparty/exception_spec.rb
141
- - spec/httparty/fragment_with_response_spec.rb
142
- - spec/httparty/hash_conversions_spec.rb
143
- - spec/httparty/logger/apache_formatter_spec.rb
144
- - spec/httparty/logger/curl_formatter_spec.rb
145
- - spec/httparty/logger/logger_spec.rb
146
- - spec/httparty/logger/logstash_formatter_spec.rb
147
- - spec/httparty/net_digest_auth_spec.rb
148
- - spec/httparty/parser_spec.rb
149
- - spec/httparty/request/body_spec.rb
150
- - spec/httparty/request_spec.rb
151
- - spec/httparty/response_spec.rb
152
- - spec/httparty/ssl_spec.rb
153
- - spec/httparty_spec.rb
154
- - spec/spec_helper.rb
155
- - spec/support/ssl_test_helper.rb
156
- - spec/support/ssl_test_server.rb
157
- - spec/support/stub_response.rb
158
113
  - website/css/common.css
159
114
  - website/index.html
160
115
  homepage: https://github.com/jnunemaker/httparty
@@ -169,66 +124,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
169
124
  requirements:
170
125
  - - ">="
171
126
  - !ruby/object:Gem::Version
172
- version: 2.0.0
127
+ version: 2.3.0
173
128
  required_rubygems_version: !ruby/object:Gem::Requirement
174
129
  requirements:
175
130
  - - ">="
176
131
  - !ruby/object:Gem::Version
177
132
  version: '0'
178
133
  requirements: []
179
- rubyforge_project:
180
- rubygems_version: 2.6.14
134
+ rubygems_version: 3.0.3
181
135
  signing_key:
182
136
  specification_version: 4
183
137
  summary: Makes http fun! Also, makes consuming restful web services dead easy.
184
- test_files:
185
- - features/basic_authentication.feature
186
- - features/command_line.feature
187
- - features/deals_with_http_error_codes.feature
188
- - features/digest_authentication.feature
189
- - features/handles_compressed_responses.feature
190
- - features/handles_multiple_formats.feature
191
- - features/steps/env.rb
192
- - features/steps/httparty_response_steps.rb
193
- - features/steps/httparty_steps.rb
194
- - features/steps/mongrel_helper.rb
195
- - features/steps/remote_service_steps.rb
196
- - features/supports_read_timeout_option.feature
197
- - features/supports_redirection.feature
198
- - features/supports_timeout_option.feature
199
- - spec/fixtures/delicious.xml
200
- - spec/fixtures/empty.xml
201
- - spec/fixtures/example.html
202
- - spec/fixtures/ssl/generate.sh
203
- - spec/fixtures/ssl/generated/bogushost.crt
204
- - spec/fixtures/ssl/generated/ca.crt
205
- - spec/fixtures/ssl/generated/ca.key
206
- - spec/fixtures/ssl/generated/selfsigned.crt
207
- - spec/fixtures/ssl/generated/server.crt
208
- - spec/fixtures/ssl/generated/server.key
209
- - spec/fixtures/ssl/openssl-exts.cnf
210
- - spec/fixtures/tiny.gif
211
- - spec/fixtures/twitter.csv
212
- - spec/fixtures/twitter.json
213
- - spec/fixtures/twitter.xml
214
- - spec/fixtures/undefined_method_add_node_for_nil.xml
215
- - spec/httparty/connection_adapter_spec.rb
216
- - spec/httparty/cookie_hash_spec.rb
217
- - spec/httparty/exception_spec.rb
218
- - spec/httparty/fragment_with_response_spec.rb
219
- - spec/httparty/hash_conversions_spec.rb
220
- - spec/httparty/logger/apache_formatter_spec.rb
221
- - spec/httparty/logger/curl_formatter_spec.rb
222
- - spec/httparty/logger/logger_spec.rb
223
- - spec/httparty/logger/logstash_formatter_spec.rb
224
- - spec/httparty/net_digest_auth_spec.rb
225
- - spec/httparty/parser_spec.rb
226
- - spec/httparty/request/body_spec.rb
227
- - spec/httparty/request_spec.rb
228
- - spec/httparty/response_spec.rb
229
- - spec/httparty/ssl_spec.rb
230
- - spec/httparty_spec.rb
231
- - spec/spec_helper.rb
232
- - spec/support/ssl_test_helper.rb
233
- - spec/support/ssl_test_server.rb
234
- - spec/support/stub_response.rb
138
+ test_files: []
data/.travis.yml DELETED
@@ -1,11 +0,0 @@
1
- language: ruby
2
- rvm:
3
- - 2.0.0
4
- - 2.1.10
5
- - 2.2.10
6
- - 2.3.8
7
- - 2.4.5
8
- - 2.5.3
9
- - 2.6.0
10
- bundler_args: --without development
11
- before_install: gem install bundler -v '< 2'
@@ -1,20 +0,0 @@
1
- Feature: Basic Authentication
2
-
3
- As a developer
4
- I want to be able to use a service that requires Basic Authentication
5
- Because that is not an uncommon requirement
6
-
7
- Scenario: Passing no credentials to a page requiring Basic Authentication
8
- Given a restricted page at '/basic_auth.html'
9
- When I call HTTParty#get with '/basic_auth.html'
10
- Then it should return a response with a 401 response code
11
-
12
- Scenario: Passing proper credentials to a page requiring Basic Authentication
13
- Given a remote service that returns 'Authenticated Page'
14
- And that service is accessed at the path '/basic_auth.html'
15
- And that service is protected by Basic Authentication
16
- And that service requires the username 'jcash' with the password 'maninblack'
17
- When I call HTTParty#get with '/basic_auth.html' and a basic_auth hash:
18
- | username | password |
19
- | jcash | maninblack |
20
- Then the return value should match 'Authenticated Page'
@@ -1,95 +0,0 @@
1
- @command_line
2
- Feature: Command Line
3
-
4
- As a developer
5
- I want to be able to harness the power of HTTParty from the command line
6
- Because that would make quick testing and debugging easy
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"]'
@@ -1,26 +0,0 @@
1
- Feature: Deals with HTTP error codes
2
-
3
- As a developer
4
- I want to be informed of non-successful responses
5
- Because sometimes thing explode
6
- And I should probably know what happened
7
-
8
- Scenario: A response of '404 - Not Found'
9
- Given a remote service that returns a 404 status code
10
- And that service is accessed at the path '/404_service.html'
11
- When I call HTTParty#get with '/404_service.html'
12
- Then it should return a response with a 404 response code
13
-
14
- Scenario: A response of '500 - Internal Server Error'
15
- Given a remote service that returns a 500 status code
16
- And that service is accessed at the path '/500_service.html'
17
- When I call HTTParty#get with '/500_service.html'
18
- Then it should return a response with a 500 response code
19
-
20
- Scenario: A non-successful response where I need the body
21
- Given a remote service that returns a 400 status code
22
- And the response from the service has a body of 'Bad response'
23
- And that service is accessed at the path '/400_service.html'
24
- When I call HTTParty#get with '/400_service.html'
25
- Then it should return a response with a 400 response code
26
- And the return value should match 'Bad response'
@@ -1,30 +0,0 @@
1
- Feature: Digest Authentication
2
-
3
- As a developer
4
- I want to be able to use a service that requires Digest Authentication
5
- Because that is not an uncommon requirement
6
-
7
- Scenario: Passing no credentials to a page requiring Digest Authentication
8
- Given a restricted page at '/digest_auth.html'
9
- When I call HTTParty#get with '/digest_auth.html'
10
- Then it should return a response with a 401 response code
11
-
12
- Scenario: Passing proper credentials to a page requiring Digest Authentication
13
- Given a remote service that returns 'Digest Authenticated Page'
14
- And that service is accessed at the path '/digest_auth.html'
15
- And that service is protected by Digest Authentication
16
- And that service requires the username 'jcash' with the password 'maninblack'
17
- When I call HTTParty#get with '/digest_auth.html' and a digest_auth hash:
18
- | username | password |
19
- | jcash | maninblack |
20
- Then the return value should match 'Digest Authenticated Page'
21
-
22
- Scenario: Passing proper credentials to a page requiring Digest Authentication using md5-sess algorithm
23
- Given a remote service that returns 'Digest Authenticated Page Using MD5-sess'
24
- And that service is accessed at the path '/digest_auth.html'
25
- And that service is protected by MD5-sess Digest Authentication
26
- And that service requires the username 'jcash' with the password 'maninblack'
27
- When I call HTTParty#get with '/digest_auth.html' and a digest_auth hash:
28
- | username | password |
29
- | jcash | maninblack |
30
- Then the return value should match 'Digest Authenticated Page Using MD5-sess'
@@ -1,27 +0,0 @@
1
- Feature: Handles Compressed Responses
2
-
3
- In order to save bandwidth
4
- As a developer
5
- I want to uncompress compressed responses
6
-
7
- Scenario: Supports deflate encoding
8
- Given a remote deflate service
9
- And the response from the service has a body of '<h1>Some HTML</h1>'
10
- And that service is accessed at the path '/deflate_service.html'
11
- When I call HTTParty#get with '/deflate_service.html'
12
- Then the return value should match '<h1>Some HTML</h1>'
13
-
14
- Scenario: Supports gzip encoding
15
- Given a remote gzip service
16
- And the response from the service has a body of '<h1>Some HTML</h1>'
17
- And that service is accessed at the path '/gzip_service.html'
18
- When I call HTTParty#get with '/gzip_service.html'
19
- Then the return value should match '<h1>Some HTML</h1>'
20
-
21
- Scenario: Supports HEAD request with gzip encoding
22
- Given a remote gzip service
23
- And that service is accessed at the path '/gzip_head.gz.js'
24
- When I call HTTParty#head with '/gzip_head.gz.js'
25
- Then it should return a response with a 200 response code
26
- Then it should return a response with a gzip content-encoding
27
- Then it should return a response with a blank body
@@ -1,57 +0,0 @@
1
- Feature: Handles Multiple Formats
2
-
3
- As a developer
4
- I want to be able to consume remote services of many different formats
5
- And I want those formats to be automatically detected and handled
6
- Because web services take many forms
7
- And I don't want to have to do any extra work
8
-
9
- Scenario: An HTML service
10
- Given a remote service that returns '<h1>Some HTML</h1>'
11
- And that service is accessed at the path '/html_service.html'
12
- And the response from the service has a Content-Type of 'text/html'
13
- When I call HTTParty#get with '/html_service.html'
14
- Then it should return a String
15
- And the return value should match '<h1>Some HTML</h1>'
16
-
17
- Scenario: A CSV service
18
- Given a remote service that returns:
19
- """
20
- "Last Name","Name"
21
- "jennings","waylon"
22
- "cash","johnny"
23
- """
24
- And that service is accessed at the path '/service.csv'
25
- And the response from the service has a Content-Type of 'application/csv'
26
- When I call HTTParty#get with '/service.csv'
27
- Then it should return an Array equaling:
28
- | Last Name | Name |
29
- | jennings | waylon |
30
- | cash | johnny |
31
-
32
- Scenario: A JSON service
33
- Given a remote service that returns '{ "jennings": "waylon", "cash": "johnny" }'
34
- And that service is accessed at the path '/service.json'
35
- And the response from the service has a Content-Type of 'application/json'
36
- When I call HTTParty#get with '/service.json'
37
- Then it should return a Hash equaling:
38
- | key | value |
39
- | jennings | waylon |
40
- | cash | johnny |
41
-
42
- Scenario: An XML Service
43
- Given a remote service that returns '<singer>waylon jennings</singer>'
44
- And that service is accessed at the path '/service.xml'
45
- And the response from the service has a Content-Type of 'text/xml'
46
- When I call HTTParty#get with '/service.xml'
47
- Then it should return a Hash equaling:
48
- | key | value |
49
- | singer | waylon jennings |
50
-
51
- Scenario: A Javascript remote file
52
- Given a remote service that returns '$(function() { alert("hi"); });'
53
- And that service is accessed at the path '/service.js'
54
- And the response from the service has a Content-Type of 'application/javascript'
55
- When I call HTTParty#get with '/service.js'
56
- Then it should return a String
57
- And the return value should match '$(function() { alert("hi"); });'
@@ -1,27 +0,0 @@
1
- require 'mongrel'
2
- require './lib/httparty'
3
- require 'rspec/expectations'
4
- require 'aruba/cucumber'
5
-
6
- def run_server(port)
7
- @host_and_port = "0.0.0.0:#{port}"
8
- @server = Mongrel::HttpServer.new("0.0.0.0", port)
9
- @server.run
10
- @request_options = {}
11
- end
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
-
25
- After do
26
- @server.stop if @server
27
- end