Sha256: 916b20afe1893c8eac38ae6764ea65461afd4d1f6692d61c614db7d9056285c9

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

module Restfulie::Common::Representation
  # Implements the interface for unmarshal Atom media type responses (application/atom+xml) to ruby objects instantiated by rAtom library.
  #
  # Furthermore, this class extends rAtom behavior to enable client users to easily access link relationships.
  class Atom

    cattr_reader :media_type_name
    @@media_type_name = 'application/atom+xml'

    cattr_reader :headers
    @@headers = { 
      :get  => { 'Accept'       => media_type_name },
      :post => { 'Content-Type' => media_type_name }
    }

    #Convert raw string to rAtom instances (client side)
    def unmarshal(content)
      begin
        ::Atom::Feed.load_feed(content)
      rescue ::ArgumentError
        ::Atom::Entry.load_entry(content)
      end
    end

    def marshal(string, rel)
      string
    end

    # transforms this content into a parameter hash for rails (server-side usage)
    def self.to_hash(content)
      Hash.from_xml(content).with_indifferent_access
    end
    
    def prepare_link_for(link)
      link
    end
  end

end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
restfulie-0.7.1 lib/restfulie/common/representation/atom.rb