Class: EVEApi::Request
- Inherits:
-
Object
- Object
- EVEApi::Request
- Defined in:
- lib/eveapi/request.rb
Overview
Handling of requests and response from the EVE Online API
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#response ⇒ Object
Returns the value of attribute response.
-
#result ⇒ Object
Returns the value of attribute result.
Instance Method Summary collapse
- #error ⇒ Object
-
#initialize(response = nil) ⇒ Request
constructor
A new instance of Request.
- #parse_result ⇒ Object
- #parse_xml ⇒ Object
- #process_array(data) ⇒ Object
- #process_hash(data) ⇒ Object
Constructor Details
#initialize(response = nil) ⇒ Request
Returns a new instance of Request.
8 9 10 11 12 13 14 |
# 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 |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
4 5 6 |
# File 'lib/eveapi/request.rb', line 4 def data @data end |
#response ⇒ Object
Returns the value of attribute response.
6 7 8 |
# File 'lib/eveapi/request.rb', line 6 def response @response end |
#result ⇒ Object
Returns the value of attribute result.
5 6 7 |
# File 'lib/eveapi/request.rb', line 5 def result @result end |
Instance Method Details
#error ⇒ Object
16 17 18 |
# File 'lib/eveapi/request.rb', line 16 def error data['eveapi'].key?('error') ? data['eveapi']['error'] : false end |
#parse_result ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/eveapi/request.rb', line 36 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 ⇒ Object
20 21 22 |
# File 'lib/eveapi/request.rb', line 20 def parse_xml Crack::XML.parse(response.body) end |
#process_array(data) ⇒ Object
30 31 32 33 34 |
# File 'lib/eveapi/request.rb', line 30 def process_array(data) data.each do |v| v.process_rows if v.is_a?(Hash) end end |
#process_hash(data) ⇒ Object
24 25 26 27 28 |
# File 'lib/eveapi/request.rb', line 24 def process_hash(data) data.each_value do |v| v.process_rows if v.is_a?(Hash) end.process_rows end |