Class: Awis::Models::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/awis/models/base.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
13
14
# File 'lib/awis/models/base.rb', line 8

def initialize(response)
  response_data = loading_response(response)

  set_xml(response_data)
  # Need to implement on sub-class
  setup_data!(response_data)
end

Instance Attribute Details

#request_idObject

Returns the value of attribute request_id.



6
7
8
# File 'lib/awis/models/base.rb', line 6

def request_id
  @request_id
end

#responseObject

Returns the value of attribute response.



6
7
8
# File 'lib/awis/models/base.rb', line 6

def response
  @response
end

#status_codeObject

Returns the value of attribute status_code.



6
7
8
# File 'lib/awis/models/base.rb', line 6

def status_code
  @status_code
end

Instance Method Details

#action_nameObject



24
25
26
# File 'lib/awis/models/base.rb', line 24

def action_name
  self.class.name.split(/\:\:/)[-1]
end

#loading_response(response) ⇒ Object



16
17
18
# File 'lib/awis/models/base.rb', line 16

def loading_response(response)
  Awis::Utils::XML.new(response.response_body)
end

#pretty_xmlObject



39
40
41
42
43
44
45
46
# File 'lib/awis/models/base.rb', line 39

def pretty_xml
  doc = Nokogiri.XML(@xml.data) do |config|
    config.default_xml.noblanks
  end
  puts doc.to_xml(:indent => 2)

  nil
end

#relationship_collections(item_object, items, items_count, kclass) ⇒ Object



28
29
30
31
32
33
# File 'lib/awis/models/base.rb', line 28

def relationship_collections(item_object, items, items_count, kclass)
  return if items.empty?

  all_items = {}.array_slice_merge!(:item, items, items_count)
  all_items.map { |item| item_object << kclass.new(item) }
end

#root_node_nameObject



20
21
22
# File 'lib/awis/models/base.rb', line 20

def root_node_name
  "/aws:#{action_name}Response/aws:Response/aws:#{action_name}Result/aws:Alexa"
end

#success?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/awis/models/base.rb', line 35

def success?
  status_code == 'Success'
end