Class: ZeroClick::Sellers::Response

Inherits:
Object
  • Object
show all
Defined in:
lib/zeroclick/sellers/contracts.rb

Overview

A framework-neutral response the caller is expected to return as-is.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Response.



64
65
66
67
68
69
# File 'lib/zeroclick/sellers/contracts.rb', line 64

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

Instance Attribute Details

#bodyObject (readonly)

Returns the value of attribute body.



62
63
64
# File 'lib/zeroclick/sellers/contracts.rb', line 62

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



62
63
64
# File 'lib/zeroclick/sellers/contracts.rb', line 62

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



62
63
64
# File 'lib/zeroclick/sellers/contracts.rb', line 62

def status
  @status
end

Class Method Details

.json(payload, status: 200, headers: {}) ⇒ Object



71
72
73
74
75
76
77
78
# File 'lib/zeroclick/sellers/contracts.rb', line 71

def self.json(payload, status: 200, headers: {})
  new(
    status: status,
    # Compact separators, matching the other SDKs byte for byte.
    body: JSON.generate(payload),
    headers: { "content-type" => "application/json" }.merge(headers)
  )
end

Instance Method Details

#json_bodyObject



80
81
82
# File 'lib/zeroclick/sellers/contracts.rb', line 80

def json_body
  JSON.parse(@body)
end