httparty 0.9.0 → 0.10.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.
- data/History +4 -0
- data/examples/custom_parsers.rb +1 -1
- data/lib/httparty.rb +14 -1
- data/lib/httparty/connection_adapter.rb +19 -1
- data/lib/httparty/module_inheritable_attributes.rb +18 -6
- data/lib/httparty/parser.rb +1 -7
- data/lib/httparty/request.rb +13 -4
- data/lib/httparty/version.rb +1 -1
- data/spec/httparty/connection_adapter_spec.rb +17 -0
- data/spec/httparty/parser_spec.rb +0 -5
- data/spec/httparty/request_spec.rb +0 -6
- data/spec/httparty_spec.rb +27 -9
- metadata +8 -8
data/History
CHANGED
data/examples/custom_parsers.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
class ParseAtom
|
2
2
|
include HTTParty
|
3
3
|
|
4
|
-
# Support Atom along with the default parsers: xml, json,
|
4
|
+
# Support Atom along with the default parsers: xml, json, etc.
|
5
5
|
class Parser::Atom < HTTParty::Parser
|
6
6
|
SupportedFormats.merge!({"application/atom+xml" => :atom})
|
7
7
|
|
data/lib/httparty.rb
CHANGED
@@ -299,7 +299,7 @@ module HTTParty
|
|
299
299
|
default_options[:query_string_normalizer] = normalizer
|
300
300
|
end
|
301
301
|
|
302
|
-
# Allows setting of SSL version to use. This only works in Ruby 1.9
|
302
|
+
# Allows setting of SSL version to use. This only works in Ruby 1.9+.
|
303
303
|
# You can get a list of valid versions from OpenSSL::SSL::SSLContext::METHODS.
|
304
304
|
#
|
305
305
|
# class Foo
|
@@ -310,6 +310,19 @@ module HTTParty
|
|
310
310
|
default_options[:ssl_version] = version
|
311
311
|
end
|
312
312
|
|
313
|
+
# Allows setting of SSL ciphers to use. This only works in Ruby 1.9+.
|
314
|
+
# You can get a list of valid specific ciphers from OpenSSL::Cipher.ciphers.
|
315
|
+
# You also can specify a cipher suite here, listed here at openssl.org:
|
316
|
+
# http://www.openssl.org/docs/apps/ciphers.html#CIPHER_SUITE_NAMES
|
317
|
+
#
|
318
|
+
# class Foo
|
319
|
+
# include HTTParty
|
320
|
+
# ciphers "RC4-SHA"
|
321
|
+
# end
|
322
|
+
def ciphers(cipher_names)
|
323
|
+
default_options[:ciphers] = cipher_names
|
324
|
+
end
|
325
|
+
|
313
326
|
# Allows setting an OpenSSL certificate authority file
|
314
327
|
#
|
315
328
|
# class Foo
|
@@ -47,6 +47,10 @@ module HTTParty
|
|
47
47
|
# * :+connection_adapter_options+: contains the hash your passed to HTTParty.connection_adapter when you configured your connection adapter
|
48
48
|
class ConnectionAdapter
|
49
49
|
|
50
|
+
# Private: Regex used to strip brackets from IPv6 URIs.
|
51
|
+
StripIpv6BracketsRegex = /\A\[(.*)\]\z/
|
52
|
+
|
53
|
+
# Public
|
50
54
|
def self.call(uri, options)
|
51
55
|
new(uri, options).connection
|
52
56
|
end
|
@@ -61,7 +65,8 @@ module HTTParty
|
|
61
65
|
end
|
62
66
|
|
63
67
|
def connection
|
64
|
-
|
68
|
+
host = clean_host(uri.host)
|
69
|
+
http = Net::HTTP.new(host, uri.port, options[:http_proxyaddr], options[:http_proxyport], options[:http_proxyuser], options[:http_proxypass])
|
65
70
|
|
66
71
|
http.use_ssl = ssl_implied?(uri)
|
67
72
|
|
@@ -76,10 +81,23 @@ module HTTParty
|
|
76
81
|
http.set_debug_output(options[:debug_output])
|
77
82
|
end
|
78
83
|
|
84
|
+
if options[:ciphers]
|
85
|
+
http.ciphers = options[:ciphers]
|
86
|
+
end
|
87
|
+
|
79
88
|
return http
|
80
89
|
end
|
81
90
|
|
82
91
|
private
|
92
|
+
|
93
|
+
def clean_host(host)
|
94
|
+
strip_ipv6_brackets(host)
|
95
|
+
end
|
96
|
+
|
97
|
+
def strip_ipv6_brackets(host)
|
98
|
+
StripIpv6BracketsRegex =~ host ? $1 : host
|
99
|
+
end
|
100
|
+
|
83
101
|
def ssl_implied?(uri)
|
84
102
|
uri.port == 443 || uri.instance_of?(URI::HTTPS)
|
85
103
|
end
|
@@ -5,12 +5,19 @@ module HTTParty
|
|
5
5
|
end
|
6
6
|
|
7
7
|
# borrowed from Rails 3.2 ActiveSupport
|
8
|
-
def self.hash_deep_dup(
|
9
|
-
duplicate =
|
10
|
-
|
11
|
-
|
12
|
-
duplicate[
|
8
|
+
def self.hash_deep_dup(hash)
|
9
|
+
duplicate = hash.dup
|
10
|
+
|
11
|
+
duplicate.each_pair do |key, value|
|
12
|
+
duplicate[key] = if value.is_a?(Hash)
|
13
|
+
hash_deep_dup(value)
|
14
|
+
elsif value.is_a?(Proc)
|
15
|
+
duplicate[key] = value.dup
|
16
|
+
else
|
17
|
+
value
|
18
|
+
end
|
13
19
|
end
|
20
|
+
|
14
21
|
duplicate
|
15
22
|
end
|
16
23
|
|
@@ -18,9 +25,11 @@ module HTTParty
|
|
18
25
|
def mattr_inheritable(*args)
|
19
26
|
@mattr_inheritable_attrs ||= [:mattr_inheritable_attrs]
|
20
27
|
@mattr_inheritable_attrs += args
|
28
|
+
|
21
29
|
args.each do |arg|
|
22
30
|
module_eval %(class << self; attr_accessor :#{arg} end)
|
23
31
|
end
|
32
|
+
|
24
33
|
@mattr_inheritable_attrs
|
25
34
|
end
|
26
35
|
|
@@ -29,12 +38,15 @@ module HTTParty
|
|
29
38
|
@mattr_inheritable_attrs.each do |inheritable_attribute|
|
30
39
|
ivar = "@#{inheritable_attribute}"
|
31
40
|
subclass.instance_variable_set(ivar, instance_variable_get(ivar).clone)
|
41
|
+
|
32
42
|
if instance_variable_get(ivar).respond_to?(:merge)
|
33
43
|
method = <<-EOM
|
34
44
|
def self.#{inheritable_attribute}
|
35
|
-
|
45
|
+
duplicate = ModuleInheritableAttributes.hash_deep_dup(#{ivar})
|
46
|
+
#{ivar} = superclass.#{inheritable_attribute}.merge(duplicate)
|
36
47
|
end
|
37
48
|
EOM
|
49
|
+
|
38
50
|
subclass.class_eval method
|
39
51
|
end
|
40
52
|
end
|
data/lib/httparty/parser.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
module HTTParty
|
2
|
-
# The default parser used by HTTParty, supports xml, json, html,
|
2
|
+
# The default parser used by HTTParty, supports xml, json, html, and
|
3
3
|
# plain text.
|
4
4
|
#
|
5
5
|
# == Custom Parsers
|
@@ -45,8 +45,6 @@ module HTTParty
|
|
45
45
|
'application/javascript' => :json,
|
46
46
|
'text/javascript' => :json,
|
47
47
|
'text/html' => :html,
|
48
|
-
'application/x-yaml' => :yaml,
|
49
|
-
'text/yaml' => :yaml,
|
50
48
|
'text/plain' => :plain
|
51
49
|
}
|
52
50
|
|
@@ -120,10 +118,6 @@ module HTTParty
|
|
120
118
|
end
|
121
119
|
end
|
122
120
|
|
123
|
-
def yaml
|
124
|
-
YAML.load(body)
|
125
|
-
end
|
126
|
-
|
127
121
|
def html
|
128
122
|
body
|
129
123
|
end
|
data/lib/httparty/request.rb
CHANGED
@@ -10,7 +10,7 @@ module HTTParty
|
|
10
10
|
Net::HTTP::Options
|
11
11
|
]
|
12
12
|
|
13
|
-
SupportedURISchemes = [URI::HTTP, URI::HTTPS]
|
13
|
+
SupportedURISchemes = [URI::HTTP, URI::HTTPS, URI::Generic]
|
14
14
|
|
15
15
|
NON_RAILS_QUERY_STRING_NORMALIZER = Proc.new do |query|
|
16
16
|
Array(query).map do |key, value|
|
@@ -24,7 +24,8 @@ module HTTParty
|
|
24
24
|
end.flatten.sort.join('&')
|
25
25
|
end
|
26
26
|
|
27
|
-
attr_accessor :http_method, :
|
27
|
+
attr_accessor :http_method, :options, :last_response, :redirect, :last_uri
|
28
|
+
attr_reader :path
|
28
29
|
|
29
30
|
def initialize(http_method, path, o={})
|
30
31
|
self.http_method = http_method
|
@@ -42,6 +43,14 @@ module HTTParty
|
|
42
43
|
@path = URI.parse(uri)
|
43
44
|
end
|
44
45
|
|
46
|
+
def request_uri(uri)
|
47
|
+
if uri.respond_to? :request_uri
|
48
|
+
uri.request_uri
|
49
|
+
else
|
50
|
+
uri.path
|
51
|
+
end
|
52
|
+
end
|
53
|
+
|
45
54
|
def uri
|
46
55
|
new_uri = path.relative? ? URI.parse("#{base_uri}#{path}") : path
|
47
56
|
|
@@ -51,7 +60,7 @@ module HTTParty
|
|
51
60
|
end
|
52
61
|
|
53
62
|
unless SupportedURISchemes.include? new_uri.class
|
54
|
-
raise UnsupportedURIScheme, "'#{new_uri}' Must be HTTP or
|
63
|
+
raise UnsupportedURIScheme, "'#{new_uri}' Must be HTTP, HTTPS or Generic"
|
55
64
|
end
|
56
65
|
|
57
66
|
@last_uri = new_uri
|
@@ -130,7 +139,7 @@ module HTTParty
|
|
130
139
|
end
|
131
140
|
|
132
141
|
def setup_raw_request
|
133
|
-
@raw_request = http_method.new(uri
|
142
|
+
@raw_request = http_method.new(request_uri(uri))
|
134
143
|
@raw_request.body = body if body
|
135
144
|
@raw_request.initialize_http_header(options[:headers])
|
136
145
|
@raw_request.basic_auth(username, password) if options[:basic_auth]
|
data/lib/httparty/version.rb
CHANGED
@@ -78,6 +78,7 @@ describe HTTParty::ConnectionAdapter do
|
|
78
78
|
it { should use_ssl }
|
79
79
|
end
|
80
80
|
|
81
|
+
|
81
82
|
context "when ssl version is set" do
|
82
83
|
let(:options) { {:ssl_version => :TLSv1} }
|
83
84
|
|
@@ -87,6 +88,22 @@ describe HTTParty::ConnectionAdapter do
|
|
87
88
|
end if RUBY_VERSION > '1.9'
|
88
89
|
end
|
89
90
|
|
91
|
+
context "when dealing with IPv6" do
|
92
|
+
let(:uri) { URI 'http://[fd00::1]' }
|
93
|
+
|
94
|
+
it "strips brackets from the address" do
|
95
|
+
subject.address.should == 'fd00::1'
|
96
|
+
end
|
97
|
+
end
|
98
|
+
|
99
|
+
context "specifying ciphers" do
|
100
|
+
let(:options) { {:ciphers => 'RC4-SHA' } }
|
101
|
+
|
102
|
+
it "should set the ciphers on the connection" do
|
103
|
+
subject.ciphers.should == 'RC4-SHA'
|
104
|
+
end
|
105
|
+
end if RUBY_VERSION > '1.9'
|
106
|
+
|
90
107
|
context "when timeout is not set" do
|
91
108
|
it "doesn't set the timeout" do
|
92
109
|
http = mock("http", :null_object => true)
|
@@ -155,11 +155,6 @@ describe HTTParty::Parser do
|
|
155
155
|
subject.send(:json)
|
156
156
|
end
|
157
157
|
|
158
|
-
it "parses yaml" do
|
159
|
-
YAML.should_receive(:load).with('body')
|
160
|
-
subject.send(:yaml)
|
161
|
-
end
|
162
|
-
|
163
158
|
it "parses html by simply returning the body" do
|
164
159
|
subject.send(:html).should == 'body'
|
165
160
|
end
|
@@ -225,12 +225,6 @@ describe HTTParty::Request do
|
|
225
225
|
@request.send(:parse_response, json).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
|
226
226
|
end
|
227
227
|
|
228
|
-
it 'should handle yaml automatically' do
|
229
|
-
yaml = "books: \n book: \n name: Foo Bar!\n id: \"1234\"\n"
|
230
|
-
@request.options[:format] = :yaml
|
231
|
-
@request.send(:parse_response, yaml).should == {'books' => {'book' => {'id' => '1234', 'name' => 'Foo Bar!'}}}
|
232
|
-
end
|
233
|
-
|
234
228
|
it "should include any HTTP headers in the returned response" do
|
235
229
|
@request.options[:format] = :html
|
236
230
|
response = stub_response "Content"
|
data/spec/httparty_spec.rb
CHANGED
@@ -45,6 +45,14 @@ describe HTTParty do
|
|
45
45
|
end
|
46
46
|
end
|
47
47
|
|
48
|
+
describe 'ciphers' do
|
49
|
+
it 'should set the ciphers content' do
|
50
|
+
@klass.default_options[:ciphers].should be_nil
|
51
|
+
@klass.ciphers 'RC4-SHA'
|
52
|
+
@klass.default_options[:ciphers].should == 'RC4-SHA'
|
53
|
+
end
|
54
|
+
end
|
55
|
+
|
48
56
|
describe 'http_proxy' do
|
49
57
|
it 'should set the address' do
|
50
58
|
@klass.http_proxy 'proxy.foo.com', 80
|
@@ -376,11 +384,6 @@ describe HTTParty do
|
|
376
384
|
@klass.default_options[:format].should == :json
|
377
385
|
end
|
378
386
|
|
379
|
-
it "should allow yaml" do
|
380
|
-
@klass.format :yaml
|
381
|
-
@klass.default_options[:format].should == :yaml
|
382
|
-
end
|
383
|
-
|
384
387
|
it "should allow plain" do
|
385
388
|
@klass.format :plain
|
386
389
|
@klass.default_options[:format].should == :plain
|
@@ -395,7 +398,7 @@ describe HTTParty do
|
|
395
398
|
it 'should only print each format once with an exception' do
|
396
399
|
lambda do
|
397
400
|
@klass.format :foobar
|
398
|
-
end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: html, json, plain, xml
|
401
|
+
end.should raise_error(HTTParty::UnsupportedFormat, "':foobar' Must be one of: html, json, plain, xml")
|
399
402
|
end
|
400
403
|
|
401
404
|
it 'sets the default parser' do
|
@@ -578,6 +581,20 @@ describe HTTParty do
|
|
578
581
|
@child1.default_options[:headers].should == {'Accept' => 'application/xml'}
|
579
582
|
end
|
580
583
|
|
584
|
+
it "works with lambda values" do
|
585
|
+
@child1.default_options[:imaginary_option] = lambda { "This is a new lambda "}
|
586
|
+
@child1.default_options[:imaginary_option].should be_a Proc
|
587
|
+
end
|
588
|
+
|
589
|
+
it 'should dup the proc on the child class' do
|
590
|
+
imaginary_option = lambda { "This is a new lambda" }
|
591
|
+
@parent.default_options[:imaginary_option] = imaginary_option
|
592
|
+
@parent.default_options[:imaginary_option].should be_equal imaginary_option
|
593
|
+
@child1.default_options[:imaginary_option]
|
594
|
+
@child1.default_options[:imaginary_option].should == imaginary_option
|
595
|
+
@child1.default_options[:imaginary_option].should_not be_equal imaginary_option
|
596
|
+
end
|
597
|
+
|
581
598
|
it "inherits default_cookies from the parent class" do
|
582
599
|
@parent.cookies 'type' => 'chocolate_chip'
|
583
600
|
@child1.default_cookies.should == {"type" => "chocolate_chip"}
|
@@ -688,10 +705,11 @@ describe HTTParty do
|
|
688
705
|
end.should_not raise_error(HTTParty::UnsupportedURIScheme)
|
689
706
|
end
|
690
707
|
|
691
|
-
it "should
|
708
|
+
it "should accept webcal URIs" do
|
709
|
+
stub_http_response_with('google.html')
|
692
710
|
lambda do
|
693
|
-
HTTParty.get(
|
694
|
-
end.
|
711
|
+
HTTParty.get('webcal://google.com')
|
712
|
+
end.should_not raise_error(HTTParty::UnsupportedURIScheme)
|
695
713
|
end
|
696
714
|
|
697
715
|
it "should raise an InvalidURIError on URIs that can't be parsed at all" do
|
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.
|
4
|
+
version: 0.10.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date:
|
13
|
+
date: 2013-01-10 00:00:00.000000000 Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: multi_json
|
17
|
-
requirement: &
|
17
|
+
requirement: &70244756875780 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ~>
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '1.0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70244756875780
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: multi_xml
|
28
|
-
requirement: &
|
28
|
+
requirement: &70244756914000 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,7 +33,7 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70244756914000
|
37
37
|
description: Makes http fun! Also, makes consuming restful web services dead easy.
|
38
38
|
email:
|
39
39
|
- nunemaker@gmail.com
|
@@ -135,7 +135,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
135
135
|
version: '0'
|
136
136
|
segments:
|
137
137
|
- 0
|
138
|
-
hash: -
|
138
|
+
hash: -707685205189815714
|
139
139
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
140
140
|
none: false
|
141
141
|
requirements:
|
@@ -144,7 +144,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
144
|
version: '0'
|
145
145
|
segments:
|
146
146
|
- 0
|
147
|
-
hash: -
|
147
|
+
hash: -707685205189815714
|
148
148
|
requirements: []
|
149
149
|
rubyforge_project:
|
150
150
|
rubygems_version: 1.8.10
|