Class: Eve::API::Response

Inherits:
Object
  • Object
show all
Includes:
Inspection, Rowsets, WrapObject
Defined in:
lib/eve/api/response.rb,
lib/eve/api/response/rowset.rb,
lib/eve/api/response/rowsets.rb,
lib/eve/api/response/inspection.rb,
lib/eve/api/response/wrap_object.rb

Defined Under Namespace

Modules: Inspection, Rowsets, WrapObject Classes: Rowset

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Inspection

#inspect, #inspected_elements, #inspected_instance_variables, #inspected_name, #inspected_rowsets, #protected_instance_variables

Methods included from Rowsets

#add_rowset, #copy_attributes, #rowset_names, #rowsets, #value_for

Methods included from WrapObject

#wrap_object

Constructor Details

#initialize(xml, options = {}) ⇒ Response

Returns a new instance of Response.



14
15
16
17
18
19
20
21
# File 'lib/eve/api/response.rb', line 14

def initialize(xml, options = {})
  @options = options
  xml = Hpricot::XML(xml).root if xml.kind_of?(String)
  @xml = xml
  #@attributes = {}

  parse_xml unless options[:process_xml] == false
end

Instance Attribute Details

#api_versionObject (readonly)

Returns the value of attribute api_version.



12
13
14
# File 'lib/eve/api/response.rb', line 12

def api_version
  @api_version
end

#contentObject (readonly)

Returns the value of attribute content.



12
13
14
# File 'lib/eve/api/response.rb', line 12

def content
  @content
end

Instance Method Details

#[](key) ⇒ Object



41
42
43
44
45
46
# File 'lib/eve/api/response.rb', line 41

def [](key)
  key = key.to_s if !key.kind_of?(String)
  key = key.underscore
  instance_variable_get("@#{key}") ||
          raise(ArgumentError, "No attribute called '#{key}' seems to exist in #{self.inspect}")
end

#to_hashObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/eve/api/response.rb', line 23

def to_hash
  hash = {}
  (instance_variables - protected_instance_variables + (@name.blank? ? [] : ["@name"])).each do |ivar|
    value = instance_variable_get(ivar)
    value = case value
      when Rowset then value.to_a
      when Response then value.to_hash
      else value
    end
    hash[ivar[1..-1]] = value
  end
  hash
end

#to_yaml(*args) ⇒ Object



37
38
39
# File 'lib/eve/api/response.rb', line 37

def to_yaml(*args)
  to_hash.to_yaml(*args)
end