Class: TOS::Response

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

Overview

Lightweight wrapper around a Net::HTTPResponse so callers don’t have to know which HTTP library produced it.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



9
10
11
12
13
# File 'lib/tos/response.rb', line 9

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



7
8
9
# File 'lib/tos/response.rb', line 7

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



7
8
9
# File 'lib/tos/response.rb', line 7

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



7
8
9
# File 'lib/tos/response.rb', line 7

def status
  @status
end

Instance Method Details

#content_lengthObject



28
29
30
# File 'lib/tos/response.rb', line 28

def content_length
  header("content-length")&.to_i
end

#content_typeObject



32
33
34
# File 'lib/tos/response.rb', line 32

def content_type
  header("content-type")
end

#etagObject



24
25
26
# File 'lib/tos/response.rb', line 24

def etag
  header("etag")&.delete('"')
end

#header(name) ⇒ Object



15
16
17
18
# File 'lib/tos/response.rb', line 15

def header(name)
  key = headers.keys.find { |k| k.downcase == name.downcase }
  key && headers[key]
end

#request_idObject



20
21
22
# File 'lib/tos/response.rb', line 20

def request_id
  header("x-tos-request-id") || header("x-tos-id-2")
end