Module: ActiveResource::Formats::AtomFormat

Extended by:
AtomFormat
Included in:
AtomFormat
Defined in:
lib/constant_contact/formats/atom_format.rb

Instance Method Summary collapse

Instance Method Details

#decode(xml) ⇒ Object


19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/constant_contact/formats/atom_format.rb', line 19

def decode(xml)
  xml.gsub!( /\<(\/?)atom\:/, '<\1' ) # the "events" feeds have "atom:" in front of tags, for some reason
  doc = REXML::Document.new(xml)
  return [] if no_content?(doc)
  result = Hash.from_xml(from_atom_data(doc))

  if is_collection?(doc)
    list = result['records']

    next_link = REXML::XPath.first(doc, "/feed/link[@rel='next']")
    if next_link
      next_path = next_link.attribute('href').value
      next_page = ::ConstantContact::Base.connection.get(next_path)
      next_page = [next_page] if Hash === next_page
      list.concat(next_page)
    end

    list
  else
    result.values.first
  end
end

#encode(hash, options = {}) ⇒ Object


15
16
17
# File 'lib/constant_contact/formats/atom_format.rb', line 15

def encode(hash, options={})
  hash.to_xml(options)
end

#extensionObject


7
8
9
# File 'lib/constant_contact/formats/atom_format.rb', line 7

def extension
  "atom"
end

#mime_typeObject


11
12
13
# File 'lib/constant_contact/formats/atom_format.rb', line 11

def mime_type
  "application/atom+xml"
end