Class: Clowk::Http::Response

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



8
9
10
11
12
13
14
# File 'lib/clowk/http/response.rb', line 8

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



6
7
8
# File 'lib/clowk/http/response.rb', line 6

def body
  @body
end

#body_parsedObject (readonly)

Returns the value of attribute body_parsed.



6
7
8
# File 'lib/clowk/http/response.rb', line 6

def body_parsed
  @body_parsed
end

#headersObject (readonly)

Returns the value of attribute headers.



6
7
8
# File 'lib/clowk/http/response.rb', line 6

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



6
7
8
# File 'lib/clowk/http/response.rb', line 6

def status
  @status
end

Instance Method Details

#==(other) ⇒ Object



34
35
36
37
38
39
40
# File 'lib/clowk/http/response.rb', line 34

def ==(other)
  to_h == if other.respond_to?(:to_h)
    other.to_h
  else
    other
  end
end

#[](key) ⇒ Object



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

def [](key)
  to_h.fetch(key)
end

#success?Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/clowk/http/response.rb', line 16

def success?
  @success
end

#to_hObject



24
25
26
27
28
29
30
31
32
# File 'lib/clowk/http/response.rb', line 24

def to_h
  {
    status: status,
    body: body,
    body_parsed: body_parsed,
    headers: headers,
    success: success?
  }
end