Class: TravelTime::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/travel_time/response.rb

Overview

The Response class represent an API response.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status: nil, headers: nil, body: nil) ⇒ Response

Returns a new instance of Response.



34
35
36
37
38
# File 'lib/travel_time/response.rb', line 34

def initialize(status: nil, headers: nil, body: nil)
  @status = status
  @headers = headers
  @body = body
end

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



8
9
10
# File 'lib/travel_time/response.rb', line 8

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



8
9
10
# File 'lib/travel_time/response.rb', line 8

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



8
9
10
# File 'lib/travel_time/response.rb', line 8

def status
  @status
end

Class Method Details

.from_hash(response) ⇒ Object



26
27
28
29
30
31
32
# File 'lib/travel_time/response.rb', line 26

def self.from_hash(response)
  new(
    status: response[:status],
    headers: response[:headers],
    body: response[:body]
  )
end

.from_object(response) ⇒ Object



10
11
12
13
14
15
16
# File 'lib/travel_time/response.rb', line 10

def self.from_object(response)
  new(
    status: response.status,
    headers: response.headers,
    body: response.body
  )
end

.from_object_proto(response) ⇒ Object



18
19
20
21
22
23
24
# File 'lib/travel_time/response.rb', line 18

def self.from_object_proto(response)
  new(
    status: response.status,
    headers: response.headers,
    body: ProtoUtils.decode_proto_response(response.body)
  )
end

Instance Method Details

#success?Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/travel_time/response.rb', line 40

def success?
  (200..299).cover?(status)
end