httparty 0.13.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 (77) 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/.travis.yml +4 -2
  7. data/CONTRIBUTING.md +23 -0
  8. data/Gemfile +8 -3
  9. data/Guardfile +3 -3
  10. data/History +106 -11
  11. data/README.md +19 -20
  12. data/Rakefile +5 -7
  13. data/bin/httparty +18 -14
  14. data/docs/README.md +100 -0
  15. data/examples/README.md +67 -0
  16. data/examples/aaws.rb +5 -5
  17. data/examples/basic.rb +6 -10
  18. data/examples/crack.rb +2 -2
  19. data/examples/custom_parsers.rb +1 -4
  20. data/examples/delicious.rb +8 -8
  21. data/examples/google.rb +2 -2
  22. data/examples/headers_and_user_agents.rb +1 -1
  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 +7 -7
  30. data/examples/whoismyrep.rb +1 -1
  31. data/features/command_line.feature +90 -2
  32. data/features/digest_authentication.feature +10 -0
  33. data/features/steps/env.rb +16 -11
  34. data/features/steps/httparty_response_steps.rb +18 -14
  35. data/features/steps/httparty_steps.rb +10 -2
  36. data/features/steps/mongrel_helper.rb +35 -2
  37. data/features/steps/remote_service_steps.rb +26 -8
  38. data/features/supports_read_timeout_option.feature +13 -0
  39. data/httparty.gemspec +6 -5
  40. data/lib/httparty/connection_adapter.rb +36 -13
  41. data/lib/httparty/cookie_hash.rb +3 -4
  42. data/lib/httparty/exceptions.rb +4 -1
  43. data/lib/httparty/hash_conversions.rb +17 -15
  44. data/lib/httparty/logger/{apache_logger.rb → apache_formatter.rb} +3 -3
  45. data/lib/httparty/logger/curl_formatter.rb +91 -0
  46. data/lib/httparty/logger/logger.rb +18 -10
  47. data/lib/httparty/module_inheritable_attributes.rb +1 -1
  48. data/lib/httparty/net_digest_auth.rb +69 -18
  49. data/lib/httparty/parser.rb +4 -2
  50. data/lib/httparty/request.rb +105 -48
  51. data/lib/httparty/response.rb +31 -6
  52. data/lib/httparty/version.rb +1 -1
  53. data/lib/httparty.rb +132 -72
  54. data/spec/httparty/connection_adapter_spec.rb +285 -88
  55. data/spec/httparty/cookie_hash_spec.rb +46 -29
  56. data/spec/httparty/exception_spec.rb +29 -7
  57. data/spec/httparty/hash_conversions_spec.rb +49 -0
  58. data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
  59. data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
  60. data/spec/httparty/logger/logger_spec.rb +23 -7
  61. data/spec/httparty/net_digest_auth_spec.rb +118 -30
  62. data/spec/httparty/parser_spec.rb +43 -35
  63. data/spec/httparty/request_spec.rb +734 -182
  64. data/spec/httparty/response_spec.rb +139 -69
  65. data/spec/httparty/ssl_spec.rb +22 -22
  66. data/spec/httparty_spec.rb +307 -199
  67. data/spec/spec_helper.rb +34 -12
  68. data/spec/support/ssl_test_helper.rb +6 -6
  69. data/spec/support/ssl_test_server.rb +21 -21
  70. data/spec/support/stub_response.rb +20 -14
  71. data/website/index.html +3 -3
  72. metadata +30 -33
  73. data/lib/httparty/core_extensions.rb +0 -32
  74. data/lib/httparty/logger/curl_logger.rb +0 -48
  75. data/spec/httparty/logger/apache_logger_spec.rb +0 -26
  76. data/spec/httparty/logger/curl_logger_spec.rb +0 -18
  77. data/spec/spec.opts +0 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e2e263bc6000ec32578c99ef814398a9742be7a7
4
- data.tar.gz: 9f8eb0a8ddb0100669e3f08c86fbde96b7c538d7
3
+ metadata.gz: f66396072d869ad76f661789a0e9b2d66495faa2
4
+ data.tar.gz: ae8e43661459ee5bd5c9018645812ecd9500cd6b
5
5
  SHA512:
6
- metadata.gz: 4e02f9c9aab76af35b66bc0421d7322357a3a180f55cb50434259ce907d9cb536adaef681312fdee37648d8b558731c1c003d5bb57caa0000a187d24377449b3
7
- data.tar.gz: 39286a8c98a2375f4fa60c98fb0ec3a5dd8828760029fcdefa054acce0da38cc20eb113cfbb6759a6df3f7ffaf7a9d62021c17ddb599318cf557ab70fdfedfad
6
+ metadata.gz: ac6a080a19674df0435a6715406b97645ed9ee2ed803b92eb3e90ade39e75ac311b3e11960d2c44d00a561720be53aa1d229f216fb40e67f4452659701005695
7
+ data.tar.gz: 7529cf1586833fef74e6e6840a8992ab6b8c8b9ff83db89c5179bf166ce21abc0868c63bd800b5f110a85f65c90472e24cc89632d9cedf0f3bae39c70c1baa6c
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ pkg/
8
8
  *.swp
9
9
  /.bundle
10
10
  .rvmrc
11
+ coverage
data/.rubocop.yml ADDED
@@ -0,0 +1,92 @@
1
+ inherit_from: .rubocop_todo.yml
2
+
3
+ # Offense count: 963
4
+ # Cop supports --auto-correct.
5
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
6
+ Style/StringLiterals:
7
+ Enabled: false
8
+
9
+ # Offense count: 327
10
+ # Cop supports --auto-correct.
11
+ # Configuration parameters: EnforcedStyle, EnforcedStyleForEmptyBraces, SupportedStyles.
12
+ Style/SpaceInsideHashLiteralBraces:
13
+ Enabled: false
14
+
15
+ # Offense count: 33
16
+ # Cop supports --auto-correct.
17
+ # Configuration parameters: EnforcedStyle, SupportedStyles, EnforcedStyleForEmptyBraces, SpaceBeforeBlockParameters.
18
+ Style/SpaceInsideBlockBraces:
19
+ Enabled: false
20
+
21
+ # Offense count: 1
22
+ # Cop supports --auto-correct.
23
+ Style/SpaceBeforeSemicolon:
24
+ Enabled: false
25
+
26
+ # Offense count: 20
27
+ # Cop supports --auto-correct.
28
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
29
+ Style/SignalException:
30
+ Enabled: false
31
+
32
+ # Offense count: 1
33
+ # Configuration parameters: Methods.
34
+ Style/SingleLineBlockParams:
35
+ Enabled: false
36
+
37
+ # Offense count: 6
38
+ # Cop supports --auto-correct.
39
+ Style/PerlBackrefs:
40
+ Enabled: false
41
+
42
+ # Offense count: 2
43
+ # Cop supports --auto-correct.
44
+ # Configuration parameters: AllowAsExpressionSeparator.
45
+ Style/Semicolon:
46
+ Enabled: false
47
+
48
+ # Offense count: 77
49
+ # Cop supports --auto-correct.
50
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
51
+ Style/BracesAroundHashParameters:
52
+ Enabled: false
53
+
54
+ # Offense count: 36
55
+ Style/Documentation:
56
+ Enabled: false
57
+
58
+ # Offense count: 6
59
+ # Cop supports --auto-correct.
60
+ # Configuration parameters: EnforcedStyle, SupportedStyles, AllowInnerSlashes.
61
+ Style/RegexpLiteral:
62
+ Enabled: false
63
+
64
+ # Offense count: 5
65
+ # Cop supports --auto-correct.
66
+ Style/NumericLiterals:
67
+ MinDigits: 6
68
+
69
+ # Offense count: 4
70
+ # Cop supports --auto-correct.
71
+ Lint/UnusedMethodArgument:
72
+ Enabled: false
73
+
74
+ # Offense count: 11
75
+ # Cop supports --auto-correct.
76
+ Lint/UnusedBlockArgument:
77
+ Enabled: false
78
+
79
+ # Offense count: 1
80
+ Lint/Void:
81
+ Enabled: false
82
+
83
+ # Offense count: 22
84
+ # Cop supports --auto-correct.
85
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
86
+ Style/IndentHash:
87
+ Enabled: false
88
+
89
+ # Offense count: 7
90
+ # Configuration parameters: MinBodyLength.
91
+ Style/GuardClause:
92
+ Enabled: false
data/.rubocop_todo.yml ADDED
@@ -0,0 +1,124 @@
1
+ # This configuration was generated by `rubocop --auto-gen-config`
2
+ # on 2015-04-24 07:22:28 +0200 using RuboCop version 0.30.0.
3
+ # The point is for the user to remove these configuration records
4
+ # one by one as the offenses are removed from the code base.
5
+ # Note that changes in the inspected code, or installation of new
6
+ # versions of RuboCop, may require this file to be generated again.
7
+
8
+ # Offense count: 33
9
+ Lint/AmbiguousRegexpLiteral:
10
+ Enabled: false
11
+
12
+ # Offense count: 1
13
+ # Configuration parameters: AlignWith, SupportedStyles.
14
+ Lint/EndAlignment:
15
+ Enabled: false
16
+
17
+ # Offense count: 1
18
+ Lint/HandleExceptions:
19
+ Enabled: false
20
+
21
+ # Offense count: 5
22
+ Lint/UselessAssignment:
23
+ Enabled: false
24
+
25
+ # Offense count: 23
26
+ Metrics/AbcSize:
27
+ Max: 86
28
+
29
+ # Offense count: 1
30
+ # Configuration parameters: CountComments.
31
+ Metrics/ClassLength:
32
+ Max: 285
33
+
34
+ # Offense count: 8
35
+ Metrics/CyclomaticComplexity:
36
+ Max: 17
37
+
38
+ # Offense count: 332
39
+ # Configuration parameters: AllowURI, URISchemes.
40
+ Metrics/LineLength:
41
+ Max: 266
42
+
43
+ # Offense count: 17
44
+ # Configuration parameters: CountComments.
45
+ Metrics/MethodLength:
46
+ Max: 39
47
+
48
+ # Offense count: 8
49
+ Metrics/PerceivedComplexity:
50
+ Max: 20
51
+
52
+ # Offense count: 1
53
+ Style/AccessorMethodName:
54
+ Enabled: false
55
+
56
+ # Offense count: 1
57
+ Style/AsciiComments:
58
+ Enabled: false
59
+
60
+ # Offense count: 14
61
+ # Cop supports --auto-correct.
62
+ # Configuration parameters: EnforcedStyle, SupportedStyles, ProceduralMethods, FunctionalMethods, IgnoredMethods.
63
+ Style/BlockDelimiters:
64
+ Enabled: false
65
+
66
+ # Offense count: 2
67
+ Style/CaseEquality:
68
+ Enabled: false
69
+
70
+ # Offense count: 3
71
+ # Configuration parameters: IndentWhenRelativeTo, SupportedStyles, IndentOneStep.
72
+ Style/CaseIndentation:
73
+ Enabled: false
74
+
75
+ # Offense count: 4
76
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
77
+ Style/ClassAndModuleChildren:
78
+ Enabled: false
79
+
80
+ # Offense count: 7
81
+ Style/ConstantName:
82
+ Enabled: false
83
+
84
+ # Offense count: 2
85
+ Style/EachWithObject:
86
+ Enabled: false
87
+
88
+ # Offense count: 2
89
+ # Cop supports --auto-correct.
90
+ Style/ElseAlignment:
91
+ Enabled: false
92
+
93
+ # Offense count: 3
94
+ # Cop supports --auto-correct.
95
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
96
+ Style/FirstParameterIndentation:
97
+ Enabled: false
98
+
99
+ # Offense count: 2
100
+ # Cop supports --auto-correct.
101
+ # Configuration parameters: EnforcedStyle, SupportedStyles, UseHashRocketsWithSymbolValues.
102
+ Style/HashSyntax:
103
+ Enabled: false
104
+
105
+ # Offense count: 7
106
+ # Cop supports --auto-correct.
107
+ # Configuration parameters: MaxLineLength.
108
+ Style/IfUnlessModifier:
109
+ Enabled: false
110
+
111
+ # Offense count: 11
112
+ # Cop supports --auto-correct.
113
+ Style/Lambda:
114
+ Enabled: false
115
+
116
+ # Offense count: 1
117
+ # Configuration parameters: EnforcedStyle, MinBodyLength, SupportedStyles.
118
+ Style/Next:
119
+ Enabled: false
120
+
121
+ # Offense count: 2
122
+ # Configuration parameters: EnforcedStyle, SupportedStyles.
123
+ Style/RaiseArgs:
124
+ Enabled: false
data/.simplecov ADDED
@@ -0,0 +1 @@
1
+ SimpleCov.start "test_frameworks"
data/.travis.yml CHANGED
@@ -2,6 +2,8 @@ language: ruby
2
2
  rvm:
3
3
  - 1.9.3
4
4
  - 2.0.0
5
- notifications:
6
- email: false
5
+ - 2.1.8
6
+ - 2.2.4
7
+ - 2.3.0
7
8
  bundler_args: --without development
9
+ before_install: gem install bundler
data/CONTRIBUTING.md ADDED
@@ -0,0 +1,23 @@
1
+ # Contributing
2
+
3
+ * Contributions will not be accepted without tests.
4
+ * Please post unconfirmed bugs to the mailing list first: https://groups.google.com/forum/#!forum/httparty-gem
5
+ * Don't change the version. The maintainers will handle that when they release.
6
+ * Always provide as much information and reproducibility as possible when filing an issue or submitting a pull request.
7
+
8
+ ## Workflow
9
+
10
+ * Fork the project.
11
+ * Run `bundle`
12
+ * Run `bundle exec rake`
13
+ * Make your feature addition or bug fix.
14
+ * Add tests for it. This is important so I don't break it in a future version unintentionally.
15
+ * Run `bundle exec rake` (No, REALLY :))
16
+ * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
17
+ * Send me a pull request. Bonus points for topic branches.
18
+
19
+ ## Help and Docs
20
+
21
+ * https://groups.google.com/forum/#!forum/httparty-gem
22
+ * http://stackoverflow.com/questions/tagged/httparty
23
+ * http://rdoc.info/projects/jnunemaker/httparty
data/Gemfile CHANGED
@@ -2,9 +2,7 @@ source 'https://rubygems.org'
2
2
  gemspec
3
3
 
4
4
  gem 'rake'
5
- gem 'cucumber', '~> 0.7'
6
- gem 'fakeweb', '~> 1.2'
7
- gem 'rspec', '~> 1.3'
5
+ gem 'fakeweb', '~> 1.3'
8
6
  gem 'mongrel', '1.2.0.pre2'
9
7
 
10
8
  group :development do
@@ -12,3 +10,10 @@ group :development do
12
10
  gem 'guard-rspec'
13
11
  gem 'guard-bundler'
14
12
  end
13
+
14
+ group :test do
15
+ gem 'rspec', '~> 3.4'
16
+ gem 'simplecov', require: false
17
+ gem 'aruba'
18
+ gem 'cucumber', '~> 2.3'
19
+ end
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  rspec_options = {
2
- :version => 1,
3
- :all_after_pass => false,
4
- :all_on_start => false,
2
+ version: 1,
3
+ all_after_pass: false,
4
+ all_on_start: false
5
5
  }
6
6
 
7
7
  guard 'rspec', rspec_options do
data/History CHANGED
@@ -1,8 +1,104 @@
1
- == 0.10.1 2013-01-26
1
+ == 0.14.0
2
+ * [added status predicate methods to Response#respond_to?](https://github.com/jnunemaker/httparty/pull/482)
3
+ * [allow empty array to be used as param](https://github.com/jnunemaker/httparty/pull/477)
4
+ * [add support for MKCOL method](https://github.com/jnunemaker/httparty/pull/465)
5
+ * [remove json gem from gemspec](https://github.com/jnunemaker/httparty/pull/464)
6
+ * [stop mutating cookie hash](https://github.com/jnunemaker/httparty/pull/460)
7
+ * [optional raising exception on certain status codes](https://github.com/jnunemaker/httparty/pull/455)
8
+
9
+ == 0.13.7 aka "party not as hard"
10
+ * remove post install emoji as it caused installation issues for some people
11
+
12
+ == 0.13.6
13
+ * avoid calling String#strip on invalid Strings
14
+ * preserve request method on 307 and 308 redirects
15
+ * output version with --version for command line bin
16
+ * maintain head request method across redirects by default
17
+ * add support for RFC2617 MD5-sess algorithm type
18
+ * add party popper emoji to post install message
19
+
20
+ == 0.13.5
21
+ * allow setting a custom URI adapter
22
+
23
+ == 0.13.4
24
+ * correct redirect url for redirect paths without leading slash
25
+ * remove core_extensions.rb as backwards compat for ruby 1.8 not needed
26
+ * replace URI.encode with ERB::Util.url_encode
27
+ * allow the response to be tapped
28
+
29
+ == 0.13.3
30
+ * minor improvement
31
+ * added option to allow for streaming large files without loading them into memory (672cdae)
32
+
33
+ == 0.13.2
34
+ * minor improvement
35
+ * [Set correct path on redirect to filename](https://github.com/jnunemaker/httparty/pull/337)
36
+ * ensure logger works with curl format
37
+
38
+ == 0.13.1 2014-04-08
39
+ * new
40
+ * [Added ability to specify a body_stream in HttpRequest](https://github.com/jnunemaker/httparty/pull/275)
41
+ * [Added read_timeout and open_timeout options](https://github.com/jnunemaker/httparty/pull/278)
42
+ * change
43
+ * [Initialize HTTParty requests with an URI object and a String](https://github.com/jnunemaker/httparty/pull/274)
44
+ * minor improvement
45
+ * [Add stackexchange API example](https://github.com/jnunemaker/httparty/pull/280)
46
+
47
+ == 0.13.0 2014-02-14
48
+ * new
49
+ * [Add CSV support](https://github.com/jnunemaker/httparty/pull/269)
50
+ * [Allows PKCS12 client certificates](https://github.com/jnunemaker/httparty/pull/246)
51
+ * bug fix
52
+ * [Digest auth no longer fails when multiple headers are sent by the server](https://github.com/jnunemaker/httparty/pull/272)
53
+ * [Use 'Basement.copy' when calling 'HTTParty.copy'](https://github.com/jnunemaker/httparty/pull/268)
54
+ * [No longer appends ampersand when queries are embedded in paths](https://github.com/jnunemaker/httparty/pull/252)
55
+ * change
56
+ * [Merge - instead of overwrite - default headers with request provided headers](https://github.com/jnunemaker/httparty/pull/270)
57
+ * [Modernize respond_to implementations to support second param](https://github.com/jnunemaker/httparty/pull/264)
58
+ * [Sort query parameters by key before processing](https://github.com/jnunemaker/httparty/pull/245)
59
+ * minor improvement
60
+ * [Add HTTParty::Error base class](https://github.com/jnunemaker/httparty/pull/260)
61
+
62
+ == 0.12.0 2013-10-10
63
+ * new
64
+ * [Added initial logging support](https://github.com/jnunemaker/httparty/pull/243)
65
+ * [Add support for local host and port binding](https://github.com/jnunemaker/httparty/pull/238)
66
+ * [content_type_charset_support](https://github.com/jnunemaker/httparty/commit/82e351f0904e8ecc856015ff2854698a2ca47fbc)
67
+ * bug fix
68
+ * [No longer attempt to decompress the body on HEAD requests](https://github.com/jnunemaker/httparty/commit/f2b8cc3d49e0e9363d7054b14f30c340d7b8e7f1)
69
+ * [Adding java check in aliasing of multiple choices](https://github.com/jnunemaker/httparty/pull/204/commits)
70
+ * change
71
+ * [MIME-type files of javascript are returned as a string instead of JSON](https://github.com/jnunemaker/httparty/pull/239)
72
+ * [Made SSL connections use the system certificate store by default](https://github.com/jnunemaker/httparty/pull/226)
73
+ * [Do not pass proxy options to Net::HTTP connection if not specified](https://github.com/jnunemaker/httparty/pull/222)
74
+ * [Replace multi_json with stdlib json](https://github.com/jnunemaker/httparty/pull/214)
75
+ * [Require Ruby >= 1.9.3]
76
+ * [Response returns array of returned cookie strings](https://github.com/jnunemaker/httparty/pull/218)
77
+ * [Allow '=' within value of a cookie]
78
+ * minor improvements
79
+ * [Improve documentation of ssl_ca_file, ssl_ca_path](https://github.com/jnunemaker/httparty/pull/223)
80
+ * [Fix example URLs](https://github.com/jnunemaker/httparty/pull/232)
81
+
82
+ == 0.11.0 2013-04-10
83
+ * new
84
+ * [Add COPY http request handling](https://github.com/jnunemaker/httparty/pull/190)
85
+ * [Ruby 2.0 tests](https://github.com/jnunemaker/httparty/pull/194)
86
+ * [Ruby >= 2.0.0 support both multiple_choice? and multiple_choices?]
87
+ * bug fix
88
+ * [Maintain blocks passed to 'perform' in redirects](https://github.com/jnunemaker/httparty/pull/191)
89
+ * [Fixed nc value being quoted, this was against spec](https://github.com/jnunemaker/httparty/pull/196)
90
+ * [Request#uri no longer duplicates non-relative-path params](https://github.com/jnunemaker/httparty/pull/189)
91
+ * change
92
+ * [Client-side-only cookie attributes are removed: case-insensitive](https://github.com/jnunemaker/httparty/pull/188)
93
+
94
+ == 0.10.2 2013-01-26
95
+ * bug fix
96
+ * [hash_conversions misnamed variable](https://github.com/jnunemaker/httparty/pull/187)
2
97
 
98
+ == 0.10.1 2013-01-26
3
99
  * new
4
- * [added support for MOVE requests](https://github.com/jnunemaker/httparty/pull/183)
5
- * [bump multi xml version](https://github.com/jnunemaker/httparty/pull/181)
100
+ * [Added support for MOVE requests](https://github.com/jnunemaker/httparty/pull/183)
101
+ * [Bump multi xml version](https://github.com/jnunemaker/httparty/pull/181)
6
102
 
7
103
  == 0.10.0 2013-01-10
8
104
  * changes
@@ -12,7 +108,6 @@
12
108
  * new
13
109
  * [support for connection adapters](https://github.com/jnunemaker/httparty/pull/157)
14
110
  * [allow ssl_version on ruby 1.9](https://github.com/jnunemaker/httparty/pull/159)
15
-
16
111
  * bug fixes
17
112
  * [don't treat port 4430 as ssl](https://github.com/jnunemaker/httparty/commit/a296b1c97f83d7dcc6ef85720a43664c265685ac)
18
113
  * [deep clone default options](https://github.com/jnunemaker/httparty/commit/f74227d30f9389b4b23a888c9af49fb9b8248e1f)
@@ -167,7 +262,7 @@
167
262
 
168
263
  * minor enhancements
169
264
  * Timeout option added; will raise a Timeout::Error after the timeout has elapsed (attack). Closes #17
170
- HTTParty.get "http://github.com", :timeout => 1
265
+ HTTParty.get "http://github.com", timeout: 1
171
266
  * Building gem with Jeweler
172
267
 
173
268
  == 0.4.4 2009-07-19
@@ -282,20 +377,20 @@
282
377
  == 0.1.3 2008-08-22
283
378
 
284
379
  * 3 major enhancements:
285
- * Added http_proxy key for setting proxy server and port (francxk@gmail.com)
286
- * Now raises exception when http error occurs (francxk@gmail.com)
287
- * Changed auto format detection from file extension to response content type (Jay Pignata)
380
+ * Added http_proxy key for setting proxy server and port (francxk@gmail.com)
381
+ * Now raises exception when http error occurs (francxk@gmail.com)
382
+ * Changed auto format detection from file extension to response content type (Jay Pignata)
288
383
 
289
384
  == 0.1.2 2008-08-09
290
385
 
291
386
  * 1 major enhancement:
292
- * default_params were not being appended to query string if option[:query] was blank
387
+ * default_params were not being appended to query string if option[:query] was blank
293
388
 
294
389
  == 0.1.1 2008-07-30
295
390
 
296
391
  * 2 major enhancement:
297
- * Added :basic_auth key for options when making a request
298
- * :query and :body both now work with query string or hash
392
+ * Added :basic_auth key for options when making a request
393
+ * :query and :body both now work with query string or hash
299
394
 
300
395
  == 0.1.0 2008-07-27
301
396
 
data/README.md CHANGED
@@ -18,37 +18,31 @@ gem install httparty
18
18
 
19
19
  ```ruby
20
20
  # Use the class methods to get down to business quickly
21
- response = HTTParty.get('http://twitter.com/statuses/public_timeline.json')
22
- puts response.body, response.code, response.message, response.headers.inspect
21
+ response = HTTParty.get('http://api.stackexchange.com/2.2/questions?site=stackoverflow')
23
22
 
24
- response.each do |item|
25
- puts item['user']['screen_name']
26
- end
23
+ puts response.body, response.code, response.message, response.headers.inspect
27
24
 
28
25
  # Or wrap things up in your own class
29
- class Twitter
26
+ class StackExchange
30
27
  include HTTParty
31
- base_uri 'twitter.com'
28
+ base_uri 'api.stackexchange.com'
32
29
 
33
- def initialize(u, p)
34
- @auth = {:username => u, :password => p}
30
+ def initialize(service, page)
31
+ @options = { query: {site: service, page: page} }
35
32
  end
36
33
 
37
- # which can be :friends, :user or :public
38
- # options[:query] can be things like since, since_id, count, etc.
39
- def timeline(which=:friends, options={})
40
- options.merge!({:basic_auth => @auth})
41
- self.class.get("/statuses/#{which}_timeline.json", options)
34
+ def questions
35
+ self.class.get("/2.2/questions", @options)
42
36
  end
43
37
 
44
- def post(text)
45
- options = { :body => {:status => text}, :basic_auth => @auth }
46
- self.class.post('/statuses/update.json', options)
38
+ def users
39
+ self.class.get("/2.2/users", @options)
47
40
  end
48
41
  end
49
42
 
50
- twitter = Twitter.new(config['email'], config['password'])
51
- pp twitter.timeline
43
+ stack_exchange = StackExchange.new("stackoverflow", 1)
44
+ puts stack_exchange.questions
45
+ puts stack_exchange.users
52
46
  ```
53
47
 
54
48
  See the [examples directory](http://github.com/jnunemaker/httparty/tree/master/examples) for even more goodies.
@@ -63,18 +57,23 @@ formatted XML or JSON. Execute `httparty --help` for all the
63
57
  options. Below is an example of how easy it is.
64
58
 
65
59
  ```
66
- httparty "http://twitter.com/statuses/public_timeline.json"
60
+ httparty "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
67
61
  ```
68
62
 
69
63
  ## Help and Docs
70
64
 
65
+ * [Docs](docs/)
71
66
  * https://groups.google.com/forum/#!forum/httparty-gem
72
67
  * http://rdoc.info/projects/jnunemaker/httparty
68
+ * http://stackoverflow.com/questions/tagged/httparty
73
69
 
74
70
  ## Contributing
75
71
 
76
72
  * Fork the project.
73
+ * Run `bundle`
74
+ * Run `bundle exec rake`
77
75
  * Make your feature addition or bug fix.
78
76
  * Add tests for it. This is important so I don't break it in a future version unintentionally.
77
+ * Run `bundle exec rake` (No, REALLY :))
79
78
  * Commit, do not mess with rakefile, version, or history. (if you want to have your own version, that is fine but bump version in a commit by itself in another branch so I can ignore when I pull)
80
79
  * Send me a pull request. Bonus points for topic branches.
data/Rakefile CHANGED
@@ -1,12 +1,10 @@
1
- require 'spec/rake/spectask'
2
- Spec::Rake::SpecTask.new(:spec) do |spec|
3
- spec.ruby_opts << '-rubygems'
4
- spec.libs << 'lib' << 'spec'
5
- spec.spec_files = FileList['spec/**/*_spec.rb']
6
- spec.spec_opts = ['--options', 'spec/spec.opts']
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError
7
5
  end
8
6
 
9
7
  require 'cucumber/rake/task'
10
8
  Cucumber::Rake::Task.new(:features)
11
9
 
12
- task :default => [:spec, :features]
10
+ task default: [:spec, :features]
data/bin/httparty CHANGED
@@ -3,21 +3,21 @@
3
3
  require "optparse"
4
4
  require "pp"
5
5
 
6
- $:.unshift(File.join(File.dirname(__FILE__), "/../lib"))
6
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), "/../lib"))
7
7
  require "httparty"
8
8
 
9
9
  opts = {
10
- :action => :get,
11
- :headers => {},
12
- :verbose => false
10
+ action: :get,
11
+ headers: {},
12
+ verbose: false
13
13
  }
14
14
 
15
15
  OptionParser.new do |o|
16
- o.banner = "USAGE: #{$0} [options] [url]"
16
+ o.banner = "USAGE: #{$PROGRAM_NAME} [options] [url]"
17
17
 
18
18
  o.on("-f",
19
19
  "--format [FORMAT]",
20
- "Output format to use instead of pretty-print ruby: " +
20
+ "Output format to use instead of pretty-print ruby: " \
21
21
  "plain, csv, json or xml") do |f|
22
22
  opts[:output_format] = f.downcase.to_sym
23
23
  end
@@ -51,7 +51,7 @@ OptionParser.new do |o|
51
51
  o.on("-u", "--user [CREDS]", "Use basic authentication. Value should be user:password") do |u|
52
52
  abort "Invalid credentials format. Must be user:password" unless u =~ /.*:.+/
53
53
  user, password = u.split(':')
54
- opts[:basic_auth] = { :username => user, :password => password }
54
+ opts[:basic_auth] = { username: user, password: password }
55
55
  end
56
56
 
57
57
  o.on("-r", "--response-code", "Command fails if response code >= 400") do
@@ -62,18 +62,22 @@ OptionParser.new do |o|
62
62
  puts o
63
63
  exit
64
64
  end
65
- end.parse!
66
65
 
66
+ o.on("--version", "Show HTTParty version") do |ver|
67
+ puts "Version: #{HTTParty::VERSION}"
68
+ exit
69
+ end
70
+ end.parse!
67
71
 
68
72
  if ARGV.empty?
69
73
  STDERR.puts "You need to provide a URL"
70
- STDERR.puts "USAGE: #{$0} [options] [url]"
74
+ STDERR.puts "USAGE: #{$PROGRAM_NAME} [options] [url]"
71
75
  end
72
76
 
73
77
  def dump_headers(response)
74
78
  resp_type = Net::HTTPResponse::CODE_TO_OBJ[response.code.to_s]
75
79
  puts "#{response.code} #{resp_type.to_s.sub(/^Net::HTTP/, '')}"
76
- response.headers.each do |n,v|
80
+ response.headers.each do |n, v|
77
81
  puts "#{n}: #{v}"
78
82
  end
79
83
  puts
@@ -81,7 +85,7 @@ end
81
85
 
82
86
  if opts[:verbose]
83
87
  puts "#{opts[:action].to_s.upcase} #{ARGV.first}"
84
- opts[:headers].each do |n,v|
88
+ opts[:headers].each do |n, v|
85
89
  puts "#{n}: #{v}"
86
90
  end
87
91
  puts
@@ -99,9 +103,9 @@ else
99
103
  when :json
100
104
  begin
101
105
  require 'json'
102
- puts JSON.pretty_generate(response.delegate)
106
+ puts JSON.pretty_generate(response)
103
107
  rescue LoadError
104
- puts YAML.dump(response.delegate)
108
+ puts YAML.dump(response)
105
109
  end
106
110
  when :xml
107
111
  require 'rexml/document'
@@ -109,7 +113,7 @@ else
109
113
  puts
110
114
  when :csv
111
115
  require 'csv'
112
- puts CSV.parse(response.body).map{|row| row.to_s }
116
+ puts CSV.parse(response.body).map(&:to_s)
113
117
  else
114
118
  puts response
115
119
  end