class SPOT::ApiResponse
Public Class Methods
new(response)
click to toggle source
# File lib/spot-gps/api_response.rb, line 9 def initialize(response) @response = response end
Public Instance Methods
body()
click to toggle source
Return the body of the API response
# File lib/spot-gps/api_response.rb, line 14 def body json? ? handle_json : handle_raw end
json?()
click to toggle source
Returns true if the response is JSON
# File lib/spot-gps/api_response.rb, line 19 def json? content_type = @response.headers[:content_type] || '' content_type.include?('application/json') end
Private Instance Methods
handle_json()
click to toggle source
# File lib/spot-gps/api_response.rb, line 30 def handle_json @json_body ||= JSON.parse(@response.body) end
handle_raw()
click to toggle source
# File lib/spot-gps/api_response.rb, line 34 def handle_raw non_json_msg = "Received non-JSON response:\n\n" \ "status: #{@response.status}\n" \ "headers: #{@response.headers}\n" \ "body: #{@response.body}" raise non_json_msg end
raw_body()
click to toggle source
# File lib/spot-gps/api_response.rb, line 26 def raw_body @response.body end