Class: Listmonk::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/listmonk/response.rb,
sig/listmonk.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



7
8
9
10
11
# File 'lib/listmonk/response.rb', line 7

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.

Returns:

  • (Object)


5
6
7
# File 'lib/listmonk/response.rb', line 5

def body
  @body
end

#headersHash[String, String] (readonly)

Returns the value of attribute headers.

Returns:

  • (Hash[String, String])


5
6
7
# File 'lib/listmonk/response.rb', line 5

def headers
  @headers
end

#statusInteger (readonly)

Returns the value of attribute status.

Returns:

  • (Integer)


5
6
7
# File 'lib/listmonk/response.rb', line 5

def status
  @status
end

Instance Method Details

#dataObject

Returns:

  • (Object)


17
18
19
20
21
# File 'lib/listmonk/response.rb', line 17

def data
  return body unless body.is_a?(Hash)

  body.key?("data") ? body["data"] : body
end

#success?Boolean

Returns:

  • (Boolean)


13
14
15
# File 'lib/listmonk/response.rb', line 13

def success?
  status.between?(200, 299)
end