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
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: cb42a1df375baa50335dbd9151a62dd8dff18ca6
4
- data.tar.gz: 7bd368829511fe16e9ee7feee2d30c234ea5a04a
3
+ metadata.gz: f5784f9133ce53f44315b798fa193aa60a6e4984
4
+ data.tar.gz: 98998538307e0526d580c90fe14c77f42b2d14c4
5
5
  SHA512:
6
- metadata.gz: 5cb7342774ce3435cce9098959d3d23b51ffbf98d0a858af47da257e5bb1610411d8cc68ec43f56a1a93048ca29a0dec2cbd77735c2ae56b8be5a9b45559ce0b
7
- data.tar.gz: e34c9b170df6166dcf763c16d17fcdfe41098b91c138c2ee1fbb51b9f38439e0d6fe6890987d214b77b3a76f313c847b87fb68d6fa923bef4a19650533d26da5
6
+ metadata.gz: 4624b824e95e17884925e53db69f34aa722ab98a9edc3e3a3210bb4417d6106b8619485dca07a430ed223c8c8c62f9be11ff3651ca88070ef524d8db12cdc3f8
7
+ data.tar.gz: 73b4f6af1037ee6ace8d7a88013dbe4d5d1371fb48440552b644526789ade291ee2f1d055be0adad47ec5682f792f50cd330d8fc28a4d70446aa518715273cc5
data/.gitignore CHANGED
@@ -8,3 +8,4 @@ pkg/
8
8
  *.swp
9
9
  /.bundle
10
10
  .rvmrc
11
+ coverage
@@ -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
@@ -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
@@ -0,0 +1 @@
1
+ SimpleCov.start "test_frameworks"
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.1'
16
+ gem 'simplecov', require: false
17
+ gem 'aruba'
18
+ gem 'cucumber', '~> 1.3.17'
19
+ end
data/Guardfile CHANGED
@@ -1,7 +1,7 @@
1
1
  rspec_options = {
2
2
  version: 1,
3
3
  all_after_pass: false,
4
- all_on_start: false,
4
+ all_on_start: false
5
5
  }
6
6
 
7
7
  guard 'rspec', rspec_options do
data/README.md CHANGED
@@ -64,6 +64,7 @@ httparty "https://api.stackexchange.com/2.2/questions?site=stackoverflow"
64
64
 
65
65
  * https://groups.google.com/forum/#!forum/httparty-gem
66
66
  * http://rdoc.info/projects/jnunemaker/httparty
67
+ * http://stackoverflow.com/questions/tagged/httparty
67
68
 
68
69
  ## Contributing
69
70
 
data/Rakefile CHANGED
@@ -1,8 +1,7 @@
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']
1
+ begin
2
+ require 'rspec/core/rake_task'
3
+ RSpec::Core::RakeTask.new(:spec)
4
+ rescue LoadError
6
5
  end
7
6
 
8
7
  require 'cucumber/rake/task'
@@ -3,7 +3,7 @@
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 = {
@@ -13,11 +13,11 @@ opts = {
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
@@ -64,16 +64,15 @@ OptionParser.new do |o|
64
64
  end
65
65
  end.parse!
66
66
 
67
-
68
67
  if ARGV.empty?
69
68
  STDERR.puts "You need to provide a URL"
70
- STDERR.puts "USAGE: #{$0} [options] [url]"
69
+ STDERR.puts "USAGE: #{$PROGRAM_NAME} [options] [url]"
71
70
  end
72
71
 
73
72
  def dump_headers(response)
74
73
  resp_type = Net::HTTPResponse::CODE_TO_OBJ[response.code.to_s]
75
74
  puts "#{response.code} #{resp_type.to_s.sub(/^Net::HTTP/, '')}"
76
- response.headers.each do |n,v|
75
+ response.headers.each do |n, v|
77
76
  puts "#{n}: #{v}"
78
77
  end
79
78
  puts
@@ -81,7 +80,7 @@ end
81
80
 
82
81
  if opts[:verbose]
83
82
  puts "#{opts[:action].to_s.upcase} #{ARGV.first}"
84
- opts[:headers].each do |n,v|
83
+ opts[:headers].each do |n, v|
85
84
  puts "#{n}: #{v}"
86
85
  end
87
86
  puts
@@ -99,9 +98,9 @@ else
99
98
  when :json
100
99
  begin
101
100
  require 'json'
102
- puts JSON.pretty_generate(response.delegate)
101
+ puts JSON.pretty_generate(response)
103
102
  rescue LoadError
104
- puts YAML.dump(response.delegate)
103
+ puts YAML.dump(response)
105
104
  end
106
105
  when :xml
107
106
  require 'rexml/document'
@@ -109,7 +108,7 @@ else
109
108
  puts
110
109
  when :csv
111
110
  require 'csv'
112
- puts CSV.parse(response.body).map{|row| row.to_s }
111
+ puts CSV.parse(response.body).map(&:to_s)
113
112
  else
114
113
  puts response
115
114
  end
@@ -62,3 +62,6 @@
62
62
  * Httparty included into poro class
63
63
  * Uses `get` requests
64
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
@@ -4,7 +4,7 @@ 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
@@ -16,7 +16,7 @@ module AAWS
16
16
  self.class.default_params AWSAccessKeyId: key
17
17
  end
18
18
 
19
- def search(options={})
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
@@ -9,7 +9,7 @@ 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,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,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'], '.delicious')))
4
+ config = YAML.load(File.read(File.join(ENV['HOME'], '.delicious')))
5
5
 
6
6
  class Delicious
7
7
  include HTTParty
@@ -16,7 +16,7 @@ class Delicious
16
16
  # dt (optional). Filter by this date (CCYY-MM-DDThh:mm:ssZ).
17
17
  # url (optional). Filter by this url.
18
18
  # ie: posts(query: {tag: 'ruby'})
19
- def posts(options={})
19
+ def posts(options = {})
20
20
  options.merge!({basic_auth: @auth})
21
21
  self.class.get('/posts/get', options)
22
22
  end
@@ -24,7 +24,7 @@ class Delicious
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={})
27
+ def recent(options = {})
28
28
  options.merge!({basic_auth: @auth})
29
29
  self.class.get('/posts/recent', options)
30
30
  end