Class Atom::HTTP
In: lib/atom/collection.rb
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::App, Atom::Collection or Atom::Feed, where it will be used for requests.

All its HTTP methods return a Net::HTTPResponse

Methods

delete   get   get_atom_entry   post   put   put_atom_entry   when_auth  

Attributes

pass  [RW]  used by the default when_auth
user  [RW]  used by the default when_auth

Public Instance methods

DELETEs to url

[Source]

    # File lib/atom/http.rb, line 54
54:     def delete url, body = nil, headers = {}
55:       http_request(url, Net::HTTP::Delete, body, headers)
56:     end

GETs an url

[Source]

    # File lib/atom/http.rb, line 39
39:     def get url, headers = {}
40:       http_request(url, Net::HTTP::Get, nil, headers)
41:     end

GET a URL and turn it into an Atom::Entry

[Source]

    # File lib/atom/collection.rb, line 57
57:     def get_atom_entry(url)
58:       res = get(url)
59: 
60:       if res.code != "200" or res.content_type != "application/atom+xml"
61:         raise Atom::HTTPException, "expected Atom::Entry, didn't get it"
62:       end
63: 
64:       Atom::Entry.parse(res.body, url)
65:     end

POSTs body to an url

[Source]

    # File lib/atom/http.rb, line 44
44:     def post url, body, headers = {}
45:       http_request(url, Net::HTTP::Post, body, headers)
46:     end

PUTs body to an url

[Source]

    # File lib/atom/http.rb, line 49
49:     def put url, body, headers = {}
50:       http_request(url, Net::HTTP::Put, body, headers)
51:     end

PUT an Atom::Entry to a URL

[Source]

    # File lib/atom/collection.rb, line 68
68:     def put_atom_entry(entry, url = entry.edit_url)
69:       raise "Cowardly refusing to PUT a non-Atom::Entry (#{entry.class})" unless entry.is_a? Atom::Entry
70:       headers = {"Content-Type" => "application/atom+xml" }
71:       
72:       put(url, entry.to_s, headers)
73:     end

a block that will be called when a remote server responds with 401 Unauthorized, so that your application can prompt for authentication details

it will be called with the base URL of the requested URL, and the realm used in the WWW-Authenticate header.

it should return a value of the form [username, password]

[Source]

    # File lib/atom/http.rb, line 65
65:     def when_auth &block
66:       @get_auth_details = block
67:     end

[Validate]