Class: Inttegro::Price::Response

Inherits:
T::Struct
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/inttegro/price/response.rb

Overview

Typed representation of the response object in the Inttegro API.

This generated model is immutable. Construct it with .new, or decode a string-keyed API payload with .from_hash. #serialize produces a string-keyed hash using the original wire field names and serialized enum values.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#price ⇒ Inttegro::Price::Fixed, Inttegro::Customer::SelectedCatalogPrice (readonly)

Value of the price field in the Inttegro API payload.

Required in the API payload. Wire name: price.



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
# File 'lib/inttegro/price/response.rb', line 25

class Response < T::Struct
  const :price, T.any(Inttegro::Price::Fixed, Inttegro::Customer::SelectedCatalogPrice)

  extend T::Sig

  sig { params(hash: T::Hash[String, Object], strict: T::Boolean).returns(T.attached_class) }
  def self.from_hash(hash, strict = false)
    data = hash.dup
    if (price_value = data["price"]).is_a?(Hash)
      data["price"] = case price_value["type"]
      when "fixed_amount"
        Inttegro::Price::Fixed.from_hash(price_value)
      when "customer_selected_amount"
        Inttegro::Customer::SelectedCatalogPrice.from_hash(price_value)
      else
        price_value
      end
    end
    super(data, strict)
  end
end

Class Method Details

.from_hash(hash, strict = false) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
# File 'lib/inttegro/price/response.rb', line 31

def self.from_hash(hash, strict = false)
  data = hash.dup
  if (price_value = data["price"]).is_a?(Hash)
    data["price"] = case price_value["type"]
    when "fixed_amount"
      Inttegro::Price::Fixed.from_hash(price_value)
    when "customer_selected_amount"
      Inttegro::Customer::SelectedCatalogPrice.from_hash(price_value)
    else
      price_value
    end
  end
  super(data, strict)
end