Asp Forum
Home
|
Login
|
Register
|
Search
Forums
>
comp.lang.ruby
Download using Safari's cookies
Tobias Weber
6/7/2008 8:04:00 AM
Hi,
the httpclient library includes a custom file-based cookie storage.
I made a primitive drop-in replacement (myclient.cookie_manager =
NSCookieManager.new) that uses OS X' built-in jar.
It works for getting stuff from Safari, but new ones I save don't
propagate back there. Probably to do with the AcceptPolicy.
Anyway I thought I'd share it. The author's email is well hidden, so he
probably doesn't like to be contacted. And I'm too lazy to create yet
another Trac account. So see below.
http://dev.ctor.org/htt...
require 'osx/cocoa'
class NSCookieManager
attr_accessor :cookies_file
def initialize(file = nil)
@cookies_file = file
@jar = OSX::NSHTTPCookieStorage.sharedHTTPCookieStorage
end
def load_cookies
end
def save_cookies(force = nil)
end
def find(url)
u = OSX::NSURL.URLWithString url.to_s
a = @jar.cookiesForURL u
d = OSX::NSHTTPCookie.requestHeaderFieldsWithCookies a
return d["Cookie"]
end
def parse(str, url)
u = OSX::NSURL.URLWithString url.to_s
d = {"Set-Cookie" => str}
a = OSX::NSHTTPCookie.cookiesWithResponseHeaderFields_forURL(d, u)
@jar.setCookie a.shift
raise unless a.empty?
end
end
--
Tobias Weber
Servizio di avviso nuovi messaggi
Ricevi direttamente nella tua mail i nuovi messaggi per
Download using Safari's cookies
Inserendo la tua e-mail nella casella sotto, riceverai un avviso tramite posta elettronica ogni volta che il motore di ricerca troverà un nuovo messaggio per te
Il servizio è completamente GRATUITO!
x
Login to ForumsZone
Login with Google
Login with E-Mail & Password