Class | Atom::HTTP |
In: |
lib/atom/http.rb
|
Parent: | Object |
An object which handles the details of HTTP - particularly authentication and caching (neither of which are fully implemented).
This object can be used on its own, or passed to an Atom::Service, Atom::Collection or Atom::Feed, where it will be used for requests.
All its HTTP methods return a Net::HTTPResponse
allow_all_redirects | [RW] |
automatically handle redirects, even for POST/PUT/DELETE requests?
defaults to false, which will transparently redirect GET requests but return a Net::HTTPRedirection object when the server indicates to redirect a POST/PUT/DELETE |
always_auth | [RW] |
when set to :basic, :wsse or :authsub, this will send an Authentication
header with every request instead of waiting for a challenge from the
server.
be careful; always_auth :basic will send your username and password in plain text to every URL this object requests. :digest won‘t work, since Digest authentication requires an initial challenge to generate a response defaults to nil |
pass | [RW] | used by the default when_auth |
token | [RW] | the token used for Google‘s AuthSub authentication |
user | [RW] | used by the default when_auth |
DELETEs to url
# File lib/atom/http.rb, line 165 165: def delete url, body = nil, headers = {} 166: http_request(url, Net::HTTP::Delete, body, headers) 167: end
GETs an url
# File lib/atom/http.rb, line 150 150: def get url, headers = {} 151: http_request(url, Net::HTTP::Get, nil, headers) 152: end
GET a URL and turn it into an Atom::Entry
# File lib/atom/http.rb, line 186 186: def get_atom_entry(url) 187: res = get(url, "Accept" => "application/atom+xml") 188: 189: # be picky for atom:entrys 190: res.validate_content_type( [ "application/atom+xml" ] ) 191: 192: # XXX handle other HTTP codes 193: if res.code != "200" 194: raise Atom::HTTPException, "expected Atom::Entry, didn't get it" 195: end 196: 197: Atom::Entry.parse(res.body, url) 198: end
POSTs body to an url
# File lib/atom/http.rb, line 155 155: def post url, body, headers = {} 156: http_request(url, Net::HTTP::Post, body, headers) 157: end
PUTs body to an url
# File lib/atom/http.rb, line 160 160: def put url, body, headers = {} 161: http_request(url, Net::HTTP::Put, body, headers) 162: end
PUT an Atom::Entry to a URL
# File lib/atom/http.rb, line 201 201: def put_atom_entry(entry, url = entry.edit_url) 202: raise "Cowardly refusing to PUT a non-Atom::Entry (#{entry.class})" unless entry.is_a? Atom::Entry 203: headers = {"Content-Type" => "application/atom+xml" } 204: 205: put(url, entry.to_s, headers) 206: end
a block that will be called when a remote server responds with 401 Unauthorized, so that your application can prompt for authentication details.
the default is to use the values of @user and @pass.
your block will be called with two parameters
abs_url: | the base URL of the request URL |
realm: | the realm used in the WWW-Authenticate header |
(will be nil if there is no WWW-Authenticate header)
it should return a value of the form [username, password]
# File lib/atom/http.rb, line 181 181: def when_auth &block # :yields: abs_url, realm 182: @get_auth_details = block 183: end