Class: Gillbus::V2::Responses::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/gillbus/v2/responses/base.rb

Direct Known Subclasses

Authenticate, Locations, SearchTrips, TripSeats

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(http_response) ⇒ Base

Returns a new instance of Base.



8
9
10
11
12
# File 'lib/gillbus/v2/responses/base.rb', line 8

def initialize(http_response)
  @http_status = http_response.status
  @http_headers = http_response.headers
  @http_body = http_response.body
end

Instance Attribute Details

#http_bodyObject (readonly)

Returns the value of attribute http_body.



6
7
8
# File 'lib/gillbus/v2/responses/base.rb', line 6

def http_body
  @http_body
end

#http_headersObject (readonly)

Returns the value of attribute http_headers.



5
6
7
# File 'lib/gillbus/v2/responses/base.rb', line 5

def http_headers
  @http_headers
end

#http_statusObject (readonly)

Returns the value of attribute http_status.



4
5
6
# File 'lib/gillbus/v2/responses/base.rb', line 4

def http_status
  @http_status
end

Instance Method Details

#error_codeObject



23
24
25
# File 'lib/gillbus/v2/responses/base.rb', line 23

def error_code
  json_body["status"] unless success?
end

#error_messageObject



27
28
29
# File 'lib/gillbus/v2/responses/base.rb', line 27

def error_message
  json_body["message"] unless success?
end

#json_bodyObject



14
15
16
17
# File 'lib/gillbus/v2/responses/base.rb', line 14

def json_body
  return @json_body if defined?(@json_body)
  @json_body = JSON.parse(@http_body) rescue {}
end

#success?Boolean

Returns:

  • (Boolean)


19
20
21
# File 'lib/gillbus/v2/responses/base.rb', line 19

def success?
  http_status == 200
end