Module: ObiWan::XmlClient::Functions

Defined in:
lib/obi-wan/messages.rb

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.included(base) ⇒ Object



6
7
8
# File 'lib/obi-wan/messages.rb', line 6

def self.included(base)
  base.module_eval { extend(Functions) }
end

Instance Method Details

#offer_subscription_id(response) ⇒ Object



44
45
46
47
# File 'lib/obi-wan/messages.rb', line 44

def offer_subscription_id(response)
  puts response.xpath("/")
  response.xpath("//offerSubscriptionId/value")
end

#resp_to_xml(resp) ⇒ Object



35
36
37
# File 'lib/obi-wan/messages.rb', line 35

def resp_to_xml(resp)
  Nokogiri::XML(resp.body)
end

#success?(response) ⇒ Boolean

Returns:

  • (Boolean)


39
40
41
42
# File 'lib/obi-wan/messages.rb', line 39

def success?(response)
  result = response.search("statusCode")
  !result.nil? and result.text.to_i / 100 === 2
end

#xml_to_hash(node) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
# File 'lib/obi-wan/messages.rb', line 10

def xml_to_hash(node)

  # this doesn't cover <a>bcdefg<h>pants</h></a>  
  # luckily, obi doesn't do insane things like this
  
  if node.elements.empty?
    result = node.text
  else
    result = {}
    node.elements.each do |c|
      key = c.name.to_sym
      val = xml_to_hash(c)
    
      if result[key].nil?
        result[key] = val
      elsif result[key].is_a? Array
        result[key] << val
      else
        result[key] = [ result[key], val ]
      end
    end
  end
  result
end