jameskilton-patron 0.4.3

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,40 @@
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
+ end
@@ -0,0 +1,199 @@
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 upload a file with :put" do
141
+ response = @session.put_file("/test", "VERSION.yml")
142
+ body = YAML::load(response.body)
143
+ body.request_method.should == "PUT"
144
+ end
145
+
146
+ it "should use chunked encoding when uploading a file with :put" do
147
+ response = @session.put_file("/test", "VERSION.yml")
148
+ body = YAML::load(response.body)
149
+ body.header['transfer-encoding'].first.should == "chunked"
150
+ end
151
+
152
+ it "should upload data with :post" do
153
+ data = "upload data"
154
+ response = @session.post("/test", data)
155
+ body = YAML::load(response.body)
156
+ body.request_method.should == "POST"
157
+ body.header['content-length'].should == [data.size.to_s]
158
+ end
159
+
160
+ it "should upload a file with :post" do
161
+ response = @session.post_file("/test", "VERSION.yml")
162
+ body = YAML::load(response.body)
163
+ body.request_method.should == "POST"
164
+ end
165
+
166
+ it "should use chunked encoding when uploading a file with :post" do
167
+ response = @session.post_file("/test", "VERSION.yml")
168
+ body = YAML::load(response.body)
169
+ body.header['transfer-encoding'].first.should == "chunked"
170
+ end
171
+
172
+ it "should pass credentials as http basic auth" do
173
+ @session.username = "foo"
174
+ @session.password = "bar"
175
+ response = @session.get("/test")
176
+ body = YAML::load(response.body)
177
+ body.header['authorization'].should == [encode_authz("foo", "bar")]
178
+ end
179
+
180
+ it "should handle cookies if set" do
181
+ @session.handle_cookies
182
+ response = @session.get("/setcookie").body
183
+ YAML::load(response).header['cookie'].first.should == "session_id=foo123"
184
+ end
185
+
186
+ it "should not handle cookies by default" do
187
+ response = @session.get("/setcookie").body
188
+ YAML::load(response).header.should_not include('cookie')
189
+ end
190
+
191
+ it "should raise exception if cookie store is not writable or readable" do
192
+ lambda { @session.handle_cookies("/trash/clash/foo") }.should raise_error(ArgumentError)
193
+ end
194
+
195
+ def encode_authz(user, passwd)
196
+ "Basic " + Base64.encode64("#{user}:#{passwd}").strip
197
+ end
198
+
199
+ end
data/spec/spec.opts ADDED
@@ -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,82 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: jameskilton-patron
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.4.3
5
+ platform: ruby
6
+ authors:
7
+ - Phillip Toland
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-08-13 00:00:00 -07:00
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
+ extra_rdoc_files:
23
+ - README.txt
24
+ files:
25
+ - LICENSE
26
+ - README.txt
27
+ - Rakefile
28
+ - ext/patron/extconf.rb
29
+ - ext/patron/session_ext.c
30
+ - lib/patron.rb
31
+ - lib/patron/error.rb
32
+ - lib/patron/request.rb
33
+ - lib/patron/response.rb
34
+ - lib/patron/session.rb
35
+ - spec/patron_spec.rb
36
+ - spec/request_spec.rb
37
+ - spec/response_spec.rb
38
+ - spec/session_spec.rb
39
+ - spec/spec.opts
40
+ - spec/spec_helper.rb
41
+ has_rdoc: false
42
+ homepage: http://github.com/toland/Patron
43
+ licenses:
44
+ post_install_message:
45
+ rdoc_options:
46
+ - --quiet
47
+ - --title
48
+ - Patron documentation
49
+ - --opname
50
+ - index.html
51
+ - --line-numbers
52
+ - --main
53
+ - README.txt
54
+ - --inline-source
55
+ require_paths:
56
+ - lib
57
+ - ext
58
+ required_ruby_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - ">="
67
+ - !ruby/object:Gem::Version
68
+ version: "0"
69
+ version:
70
+ requirements: []
71
+
72
+ rubyforge_project: patron
73
+ rubygems_version: 1.3.5
74
+ signing_key:
75
+ specification_version: 3
76
+ summary: Patron HTTP client
77
+ test_files:
78
+ - spec/patron_spec.rb
79
+ - spec/request_spec.rb
80
+ - spec/response_spec.rb
81
+ - spec/session_spec.rb
82
+ - spec/spec_helper.rb