kaiwren-patron 0.4.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,38 @@
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.dirname(__FILE__) + '/spec_helper.rb'
25
+
26
+ describe Patron do
27
+
28
+ it "should return the version number of the Patron library" do
29
+ version = Patron.version
30
+ version.should match(%r|^\d+.\d+.\d+$|)
31
+ end
32
+
33
+ it "should return the version number of the libcurl library" do
34
+ version = Patron.libcurl_version
35
+ version.should match(%r|^libcurl/\d+.\d+.\d+|)
36
+ end
37
+
38
+ end
@@ -0,0 +1,75 @@
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.dirname(__FILE__) + '/spec_helper.rb'
25
+
26
+
27
+ describe Patron::Request do
28
+
29
+ before(:each) do
30
+ @request = Patron::Request.new
31
+ end
32
+
33
+ describe :action do
34
+
35
+ it "should accept :get, :put, :post, :delete and :head" do
36
+ [:get, :put, :post, :delete, :head, :copy].each do |action|
37
+ lambda {@request.action = action}.should_not raise_error
38
+ end
39
+ end
40
+
41
+ it "should raise an exception when assigned a bad value" do
42
+ lambda {@request.action = :foo}.should raise_error(ArgumentError)
43
+ end
44
+
45
+ end
46
+
47
+ describe :timeout do
48
+
49
+ it "should raise an exception when assigned a negative number" do
50
+ lambda {@request.timeout = -1}.should raise_error(ArgumentError)
51
+ end
52
+
53
+ it "should raise an exception when assigned 0" do
54
+ lambda {@request.timeout = 0}.should raise_error(ArgumentError)
55
+ end
56
+
57
+ end
58
+
59
+ describe :max_redirects do
60
+
61
+ it "should raise an error when assigned an integer smaller than -1" do
62
+ lambda {@request.max_redirects = -2}.should raise_error(ArgumentError)
63
+ end
64
+
65
+ end
66
+
67
+ describe :headers do
68
+
69
+ it "should raise an error when assigned something other than a hash" do
70
+ lambda {@request.headers = :foo}.should raise_error(ArgumentError)
71
+ end
72
+
73
+ end
74
+
75
+ end
@@ -0,0 +1,45 @@
1
+ ## -------------------------------------------------------------------
2
+ ##
3
+ ## Copyright (c) 2009 Phillip Toland <phil.toland@gmail.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.dirname(__FILE__) + '/spec_helper.rb'
25
+ require 'webrick'
26
+ require 'base64'
27
+ require 'fileutils'
28
+
29
+ describe Patron::Response do
30
+ before(:each) do
31
+ @session = Patron::Session.new
32
+ @session.base_url = "http://localhost:9001"
33
+ end
34
+
35
+ it "should strip extra spaces from header values" do
36
+ response = @session.get("/test")
37
+ # All digits, no spaces
38
+ response.headers['Content-Length'].should match(/^\d+$/)
39
+ end
40
+
41
+ it "should combine header values sent in different fields with same name" do
42
+ response = @session.get("/repetitiveheader")
43
+ response.headers['Set-Cookie'].should == "a=1,b=2"
44
+ end
45
+ end
@@ -0,0 +1,215 @@
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.dirname(__FILE__) + '/spec_helper.rb'
25
+ require 'webrick'
26
+ require 'base64'
27
+ require 'fileutils'
28
+
29
+ describe Patron::Session do
30
+
31
+ before(:each) do
32
+ @session = Patron::Session.new
33
+ @session.base_url = "http://localhost:9001"
34
+ end
35
+
36
+ it "should escape and unescape strings symetrically" do
37
+ string = "foo~bar baz/"
38
+ escaped = @session.escape(string)
39
+ unescaped = @session.unescape(escaped)
40
+ unescaped.should == string
41
+ end
42
+
43
+ it "should raise an error when passed an invalid action" do
44
+ lambda { @session.request(:bogus, "/test", {}) }.should raise_error(ArgumentError)
45
+ end
46
+
47
+ it "should raise an error when no URL is provided" do
48
+ @session.base_url = nil
49
+ lambda {@session.get(nil)}.should raise_error(ArgumentError)
50
+ end
51
+
52
+ it "should retrieve a url with :get" do
53
+ response = @session.get("/test")
54
+ body = YAML::load(response.body)
55
+ body.request_method.should == "GET"
56
+ end
57
+
58
+ it "should download content with :get and a file path" do
59
+ tmpfile = "/tmp/patron_test.yaml"
60
+ response = @session.get_file "/test", tmpfile
61
+ response.body.should be_nil
62
+ body = YAML::load_file(tmpfile)
63
+ body.request_method.should == "GET"
64
+ FileUtils.rm tmpfile
65
+ end
66
+
67
+ it "should include custom headers in a request" do
68
+ response = @session.get("/test", {"User-Agent" => "PatronTest"})
69
+ body = YAML::load(response.body)
70
+ body.header["user-agent"].should == ["PatronTest"]
71
+ end
72
+
73
+ it "should merge custom headers with session headers" do
74
+ @session.headers["X-Test"] = "Testing"
75
+ response = @session.get("/test", {"User-Agent" => "PatronTest"})
76
+ body = YAML::load(response.body)
77
+ body.header["user-agent"].should == ["PatronTest"]
78
+ body.header["x-test"].should == ["Testing"]
79
+ end
80
+
81
+ it "should raise an exception on timeout" do
82
+ @session.timeout = 1
83
+ lambda {@session.get("/timeout")}.should raise_error(Patron::TimeoutError)
84
+ end
85
+
86
+ it "should follow redirects by default" do
87
+ @session.max_redirects = 1
88
+ response = @session.get("/redirect")
89
+ body = YAML::load(response.body)
90
+ response.status.should == 200
91
+ body.path.should == "/test"
92
+ end
93
+
94
+ it "should include redirect count in response" do
95
+ @session.max_redirects = 1
96
+ response = @session.get("/redirect")
97
+ response.redirect_count.should == 1
98
+ end
99
+
100
+ it "should not follow redirects when configured to do so" do
101
+ @session.max_redirects = 0
102
+ response = @session.get("/redirect")
103
+ response.status.should == 301
104
+ response.body.should be_empty
105
+ end
106
+
107
+ it "should retrieve URL metadata with :head" do
108
+ response = @session.head("/test")
109
+ response.status.should == 200
110
+ response.body.should be_empty
111
+ response.headers.should_not be_empty
112
+ end
113
+
114
+ it "should send a delete request with :delete" do
115
+ response = @session.delete("/test")
116
+ body = YAML::load(response.body)
117
+ body.request_method.should == "DELETE"
118
+ end
119
+
120
+ it "should send a COPY request with :copy" do
121
+ response = @session.copy("/test", "/test2")
122
+ body = YAML::load(response.body)
123
+ body.request_method.should == "COPY"
124
+ end
125
+
126
+ it "should include a Destination header in COPY requests" do
127
+ response = @session.copy("/test", "/test2")
128
+ body = YAML::load(response.body)
129
+ body.header['destination'].first.should == "/test2"
130
+ end
131
+
132
+ it "should upload data with :put" do
133
+ data = "upload data"
134
+ response = @session.put("/test", data)
135
+ body = YAML::load(response.body)
136
+ body.request_method.should == "PUT"
137
+ body.header['content-length'].should == [data.size.to_s]
138
+ end
139
+
140
+ it "should raise when no data is provided to :put" do
141
+ lambda { @session.put("/test", nil) }.should raise_error(ArgumentError)
142
+ end
143
+
144
+ it "should upload a file with :put" do
145
+ response = @session.put_file("/test", "VERSION.yml")
146
+ body = YAML::load(response.body)
147
+ body.request_method.should == "PUT"
148
+ end
149
+
150
+ it "should raise when no file is provided to :put" do
151
+ lambda { @session.put_file("/test", nil) }.should raise_error(ArgumentError)
152
+ end
153
+
154
+ it "should use chunked encoding when uploading a file with :put" do
155
+ response = @session.put_file("/test", "VERSION.yml")
156
+ body = YAML::load(response.body)
157
+ body.header['transfer-encoding'].first.should == "chunked"
158
+ end
159
+
160
+ it "should upload data with :post" do
161
+ data = "upload data"
162
+ response = @session.post("/test", data)
163
+ body = YAML::load(response.body)
164
+ body.request_method.should == "POST"
165
+ body.header['content-length'].should == [data.size.to_s]
166
+ end
167
+
168
+ it "should raise when no data is provided to :post" do
169
+ lambda { @session.post("/test", nil) }.should raise_error(ArgumentError)
170
+ end
171
+
172
+ it "should upload a file with :post" do
173
+ response = @session.post_file("/test", "VERSION.yml")
174
+ body = YAML::load(response.body)
175
+ body.request_method.should == "POST"
176
+ end
177
+
178
+ it "should raise when no file is provided to :post" do
179
+ lambda { @session.post_file("/test", nil) }.should raise_error(ArgumentError)
180
+ end
181
+
182
+ it "should use chunked encoding when uploading a file with :post" do
183
+ response = @session.post_file("/test", "VERSION.yml")
184
+ body = YAML::load(response.body)
185
+ body.header['transfer-encoding'].first.should == "chunked"
186
+ end
187
+
188
+ it "should pass credentials as http basic auth" do
189
+ @session.username = "foo"
190
+ @session.password = "bar"
191
+ response = @session.get("/test")
192
+ body = YAML::load(response.body)
193
+ body.header['authorization'].should == [encode_authz("foo", "bar")]
194
+ end
195
+
196
+ it "should handle cookies if set" do
197
+ @session.handle_cookies
198
+ response = @session.get("/setcookie").body
199
+ YAML::load(response).header['cookie'].first.should == "session_id=foo123"
200
+ end
201
+
202
+ it "should not handle cookies by default" do
203
+ response = @session.get("/setcookie").body
204
+ YAML::load(response).header.should_not include('cookie')
205
+ end
206
+
207
+ it "should raise exception if cookie store is not writable or readable" do
208
+ lambda { @session.handle_cookies("/trash/clash/foo") }.should raise_error(ArgumentError)
209
+ end
210
+
211
+ def encode_authz(user, passwd)
212
+ "Basic " + Base64.encode64("#{user}:#{passwd}").strip
213
+ end
214
+
215
+ end
@@ -0,0 +1,6 @@
1
+ --colour
2
+ --format
3
+ progress
4
+ --loadby
5
+ mtime
6
+ --reverse
@@ -0,0 +1,36 @@
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 'test/unit'
25
+
26
+ begin
27
+ require 'spec'
28
+ rescue LoadError
29
+ require 'rubygems'
30
+ gem 'rspec'
31
+ require 'spec'
32
+ end
33
+
34
+ $:.unshift(File.dirname(__FILE__) + '/../lib')
35
+ $:.unshift(File.dirname(__FILE__) + '/../ext')
36
+ require 'patron'
metadata ADDED
@@ -0,0 +1,86 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: kaiwren-patron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.4
5
+ platform: ruby
6
+ authors:
7
+ - Phillip Toland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-12-07 00:00:00 +05:30
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Ruby HTTP client library based on libcurl
17
+ email: phil.toland@gmail.com
18
+ executables: []
19
+
20
+ extensions:
21
+ - ext/patron/extconf.rb
22
+ - ext/patron/extconf.rb
23
+ extra_rdoc_files:
24
+ - README.txt
25
+ files:
26
+ - LICENSE
27
+ - README.txt
28
+ - Rakefile
29
+ - VERSION.yml
30
+ - ext/patron/extconf.rb
31
+ - ext/patron/session_ext.c
32
+ - lib/patron.rb
33
+ - lib/patron/error.rb
34
+ - lib/patron/request.rb
35
+ - lib/patron/response.rb
36
+ - lib/patron/session.rb
37
+ - spec/patron_spec.rb
38
+ - spec/request_spec.rb
39
+ - spec/response_spec.rb
40
+ - spec/session_spec.rb
41
+ - spec/spec.opts
42
+ - spec/spec_helper.rb
43
+ has_rdoc: true
44
+ homepage: http://github.com/toland/Patron
45
+ licenses: []
46
+
47
+ post_install_message:
48
+ rdoc_options:
49
+ - --quiet
50
+ - --title
51
+ - Patron documentation
52
+ - --opname
53
+ - index.html
54
+ - --line-numbers
55
+ - --main
56
+ - README.txt
57
+ - --inline-source
58
+ require_paths:
59
+ - lib
60
+ - ext
61
+ - ext
62
+ required_ruby_version: !ruby/object:Gem::Requirement
63
+ requirements:
64
+ - - ">="
65
+ - !ruby/object:Gem::Version
66
+ version: "0"
67
+ version:
68
+ required_rubygems_version: !ruby/object:Gem::Requirement
69
+ requirements:
70
+ - - ">="
71
+ - !ruby/object:Gem::Version
72
+ version: "0"
73
+ version:
74
+ requirements: []
75
+
76
+ rubyforge_project: patron
77
+ rubygems_version: 1.3.5
78
+ signing_key:
79
+ specification_version: 3
80
+ summary: Patron HTTP client
81
+ test_files:
82
+ - spec/patron_spec.rb
83
+ - spec/request_spec.rb
84
+ - spec/response_spec.rb
85
+ - spec/session_spec.rb
86
+ - spec/spec_helper.rb