Class: The86::Client::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/the86-client/response.rb

Overview

Representation of an HTTP response.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(status, headers, data) ⇒ Response

status: The numeric HTTP status. headers: Hash of HTTP response headers. data: The decoded body of the response.



9
10
11
12
13
# File 'lib/the86-client/response.rb', line 9

def initialize(status, headers, data)
  @status = status
  @headers = headers
  @data = data
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



17
18
19
# File 'lib/the86-client/response.rb', line 17

def data
  @data
end

#headersObject (readonly)

Returns the value of attribute headers.



16
17
18
# File 'lib/the86-client/response.rb', line 16

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



15
16
17
# File 'lib/the86-client/response.rb', line 15

def status
  @status
end

Instance Method Details



20
21
22
23
24
25
26
27
28
# File 'lib/the86-client/response.rb', line 20

def links
  @_links ||= {}.tap do |links|
    Array(headers["Link"] || headers["link"]).map do |link|
      link.match %r{\A<([^>]+)>;\s*rel="([^"]+)"\z}
    end.compact.each do |match|
      links[match[2].downcase.to_sym] = match[1]
    end
  end
end