patron 0.4.11 → 0.4.12

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- patron (0.4.10)
4
+ patron (0.4.12)
5
5
 
6
6
  GEM
7
7
  remote: http://rubygems.org/
@@ -29,6 +29,8 @@ end
29
29
  require 'mkmf'
30
30
  require 'rbconfig'
31
31
 
32
+ dir_config('curl')
33
+
32
34
  if find_executable('curl-config')
33
35
  $CFLAGS << " #{`curl-config --cflags`.strip}"
34
36
  $LIBS << " #{`curl-config --libs`.strip}"
@@ -23,7 +23,7 @@
23
23
  ##
24
24
  ## -------------------------------------------------------------------
25
25
 
26
- require 'cgi'
26
+ require 'patron/util'
27
27
 
28
28
  module Patron
29
29
 
@@ -71,7 +71,7 @@ module Patron
71
71
  def upload_data=(data)
72
72
  @upload_data = case data
73
73
  when Hash
74
- self.multipart ? data : hash_to_string(data)
74
+ self.multipart ? data : Util.build_query_string_from_hash(data, @action == :post)
75
75
  else
76
76
  data
77
77
  end
@@ -138,20 +138,5 @@ module Patron
138
138
  "#{username}:#{password}"
139
139
  end
140
140
 
141
- private
142
-
143
- # serialize hash for Rails-style params
144
- def hash_to_string(hash)
145
- pairs = []
146
- recursive = Proc.new do |h, prefix|
147
- h.each_pair do |k,v|
148
- key = prefix == '' ? k : "#{prefix}[#{k}]"
149
- @action == :post ? v = CGI::escape(v.to_s) : v
150
- v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
151
- end
152
- end
153
- recursive.call(hash, '')
154
- return pairs.join('&')
155
- end
156
141
  end
157
142
  end
@@ -22,11 +22,13 @@
22
22
  ## THE SOFTWARE.
23
23
  ##
24
24
  ## -------------------------------------------------------------------
25
+
26
+ require 'uri'
25
27
  require 'patron/error'
26
28
  require 'patron/request'
27
29
  require 'patron/response'
28
30
  require 'patron/session_ext'
29
-
31
+ require 'patron/util'
30
32
 
31
33
  module Patron
32
34
 
@@ -196,8 +198,15 @@ module Patron
196
198
  req.insecure = insecure
197
199
  req.buffer_size = buffer_size
198
200
 
199
- req.url = self.base_url.to_s + url.to_s
200
- raise ArgumentError, "Empty URL" if req.url.empty?
201
+ url = self.base_url.to_s + url.to_s
202
+ uri = URI.parse(url)
203
+ query = uri.query.to_s.split('&')
204
+ query += options[:query].is_a?(Hash) ? Util.build_query_pairs_from_hash(options[:query]) : options[:query].to_s.split('&')
205
+ uri.query = query.join('&')
206
+ uri.query = nil if uri.query.empty?
207
+ url = uri.to_s
208
+ raise ArgumentError, "Empty URL" if url.empty?
209
+ req.url = url
201
210
 
202
211
  handle_request(req)
203
212
  end
@@ -0,0 +1,50 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Patron HTTP Client: Request class
4
+ ## Copyright (c) 2008 The Hive http://www.thehive.com/
5
+ ##
6
+ ## Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ ## of this software and associated documentation files (the "Software"), to deal
8
+ ## in the Software without restriction, including without limitation the rights
9
+ ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ ## copies of the Software, and to permit persons to whom the Software is
11
+ ## furnished to do so, subject to the following conditions:
12
+ ##
13
+ ## The above copyright notice and this permission notice shall be included in
14
+ ## all copies or substantial portions of the Software.
15
+ ##
16
+ ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
22
+ ## THE SOFTWARE.
23
+ ##
24
+ ## -------------------------------------------------------------------
25
+
26
+ require 'cgi'
27
+
28
+ module Patron
29
+ module Util
30
+ extend self
31
+
32
+ def build_query_pairs_from_hash(hash, escape_values=false)
33
+ pairs = []
34
+ recursive = Proc.new do |h, prefix|
35
+ h.each_pair do |k,v|
36
+ key = prefix == '' ? k : "#{prefix}[#{k}]"
37
+ v = CGI::escape(v.to_s) if escape_values
38
+ v.is_a?(Hash) ? recursive.call(v, key) : pairs << "#{key}=#{v}"
39
+ end
40
+ end
41
+ recursive.call(hash, '')
42
+ pairs
43
+ end
44
+
45
+ def build_query_string_from_hash(hash, escape_values=false)
46
+ build_query_pairs_from_hash(hash, escape_values).join('&')
47
+ end
48
+
49
+ end
50
+ end
@@ -1,3 +1,3 @@
1
1
  module Patron
2
- VERSION = "0.4.11"
2
+ VERSION = "0.4.12"
3
3
  end
@@ -243,6 +243,20 @@ describe Patron::Session do
243
243
 
244
244
  body.request_method.should == "GET"
245
245
  end
246
+
247
+ it "should serialize query params and append them to the url" do
248
+ response = @session.request(:get, "/test", {}, :query => {:foo => "bar"})
249
+ request = YAML::load(response.body)
250
+ request.parse
251
+ (request.path + '?' + request.query_string).should == "/test?foo=bar"
252
+ end
253
+
254
+ it "should merge parameters in the :query option with pre-existing query parameters" do
255
+ response = @session.request(:get, "/test?foo=bar", {}, :query => {:baz => "quux"})
256
+ request = YAML::load(response.body)
257
+ request.parse
258
+ (request.path + '?' + request.query_string).should == "/test?foo=bar&baz=quux"
259
+ end
246
260
 
247
261
  def encode_authz(user, passwd)
248
262
  "Basic " + Base64.encode64("#{user}:#{passwd}").strip
@@ -0,0 +1,92 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) 2008 The Hive http://www.thehive.com/
4
+ ##
5
+ ## Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ ## of this software and associated documentation files (the "Software"), to deal
7
+ ## in the Software without restriction, including without limitation the rights
8
+ ## to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ ## copies of the Software, and to permit persons to whom the Software is
10
+ ## furnished to do so, subject to the following conditions:
11
+ ##
12
+ ## The above copyright notice and this permission notice shall be included in
13
+ ## all copies or substantial portions of the Software.
14
+ ##
15
+ ## THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ ## IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ ## FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ ## AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ ## LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ ## OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ ## THE SOFTWARE.
22
+ ##
23
+ ## -------------------------------------------------------------------
24
+ require File.expand_path("./spec") + '/spec_helper.rb'
25
+
26
+ describe Patron::Util do
27
+
28
+ describe :build_query_pairs_from_hash do
29
+ it "correctly serializes a simple hash" do
30
+ hash = {:foo => "bar", "baz" => 42}
31
+ array = Patron::Util.build_query_pairs_from_hash(hash)
32
+ array.size.should == 2
33
+ array.should include("foo=bar")
34
+ array.should include("baz=42")
35
+ end
36
+ it "correctly serializes a more complex hash" do
37
+ hash = {
38
+ :foo => "bar",
39
+ :baz => {
40
+ "quux" => {
41
+ :zing => {
42
+ :ying => 42
43
+ }
44
+ },
45
+ :blargh => {
46
+ :spaz => "sox",
47
+ :razz => "matazz"
48
+ }
49
+ }
50
+ }
51
+ array = Patron::Util.build_query_pairs_from_hash(hash)
52
+ array.size.should == 4
53
+ array.should include("foo=bar")
54
+ array.should include("baz[quux][zing][ying]=42")
55
+ array.should include("baz[blargh][spaz]=sox")
56
+ array.should include("baz[blargh][razz]=matazz")
57
+ end
58
+ end
59
+
60
+ describe :build_query_string_from_hash do
61
+ it "correctly serializes a simple hash" do
62
+ hash = {:foo => "bar", "baz" => 42}
63
+ array = Patron::Util.build_query_string_from_hash(hash).split('&')
64
+ array.size.should == 2
65
+ array.should include("foo=bar")
66
+ array.should include("baz=42")
67
+ end
68
+ it "correctly serializes a more complex hash" do
69
+ hash = {
70
+ :foo => "bar",
71
+ :baz => {
72
+ "quux" => {
73
+ :zing => {
74
+ :ying => 42
75
+ }
76
+ },
77
+ :blargh => {
78
+ :spaz => "sox",
79
+ :razz => "matazz"
80
+ }
81
+ }
82
+ }
83
+ array = Patron::Util.build_query_string_from_hash(hash).split('&')
84
+ array.size.should == 4
85
+ array.should include("foo=bar")
86
+ array.should include("baz[quux][zing][ying]=42")
87
+ array.should include("baz[blargh][spaz]=sox")
88
+ array.should include("baz[blargh][razz]=matazz")
89
+ end
90
+ end
91
+
92
+ end
metadata CHANGED
@@ -1,12 +1,8 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: patron
3
3
  version: !ruby/object:Gem::Version
4
- prerelease: false
5
- segments:
6
- - 0
7
- - 4
8
- - 11
9
- version: 0.4.11
4
+ prerelease:
5
+ version: 0.4.12
10
6
  platform: ruby
11
7
  authors:
12
8
  - Phillip Toland
@@ -14,7 +10,7 @@ autorequire:
14
10
  bindir: bin
15
11
  cert_chain: []
16
12
 
17
- date: 2010-12-31 00:00:00 -06:00
13
+ date: 2011-06-22 00:00:00 -05:00
18
14
  default_executable:
19
15
  dependencies:
20
16
  - !ruby/object:Gem::Dependency
@@ -25,10 +21,6 @@ dependencies:
25
21
  requirements:
26
22
  - - ">="
27
23
  - !ruby/object:Gem::Version
28
- segments:
29
- - 1
30
- - 0
31
- - 0
32
24
  version: 1.0.0
33
25
  type: :development
34
26
  version_requirements: *id001
@@ -40,10 +32,6 @@ dependencies:
40
32
  requirements:
41
33
  - - ~>
42
34
  - !ruby/object:Gem::Version
43
- segments:
44
- - 0
45
- - 7
46
- - 5
47
35
  version: 0.7.5
48
36
  type: :development
49
37
  version_requirements: *id002
@@ -55,10 +43,6 @@ dependencies:
55
43
  requirements:
56
44
  - - ~>
57
45
  - !ruby/object:Gem::Version
58
- segments:
59
- - 2
60
- - 3
61
- - 0
62
46
  version: 2.3.0
63
47
  type: :development
64
48
  version_requirements: *id003
@@ -70,10 +54,6 @@ dependencies:
70
54
  requirements:
71
55
  - - ~>
72
56
  - !ruby/object:Gem::Version
73
- segments:
74
- - 0
75
- - 9
76
- - 9
77
57
  version: 0.9.9
78
58
  type: :development
79
59
  version_requirements: *id004
@@ -105,6 +85,7 @@ files:
105
85
  - lib/patron/request.rb
106
86
  - lib/patron/response.rb
107
87
  - lib/patron/session.rb
88
+ - lib/patron/util.rb
108
89
  - lib/patron/version.rb
109
90
  - patron.gemspec
110
91
  - script/console
@@ -114,6 +95,7 @@ files:
114
95
  - spec/response_spec.rb
115
96
  - spec/session_spec.rb
116
97
  - spec/spec_helper.rb
98
+ - spec/util_spec.rb
117
99
  has_rdoc: true
118
100
  homepage: https://github.com/toland/patron
119
101
  licenses: []
@@ -129,23 +111,17 @@ required_ruby_version: !ruby/object:Gem::Requirement
129
111
  requirements:
130
112
  - - ">="
131
113
  - !ruby/object:Gem::Version
132
- segments:
133
- - 0
134
114
  version: "0"
135
115
  required_rubygems_version: !ruby/object:Gem::Requirement
136
116
  none: false
137
117
  requirements:
138
118
  - - ">="
139
119
  - !ruby/object:Gem::Version
140
- segments:
141
- - 1
142
- - 3
143
- - 6
144
120
  version: 1.3.6
145
121
  requirements: []
146
122
 
147
123
  rubyforge_project: patron
148
- rubygems_version: 1.3.7
124
+ rubygems_version: 1.6.2
149
125
  signing_key:
150
126
  specification_version: 3
151
127
  summary: Patron HTTP Client