Module: Azure::Table::Serialization

Includes:
Service::Serialization
Defined in:
lib/azure/table/serialization.rb

Class Method Summary collapse

Methods included from Service::Serialization

included

Methods included from Service::Serialization::ClassMethods

#access_policy_from_xml, #enumeration_results_from_xml, #expect_node, #logging_from_xml, #logging_to_xml, #metadata_from_headers, #metadata_from_xml, #metrics_from_xml, #metrics_to_xml, #retention_policy_from_xml, #retention_policy_to_xml, #service_properties_from_xml, #service_properties_to_xml, #signed_identifier_from_xml, #signed_identifiers_from_xml, #signed_identifiers_to_xml, #slopify, #to_bool

Class Method Details

.entries_from_feed_xml(xml) ⇒ Object



69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/azure/table/serialization.rb', line 69

def self.entries_from_feed_xml(xml)
  xml = slopify(xml)
  expect_node("feed", xml)

  return nil unless (xml > "entry").any?
  
  results = []
  
  if (xml > "entry").count == 0
    results.push hash_from_entry_xml((xml > "entry"))
  else
    (xml > "entry").each do |entry|
      results.push hash_from_entry_xml(entry)
    end
  end

  results
end

.hash_from_entry_xml(xml) ⇒ Object



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
# File 'lib/azure/table/serialization.rb', line 88

def self.hash_from_entry_xml(xml)
  xml = slopify(xml)
  expect_node("entry", xml)
  result = {}
  result[:etag] = xml["etag"]
  result[:updated] = Time.parse((xml > "updated").text) if (xml > "updated").any?
  properties = {} 
  if (xml > "content").any?
    (xml > "content").first.first_element_child.element_children.each do |prop|
      properties[prop.name] = prop.text != "" ? Azure::Table::EdmType.unserialize_query_value(prop.text, prop["m:type"]) : prop["null"] ? nil : ""
    end
  end
  result[:properties] = properties
  result
end

.hash_to_content_xml(hash, xml = Nokogiri::XML::Builder.new) ⇒ Object



48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/azure/table/serialization.rb', line 48

def self.hash_to_content_xml(hash, xml=Nokogiri::XML::Builder.new)
  xml.send("content", :type => "application/xml") do |content|
    content.send("m:properties") do |properties|
      hash.each do |key, val|
        type = Azure::Table::EdmType.property_type(val)
        attributes = {}
        attributes["m:type"] = type unless type.nil? || type.empty?

        if val.nil?
          attributes["m:null"] = "true"
          properties.send("d:#{key}", attributes)
        else
          properties.send("d:#{key}", Azure::Table::EdmType.serialize_value(type, val), attributes)
        end
      end
    end
  end

  xml
end

.hash_to_entry_xml(hash, id = nil, xml = Nokogiri::XML::Builder.new) ⇒ Object



28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/azure/table/serialization.rb', line 28

def self.hash_to_entry_xml(hash, id=nil, xml=Nokogiri::XML::Builder.new)
  entry_namespaces = {
    "xmlns"   => "http://www.w3.org/2005/Atom",
    "xmlns:m" => "http://schemas.microsoft.com/ado/2007/08/dataservices/metadata",
    "xmlns:d" => "http://schemas.microsoft.com/ado/2007/08/dataservices"
  }

  xml.entry entry_namespaces do |entry|
      id ? entry.id(id): entry.id
      entry.updated Time.now.xmlschema 
      entry.title
      entry.author do |author|
        author.name
      end
    hash_to_content_xml(hash, entry)
  end

  xml
end