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.



68
69
70
71
72
73
# File 'lib/zeroclick/sellers/contracts.rb', line 68

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.



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

def body
  @body
end

#headersObject (readonly)

Returns the value of attribute headers.



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

def headers
  @headers
end

#statusObject (readonly)

Returns the value of attribute status.



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

def status
  @status
end

Class Method Details

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



75
76
77
78
79
80
81
82
# File 'lib/zeroclick/sellers/contracts.rb', line 75

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



84
85
86
# File 'lib/zeroclick/sellers/contracts.rb', line 84

def json_body
  JSON.parse(@body)
end