Class: UnderFire::APIResponse

Inherits:
Object
  • Object
show all
Defined in:
lib/under_fire/api_response.rb

Overview

Wraps query response, providing to_h and to_s methods for easy processing.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ APIResponse

Returns a new instance of APIResponse.

Parameters:

  • response (String)

    XML string.



10
11
12
# File 'lib/under_fire/api_response.rb', line 10

def initialize(response)
  @response = parse_response(response)
end

Instance Attribute Details

#responseHash (readonly)

Returns Response as Hash.

Returns:

  • (Hash)

    Response as Hash.



7
8
9
# File 'lib/under_fire/api_response.rb', line 7

def response
  @response
end

Instance Method Details

#success?Boolean

Returns Did the query return something?.

Returns:

  • (Boolean)

    Did the query return something?



25
26
27
# File 'lib/under_fire/api_response.rb', line 25

def success?
  response[:responses][:response][:@status] == 'OK'
end

#to_hHash

Returns Hash representation of response.

Returns:

  • (Hash)

    Hash representation of response.



15
16
17
# File 'lib/under_fire/api_response.rb', line 15

def to_h
  response[:responses]
end

#to_sString

Returns String represenation suitable for command line.

Returns:

  • (String)

    String represenation suitable for command line.



20
21
22
# File 'lib/under_fire/api_response.rb', line 20

def to_s
  recursive_to_s(to_h)
end