Module: ActiveResource::Formats::SCXmlFormat

Extended by:
SCXmlFormat
Included in:
SCXmlFormat
Defined in:
lib/soundcloud/sc_xml_format.rb

Instance Method Summary collapse

Instance Method Details

#decode(xml) ⇒ Object



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

def decode(xml)
  # Extract the link to the next collection, if present.
  # This may have to change if the name of the link changes from 'next-partition-href'
  r1 = %r[ next-partition-href=\".+\"]
  r2 = %r[http://.+"]
  if xml[r1] !=nil
    next_partition_url = xml[r1][r2].chop
    xml[r1] = ''
  else
    next_partition_url = nil
  end
  
  response = from_xml_data(Hash.from_xml(xml))
  if response.class == Array
    resource_data = PartitionedResource.new(response)
    resource_data.next_partition = next_partition_url
  else
    resource_data = response
  end
  
  resource_data
end

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



14
15
16
# File 'lib/soundcloud/sc_xml_format.rb', line 14

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

#extensionObject



6
7
8
# File 'lib/soundcloud/sc_xml_format.rb', line 6

def extension
  "xml"
end

#mime_typeObject



10
11
12
# File 'lib/soundcloud/sc_xml_format.rb', line 10

def mime_type
  "application/xml"
end