Module: RubyRest::Atom
Defined Under Namespace
Modules: DummyEntry, Entry, EntryBinder
Constant Summary collapse
- NAMESPACES =
{ "xmlns" => "http://www.w3.org/2005/Atom", "xmlns:moodisland" => "http://www.moodisland.com/ns#" }
- ATOM_TYPE =
"application/atom+xml".freeze
- ATOMSERV_TYPE =
"application/atomserv+xml".freeze
- HTML_TYPE =
"text/html".freeze
- WORKSPACE_METHOD =
"dashboard".freeze
- MODULEID =
"Ruby-on-Rest (http://rubyrest.rubyforge.org)".freeze
Constants included from Tools
Tools::ATOM_DATE_FORMAT, Tools::ERRORS
Instance Method Summary collapse
-
#build_entry(object, builder, uri) ⇒ Object
Builds an Atom Entry representation of the specified object.
-
#build_feed(entries, builder, uri, path, title) ⇒ Object
Builds an Atom Feed representation of the specified collection of entries.
-
#build_service_document(collections, builder, uri) ⇒ Object
Builds an Atom Service Document.
-
#format_response(request, response) ⇒ Object
Formats the response as a Atom feed, Atom Entry or Atom Service Document.
Methods included from Tools
#error, #format_atom_date, #nvl, #parse_atom_date, #to_class, #to_gem_name, #to_module_name
Instance Method Details
#build_entry(object, builder, uri) ⇒ Object
Builds an Atom Entry representation of the specified object.
The object is supposed to implement the following mandatory methods: atom_id, atom_title, atom_author, atom_updated, atom_summary
The object can implement the following optionnal methods: atom_related, atom_content
88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 |
# File 'lib/rubyrest/atom.rb', line 88 def build_entry( object, builder, uri ) entry_link = uri entry_link = "#{uri}/#{object.atom_id}" if @id == nil builder.entry( NAMESPACES ) { builder.title object.atom_title builder. { builder.name object. } builder.updated format_atom_date( object.atom_updated ) builder.id entry_link builder.summary object.atom_summary builder.link( "rel" => "alternate", "href" => entry_link ) if object.respond_to?( :atom_related ) = object.( @principal ) if .respond_to?( :each ) .each{ || builder.link( "rel" => "related", "href" => "#{entry_link}/#{}", "title" => "#{}", "type" => ATOM_TYPE ) } end end builder.moodisland :content do object.atom_content( builder ) if object.respond_to? :atom_content end } end |
#build_feed(entries, builder, uri, path, title) ⇒ Object
Builds an Atom Feed representation of the specified collection of entries
68 69 70 71 72 73 74 75 76 77 |
# File 'lib/rubyrest/atom.rb', line 68 def build_feed( entries, builder, uri, path, title ) builder.feed( NAMESPACES ) { builder.id uri builder.link( { "rel" => "self", "href" => path, "type" => ATOM_TYPE } ) builder.link( { "rel" => "alternate", "href" => uri, "type" => HTML_TYPE } ) builder.title title builder.updated format_atom_date( Time.now ) entries.each { |object| build_entry( object, builder, uri ) } } end |
#build_service_document(collections, builder, uri) ⇒ Object
Builds an Atom Service Document. This is a representation of the user’s dashboard or initial workspace.
49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 |
# File 'lib/rubyrest/atom.rb', line 49 def build_service_document( collections, builder, uri ) builder.service( NAMESPACES ){ builder.workspace { builder.title "Dashboard" if collections != nil and collections.respond_to?( :each ) collections.each { |col| builder.collection( { "href" => "/#{col}" } ) { builder.title col builder.accept "entry" } } end } } end |
#format_response(request, response) ⇒ Object
Formats the response as a Atom feed, Atom Entry or Atom Service Document
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 |
# File 'lib/rubyrest/atom.rb', line 29 def format_response( request, response ) builder = Builder::XmlMarkup.new( :target => response.body ) builder.instruct! if @service_method == "dashboard" response[ "content-type" ] = ATOMSERV_TYPE build_service_document( @result, builder, request.request_uri ) else response[ "content-type" ] = ATOM_TYPE if @result.respond_to? "each" title = @property || @model build_feed( @result, builder, request.request_uri, request.path, title ) else build_entry( @result, builder, request.request_uri ) end end end |