Module: Azure::Queue::Serialization

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

Class Method Summary collapse

Methods included from Service::Serialization

included

Methods included from Service::Serialization::ClassMethods

#access_policy_from_xml, #ary_from_node, #cors_from_xml, #cors_rule_from_xml, #cors_rule_to_xml, #cors_to_xml, #enumeration_results_from_xml, #expect_node, #hour_metrics_to_xml, #logging_from_xml, #logging_to_xml, #metadata_from_headers, #metadata_from_xml, #metrics_from_xml, #metrics_to_xml_children, #minute_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

.message_to_xml(message_text, encode) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/azure/queue/serialization.rb', line 61

def self.message_to_xml(message_text, encode)
  if encode
    builder = Nokogiri::XML::Builder.new do |xml|
      xml.QueueMessage { xml.MessageText Base64.encode64(message_text) }
    end
  else
    builder = Nokogiri::XML::Builder.new(:encoding => 'utf-8') do |xml|
      xml.QueueMessage { xml.MessageText message_text.encode("utf-8") }
    end
  end
  builder.to_xml
end

.queue_enumeration_results_from_xml(xml) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
# File 'lib/azure/queue/serialization.rb', line 74

def self.queue_enumeration_results_from_xml(xml)
  xml = slopify(xml)
  expect_node("EnumerationResults", xml)

  results = enumeration_results_from_xml(xml, Azure::Service::EnumerationResults.new)

  return results unless (xml > "Queues").any? && ((xml > "Queues") > "Queue").any?

  if xml.Queues.Queue.count == 0
    results.push(queue_from_xml(xml.Queues.Queue))
  else
    xml.Queues.Queue.each { |queue_node|
      results.push(queue_from_xml(queue_node))
    }
  end

  results
end

.queue_from_xml(xml) ⇒ Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/azure/queue/serialization.rb', line 93

def self.queue_from_xml(xml)
  xml = slopify(xml)
  expect_node("Queue", xml)

  queue = Queue.new
  queue.name = xml.Name.text if (xml > "Name").any?
  queue. = (xml.Metadata) if (xml > "Metadata").any?

  queue
end

.queue_message_from_xml(xml, decode) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/azure/queue/serialization.rb', line 44

def self.queue_message_from_xml(xml, decode)
  xml = slopify(xml)
  expect_node("QueueMessage", xml)

  Message.new do |msg|
    msg.id = xml.MessageId.text if (xml > "MessageId").any?
    msg.insertion_time = xml.InsertionTime.text if (xml > "InsertionTime").any?
    msg.expiration_time = xml.ExpirationTime.text if (xml > "ExpirationTime").any?
    msg.dequeue_count = xml.DequeueCount.text.to_i if (xml > "DequeueCount").any?
    msg.message_text = xml.MessageText.text if (xml > "MessageText").any?
    msg.time_next_visible = xml.TimeNextVisible.text if (xml > "TimeNextVisible").any?
    msg.pop_receipt = xml.PopReceipt.text if (xml > "PopReceipt").any?

    msg.message_text = Base64.decode64(msg.message_text) if decode
  end
end

.queue_messages_from_xml(xml, decode) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/azure/queue/serialization.rb', line 26

def self.queue_messages_from_xml(xml, decode)
  xml = slopify(xml)

  expect_node("QueueMessagesList", xml)
  results = []
  return results unless (xml > "QueueMessage").any?

  if xml.QueueMessage.count == 0
    results.push(queue_message_from_xml(xml.QueueMessage, decode))
  else
    xml.QueueMessage.each { |message_node|
      results.push(queue_message_from_xml(message_node, decode))
    }
  end

  results
end