patron 0.4.1 → 0.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/Rakefile +1 -26
- data/ext/patron/session_ext.c +12 -0
- data/lib/patron/request.rb +1 -1
- data/lib/patron/session.rb +18 -1
- data/spec/session_spec.rb +15 -0
- metadata +2 -2
data/Rakefile
CHANGED
@@ -126,31 +126,6 @@ Spec::Rake::SpecTask.new('spec:rcov') do |t|
|
|
126
126
|
t.rcov_opts << '--exclude /Library/Ruby/Gems'
|
127
127
|
end
|
128
128
|
|
129
|
-
|
130
|
-
begin
|
131
|
-
require 'rake/contrib/sshpublisher'
|
132
|
-
namespace :rubyforge do
|
133
|
-
|
134
|
-
desc "Release gem and RDoc documentation to RubyForge"
|
135
|
-
task :release => ["rubyforge:release:gem", "rubyforge:release:docs"]
|
136
|
-
|
137
|
-
namespace :release do
|
138
|
-
desc "Publish RDoc to RubyForge."
|
139
|
-
task :docs => [:rdoc] do
|
140
|
-
config = YAML.load(
|
141
|
-
File.read(File.expand_path('~/.rubyforge/user-config.yml'))
|
142
|
-
)
|
143
|
-
|
144
|
-
host = "#{config['username']}@rubyforge.org"
|
145
|
-
remote_dir = "/var/www/gforge-projects/patron/"
|
146
|
-
local_dir = 'doc'
|
147
|
-
|
148
|
-
Rake::SshDirPublisher.new(host, remote_dir, local_dir).upload
|
149
|
-
end
|
150
|
-
end
|
151
|
-
end
|
152
|
-
rescue LoadError
|
153
|
-
puts "Rake SshDirPublisher is unavailable or your rubyforge environment is not configured."
|
154
|
-
end
|
129
|
+
Jeweler::RubyforgeTasks.new
|
155
130
|
|
156
131
|
task :default => :spec
|
data/ext/patron/session_ext.c
CHANGED
@@ -380,6 +380,17 @@ VALUE session_handle_request(VALUE self, VALUE request) {
|
|
380
380
|
return rb_ensure(&perform_request, self, &cleanup, self);
|
381
381
|
}
|
382
382
|
|
383
|
+
VALUE enable_cookie_session(VALUE self, VALUE file) {
|
384
|
+
struct curl_state *state;
|
385
|
+
Data_Get_Struct(self, struct curl_state, state);
|
386
|
+
CURL* curl = state->handle;
|
387
|
+
char *file_path = RSTRING_PTR(file);
|
388
|
+
if (file_path != "")
|
389
|
+
curl_easy_setopt(curl, CURLOPT_COOKIEJAR, file_path);
|
390
|
+
curl_easy_setopt(curl, CURLOPT_COOKIEFILE, file_path);
|
391
|
+
return Qnil;
|
392
|
+
}
|
393
|
+
|
383
394
|
//------------------------------------------------------------------------------
|
384
395
|
// Extension initialization
|
385
396
|
//
|
@@ -411,6 +422,7 @@ void Init_session_ext() {
|
|
411
422
|
rb_define_method(cSession, "escape", session_escape, 1);
|
412
423
|
rb_define_method(cSession, "unescape", session_unescape, 1);
|
413
424
|
rb_define_method(cSession, "handle_request", session_handle_request, 1);
|
425
|
+
rb_define_method(cSession, "enable_cookie_session", enable_cookie_session, 1);
|
414
426
|
|
415
427
|
rb_define_const(cRequest, "AuthBasic", CURLAUTH_BASIC);
|
416
428
|
rb_define_const(cRequest, "AuthDigest", CURLAUTH_DIGEST);
|
data/lib/patron/request.rb
CHANGED
data/lib/patron/session.rb
CHANGED
@@ -60,7 +60,7 @@ module Patron
|
|
60
60
|
# @see Patron::Request#auth_type
|
61
61
|
attr_accessor :auth_type
|
62
62
|
|
63
|
-
private :ext_initialize, :handle_request
|
63
|
+
private :ext_initialize, :handle_request, :enable_cookie_session
|
64
64
|
|
65
65
|
# Create a new Session object.
|
66
66
|
def initialize
|
@@ -72,6 +72,23 @@ module Patron
|
|
72
72
|
@auth_type = :basic
|
73
73
|
end
|
74
74
|
|
75
|
+
# Makes this session handle cookies and store them in in +file+.
|
76
|
+
# If file is nil they will be stored in memory. Otherwise the +file+
|
77
|
+
# must be readable and writable. Calling multiple times will add more files.
|
78
|
+
def handle_cookies(file = nil)
|
79
|
+
if file
|
80
|
+
path = Pathname(file).expand_path
|
81
|
+
unless File.exists?(file) and File.writable?(path.dirname)
|
82
|
+
raise ArgumentError, "Can't create file #{path} (permission error)"
|
83
|
+
end
|
84
|
+
unless File.readable?(file) or File.writable?(path)
|
85
|
+
raise ArgumentError, "Cant read or write file #{path} (permission error)"
|
86
|
+
end
|
87
|
+
end
|
88
|
+
enable_cookie_session(path.to_s)
|
89
|
+
self
|
90
|
+
end
|
91
|
+
|
75
92
|
###################################################################
|
76
93
|
### Standard HTTP methods
|
77
94
|
###
|
data/spec/session_spec.rb
CHANGED
@@ -177,6 +177,21 @@ describe Patron::Session do
|
|
177
177
|
body.header['authorization'].should == [encode_authz("foo", "bar")]
|
178
178
|
end
|
179
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
|
+
|
180
195
|
def encode_authz(user, passwd)
|
181
196
|
"Basic " + Base64.encode64("#{user}:#{passwd}").strip
|
182
197
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: patron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.4.
|
4
|
+
version: 0.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Phillip Toland
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2009-08-
|
12
|
+
date: 2009-08-13 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|