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.
- checksums.yaml +7 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +92 -0
- data/.rubocop_todo.yml +124 -0
- data/.simplecov +1 -0
- data/.travis.yml +5 -4
- data/CONTRIBUTING.md +23 -0
- data/Gemfile +9 -5
- data/Guardfile +3 -3
- data/History +109 -8
- data/README.md +21 -21
- data/Rakefile +5 -10
- data/bin/httparty +21 -14
- data/docs/README.md +100 -0
- data/examples/README.md +67 -0
- data/examples/aaws.rb +9 -9
- data/examples/basic.rb +6 -10
- data/examples/crack.rb +3 -3
- data/examples/custom_parsers.rb +1 -4
- data/examples/delicious.rb +12 -12
- data/examples/google.rb +2 -2
- data/examples/headers_and_user_agents.rb +2 -2
- data/examples/logging.rb +36 -0
- data/examples/nokogiri_html_parser.rb +0 -3
- data/examples/rescue_json.rb +17 -0
- data/examples/rubyurl.rb +3 -3
- data/examples/stackexchange.rb +24 -0
- data/examples/tripit_sign_in.rb +20 -9
- data/examples/twitter.rb +11 -11
- data/examples/whoismyrep.rb +2 -2
- data/features/command_line.feature +90 -2
- data/features/digest_authentication.feature +10 -0
- data/features/handles_compressed_responses.feature +8 -0
- data/features/handles_multiple_formats.feature +23 -0
- data/features/steps/env.rb +16 -11
- data/features/steps/httparty_response_steps.rb +40 -10
- data/features/steps/httparty_steps.rb +19 -3
- data/features/steps/mongrel_helper.rb +35 -2
- data/features/steps/remote_service_steps.rb +31 -8
- data/features/supports_read_timeout_option.feature +13 -0
- data/httparty.gemspec +9 -6
- data/lib/httparty/connection_adapter.rb +76 -11
- data/lib/httparty/cookie_hash.rb +3 -4
- data/lib/httparty/exceptions.rb +10 -4
- data/lib/httparty/hash_conversions.rb +19 -17
- data/lib/httparty/logger/apache_formatter.rb +22 -0
- data/lib/httparty/logger/curl_formatter.rb +91 -0
- data/lib/httparty/logger/logger.rb +26 -0
- data/lib/httparty/module_inheritable_attributes.rb +1 -1
- data/lib/httparty/net_digest_auth.rb +69 -18
- data/lib/httparty/parser.rb +15 -11
- data/lib/httparty/request.rb +186 -47
- data/lib/httparty/response/headers.rb +2 -2
- data/lib/httparty/response.rb +44 -9
- data/lib/httparty/version.rb +1 -1
- data/lib/httparty.rb +187 -65
- data/script/release +42 -0
- data/spec/fixtures/twitter.csv +2 -0
- data/spec/httparty/connection_adapter_spec.rb +334 -62
- data/spec/httparty/cookie_hash_spec.rb +53 -23
- data/spec/httparty/exception_spec.rb +45 -0
- data/spec/httparty/hash_conversions_spec.rb +49 -0
- data/spec/httparty/logger/apache_formatter_spec.rb +41 -0
- data/spec/httparty/logger/curl_formatter_spec.rb +119 -0
- data/spec/httparty/logger/logger_spec.rb +38 -0
- data/spec/httparty/net_digest_auth_spec.rb +148 -23
- data/spec/httparty/parser_spec.rb +48 -41
- data/spec/httparty/request_spec.rb +845 -151
- data/spec/httparty/response_spec.rb +147 -70
- data/spec/httparty/ssl_spec.rb +33 -21
- data/spec/httparty_spec.rb +337 -186
- data/spec/spec_helper.rb +38 -9
- data/spec/support/ssl_test_helper.rb +10 -10
- data/spec/support/ssl_test_server.rb +21 -21
- data/spec/support/stub_response.rb +20 -14
- data/website/index.html +3 -3
- metadata +46 -37
- data/lib/httparty/core_extensions.rb +0 -32
- data/spec/spec.opts +0 -2
@@ -1,64 +1,64 @@
|
|
1
1
|
require File.expand_path(File.join(File.dirname(__FILE__), '..', 'spec_helper'))
|
2
2
|
|
3
|
-
describe HTTParty::Parser do
|
3
|
+
RSpec.describe HTTParty::Parser do
|
4
4
|
describe ".SupportedFormats" do
|
5
5
|
it "returns a hash" do
|
6
|
-
HTTParty::Parser::SupportedFormats.
|
6
|
+
expect(HTTParty::Parser::SupportedFormats).to be_instance_of(Hash)
|
7
7
|
end
|
8
8
|
end
|
9
9
|
|
10
10
|
describe ".call" do
|
11
11
|
it "generates an HTTParty::Parser instance with the given body and format" do
|
12
|
-
HTTParty::Parser.
|
12
|
+
expect(HTTParty::Parser).to receive(:new).with('body', :plain).and_return(double(parse: nil))
|
13
13
|
HTTParty::Parser.call('body', :plain)
|
14
14
|
end
|
15
15
|
|
16
16
|
it "calls #parse on the parser" do
|
17
|
-
parser =
|
18
|
-
parser.
|
19
|
-
HTTParty::Parser.
|
17
|
+
parser = double('Parser')
|
18
|
+
expect(parser).to receive(:parse)
|
19
|
+
allow(HTTParty::Parser).to receive_messages(new: parser)
|
20
20
|
parser = HTTParty::Parser.call('body', :plain)
|
21
21
|
end
|
22
22
|
end
|
23
23
|
|
24
24
|
describe ".formats" do
|
25
25
|
it "returns the SupportedFormats constant" do
|
26
|
-
HTTParty::Parser.formats.
|
26
|
+
expect(HTTParty::Parser.formats).to eq(HTTParty::Parser::SupportedFormats)
|
27
27
|
end
|
28
28
|
|
29
29
|
it "returns the SupportedFormats constant for subclasses" do
|
30
30
|
class MyParser < HTTParty::Parser
|
31
31
|
SupportedFormats = {"application/atom+xml" => :atom}
|
32
32
|
end
|
33
|
-
MyParser.formats.
|
33
|
+
expect(MyParser.formats).to eq({"application/atom+xml" => :atom})
|
34
34
|
end
|
35
35
|
end
|
36
36
|
|
37
37
|
describe ".format_from_mimetype" do
|
38
38
|
it "returns a symbol representing the format mimetype" do
|
39
|
-
HTTParty::Parser.format_from_mimetype("text/plain").
|
39
|
+
expect(HTTParty::Parser.format_from_mimetype("text/plain")).to eq(:plain)
|
40
40
|
end
|
41
41
|
|
42
42
|
it "returns nil when the mimetype is not supported" do
|
43
|
-
HTTParty::Parser.format_from_mimetype("application/atom+xml").
|
43
|
+
expect(HTTParty::Parser.format_from_mimetype("application/atom+xml")).to be_nil
|
44
44
|
end
|
45
45
|
end
|
46
46
|
|
47
47
|
describe ".supported_formats" do
|
48
48
|
it "returns a unique set of supported formats represented by symbols" do
|
49
|
-
HTTParty::Parser.supported_formats.
|
49
|
+
expect(HTTParty::Parser.supported_formats).to eq(HTTParty::Parser::SupportedFormats.values.uniq)
|
50
50
|
end
|
51
51
|
end
|
52
52
|
|
53
53
|
describe ".supports_format?" do
|
54
54
|
it "returns true for a supported format" do
|
55
|
-
HTTParty::Parser.
|
56
|
-
HTTParty::Parser.supports_format?(:json).
|
55
|
+
allow(HTTParty::Parser).to receive_messages(supported_formats: [:json])
|
56
|
+
expect(HTTParty::Parser.supports_format?(:json)).to be_truthy
|
57
57
|
end
|
58
58
|
|
59
59
|
it "returns false for an unsupported format" do
|
60
|
-
HTTParty::Parser.
|
61
|
-
HTTParty::Parser.supports_format?(:json).
|
60
|
+
allow(HTTParty::Parser).to receive_messages(supported_formats: [])
|
61
|
+
expect(HTTParty::Parser.supports_format?(:json)).to be_falsey
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
@@ -68,40 +68,46 @@ describe HTTParty::Parser do
|
|
68
68
|
end
|
69
69
|
|
70
70
|
it "attempts to parse supported formats" do
|
71
|
-
@parser.
|
72
|
-
@parser.
|
71
|
+
allow(@parser).to receive_messages(supports_format?: true)
|
72
|
+
expect(@parser).to receive(:parse_supported_format)
|
73
73
|
@parser.parse
|
74
74
|
end
|
75
75
|
|
76
76
|
it "returns the unparsed body when the format is unsupported" do
|
77
|
-
@parser.
|
78
|
-
@parser.parse.
|
77
|
+
allow(@parser).to receive_messages(supports_format?: false)
|
78
|
+
expect(@parser.parse).to eq(@parser.body)
|
79
79
|
end
|
80
80
|
|
81
81
|
it "returns nil for an empty body" do
|
82
|
-
@parser.
|
83
|
-
@parser.parse.
|
82
|
+
allow(@parser).to receive_messages(body: '')
|
83
|
+
expect(@parser.parse).to be_nil
|
84
84
|
end
|
85
85
|
|
86
86
|
it "returns nil for a nil body" do
|
87
|
-
@parser.
|
88
|
-
@parser.parse.
|
87
|
+
allow(@parser).to receive_messages(body: nil)
|
88
|
+
expect(@parser.parse).to be_nil
|
89
89
|
end
|
90
90
|
|
91
91
|
it "returns nil for a 'null' body" do
|
92
|
-
@parser.
|
93
|
-
@parser.parse.
|
92
|
+
allow(@parser).to receive_messages(body: "null")
|
93
|
+
expect(@parser.parse).to be_nil
|
94
94
|
end
|
95
95
|
|
96
96
|
it "returns nil for a body with spaces only" do
|
97
|
-
@parser.
|
98
|
-
@parser.parse.
|
97
|
+
allow(@parser).to receive_messages(body: " ")
|
98
|
+
expect(@parser.parse).to be_nil
|
99
|
+
end
|
100
|
+
|
101
|
+
it "does not raise exceptions for bodies with invalid encodings" do
|
102
|
+
allow(@parser).to receive_messages(body: "\x80")
|
103
|
+
allow(@parser).to receive_messages(supports_format?: false)
|
104
|
+
expect(@parser.parse).to_not be_nil
|
99
105
|
end
|
100
106
|
end
|
101
107
|
|
102
108
|
describe "#supports_format?" do
|
103
109
|
it "utilizes the class method to determine if the format is supported" do
|
104
|
-
HTTParty::Parser.
|
110
|
+
expect(HTTParty::Parser).to receive(:supports_format?).with(:json)
|
105
111
|
parser = HTTParty::Parser.new('body', :json)
|
106
112
|
parser.send(:supports_format?)
|
107
113
|
end
|
@@ -110,7 +116,7 @@ describe HTTParty::Parser do
|
|
110
116
|
describe "#parse_supported_format" do
|
111
117
|
it "calls the parser for the given format" do
|
112
118
|
parser = HTTParty::Parser.new('body', :json)
|
113
|
-
parser.
|
119
|
+
expect(parser).to receive(:json)
|
114
120
|
parser.send(:parse_supported_format)
|
115
121
|
end
|
116
122
|
|
@@ -124,7 +130,9 @@ describe HTTParty::Parser do
|
|
124
130
|
|
125
131
|
it "raises a useful exception message for subclasses" do
|
126
132
|
atom_parser = Class.new(HTTParty::Parser) do
|
127
|
-
def self.name
|
133
|
+
def self.name
|
134
|
+
'AtomParser'
|
135
|
+
end
|
128
136
|
end
|
129
137
|
parser = atom_parser.new 'body', :atom
|
130
138
|
expect do
|
@@ -140,27 +148,26 @@ describe HTTParty::Parser do
|
|
140
148
|
end
|
141
149
|
|
142
150
|
it "parses xml with MultiXml" do
|
143
|
-
MultiXml.
|
151
|
+
expect(MultiXml).to receive(:parse).with('body')
|
144
152
|
subject.send(:xml)
|
145
153
|
end
|
146
154
|
|
147
|
-
it "parses json with
|
148
|
-
|
149
|
-
subject.send(:json)
|
150
|
-
end
|
151
|
-
|
152
|
-
it "uses MultiJson.decode if MultiJson does not respond to adapter" do
|
153
|
-
MultiJson.should_receive(:respond_to?).with(:adapter).and_return(false)
|
154
|
-
MultiJson.should_receive(:decode).with('body')
|
155
|
+
it "parses json with JSON" do
|
156
|
+
expect(JSON).to receive(:parse).with('body', :quirks_mode => true, :allow_nan => true)
|
155
157
|
subject.send(:json)
|
156
158
|
end
|
157
159
|
|
158
160
|
it "parses html by simply returning the body" do
|
159
|
-
subject.send(:html).
|
161
|
+
expect(subject.send(:html)).to eq('body')
|
160
162
|
end
|
161
163
|
|
162
164
|
it "parses plain text by simply returning the body" do
|
163
|
-
subject.send(:plain).
|
165
|
+
expect(subject.send(:plain)).to eq('body')
|
166
|
+
end
|
167
|
+
|
168
|
+
it "parses csv with CSV" do
|
169
|
+
expect(CSV).to receive(:parse).with('body')
|
170
|
+
subject.send(:csv)
|
164
171
|
end
|
165
172
|
end
|
166
173
|
end
|