class EVEApi::Request

Handling of requests and response from the EVE Online API

Attributes

data[RW]
response[RW]
result[RW]

Public Class Methods

new(response = nil) click to toggle source
# File lib/eveapi/request.rb, line 8
def initialize(response = nil)
  @response = response
  fail "HTTP: #{response.status}" unless response.status == 200
  @data = parse_xml
  @result = convert_hash_keys(parse_result)
  fail error if error
end

Private Instance Methods

error() click to toggle source
# File lib/eveapi/request.rb, line 16
def error
  data['eveapi'].key?('error') ? data['eveapi']['error'] : false
end
parse_result() click to toggle source
# File lib/eveapi/request.rb, line 40
def parse_result
  api_result = data['eveapi']['result']
  case api_result['rowset']['row']
  when Array
    return process_array api_result['rowset']['row']
  else
    return api_result['rowset']['row']
  end
rescue TypeError, NoMethodError
  return process_hash(api_result)
end
parse_xml() click to toggle source
# File lib/eveapi/request.rb, line 21
def parse_xml
  Crack::XML.parse(response.body)
end
process_array(data) click to toggle source
# File lib/eveapi/request.rb, line 33
def process_array(data)
  data.each do |v|
    v.process_rows if v.is_a?(Hash)
  end
end
process_hash(data) click to toggle source
# File lib/eveapi/request.rb, line 26
def process_hash(data)
  data.each_value do |v|
    v.process_rows if v.is_a?(Hash)
  end.process_rows
end