Class: PCPServerSDK::Models::ModelBase

Inherits:
Object
  • Object
show all
Defined in:
lib/PCP-server-Ruby-SDK/models/model_base.rb

Direct Known Subclasses

APIError, Address, AddressPersonal, AmountOfMoney, ApplePaymentDataTokenHeaderInformation, ApplePaymentDataTokenInformation, AuthenticationToken, BankAccountInformation, BankPayoutMethodSpecificInput, CancelItem, CancelPaymentRequest, CancelPaymentResponse, CancelRequest, CancelResponse, CaptureOutput, CapturePaymentRequest, CapturePaymentResponse, CardFraudResults, CardInfo, CardPaymentDetails, CardPaymentMethodSpecificInput, CardPaymentMethodSpecificOutput, CardRecurrenceDetails, CartItemData, CartItemInvoiceData, CartItemOrderStatus, CartItemPatch, CartItemResult, CartItemSupplierReferences, CheckoutReferences, CheckoutResponse, CheckoutsResponse, CompanyInformation, CompleteFinancingPaymentMethodSpecificInput, CompleteOrderRequest, CompletePaymentMethodSpecificInput, CompletePaymentProduct840SpecificInput, CompletePaymentRequest, CompletePaymentResponse, CompleteRedirectPaymentMethodSpecificInput, ContactDetails, CreateCheckoutRequest, CreateCheckoutResponse, CreateCommerceCaseResponse, CreatePayByLinkRequest, CreatePayByLinkResponse, CreatePaymentIntent, CreatePaymentIntentResponse, CreatePaymentResponse, Customer, CustomerAccount, CustomerDevice, DeliverItem, DeliverRequest, DeliverResponse, DeliveryInformation, ErrorResponse, FinancingPaymentMethodSpecificInput, FinancingPaymentMethodSpecificOutput, FundDistribution, FundSplit, FundSplitRequest, FundSplitResponse, InstallmentOption, LinkInformation, MerchantAction, MobilePaymentMethodSpecificInput, MobilePaymentMethodSpecificOutput, MobilePaymentThreeDSecure, Order, OrderItem, OrderLineDetailsInput, OrderRequest, OrderResponse, PatchCheckoutRequest, PatchCommerceCaseRequest, PausePaymentRequest, PausePaymentResponse, Payee, PaymentCreationOutput, PaymentEvent, PaymentExecution, PaymentExecutionRequest, PaymentExecutionSpecificInput, PaymentInformationRefundRequest, PaymentInformationRefundResponse, PaymentInformationRequest, PaymentInformationResponse, PaymentInstructions, PaymentIntentResponseData, PaymentLinkOrder, PaymentLinkSpecificInput, PaymentMethodSpecificInput, PaymentMethodSpecificInputForIntent, PaymentOutput, PaymentProduct302SpecificInput, PaymentProduct3391SpecificInput, PaymentProduct3391SpecificOutput, PaymentProduct3392SpecificInput, PaymentProduct5002SpecificInput, PaymentProduct771SpecificOutput, PaymentProduct840CustomerAccount, PaymentProduct840CustomerAccountForIntent, PaymentProduct840SpecificOutput, PaymentProduct840SpecificOutputForIntent, PaymentReferences, PaymentResponse, PaymentStatusOutput, PayoutOutput, PayoutResponse, PersonalInformation, PersonalName, PositiveAmountOfMoney, ProcessingMandateInformation, RedirectData, RedirectPaymentMethodSpecificInput, RedirectPaymentMethodSpecificInputForIntent, RedirectPaymentMethodSpecificOutput, RedirectPaymentMethodSpecificOutputForCreateIntent, RedirectPaymentMethodSpecificOutputForIntent, RedirectPaymentProduct840SpecificInputData, RedirectPaymentProduct900SpecificInput, RedirectionData, References, RefreshPaymentRequest, RefundErrorResponse, RefundOutput, RefundPaymentResponse, RefundRequest, ReturnInformation, ReturnItem, ReturnRequest, ReturnResponse, SepaDirectDebitPaymentMethodSpecificInput, SepaDirectDebitPaymentMethodSpecificOutput, SepaDirectDebitPaymentProduct771SpecificInput, SepaTransferPaymentProduct772SpecificInput, Shipping, ShoppingCartData, ShoppingCartInput, ShoppingCartPatch, ShoppingCartResult, StatusOutput, ThreeDSecureResults

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(attributes = {}) ⇒ ModelBase

Returns a new instance of ModelBase.

Raises:

  • (ArgumentError)


101
102
103
104
105
106
107
108
109
110
111
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 101

def initialize(attributes = {})
  raise ArgumentError, "The input argument must be a hash" unless attributes.is_a?(Hash)

  self.class.attribute_defaults.each { |name, value| public_send("#{name}=", value) }
  attributes.each do |name, value|
    name = name.to_sym
    raise ArgumentError, "`#{name}` is not a valid attribute" unless self.class.attribute_map.key?(name)

    public_send("#{name}=", value)
  end
end

Class Method Details

._deserialize(type, value) ⇒ Object



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 72

def _deserialize(type, value)
  return nil if value.nil?

  type_name = type.to_s

  case type_name
  when 'Time' then Time.parse(value)
  when 'Date' then Date.parse(value)
  when 'String' then value.to_s
  when 'Integer' then value.to_i
  when 'Float' then value.to_f
  when 'Boolean' then value.to_s.match?(/\A(true|t|yes|y|1)\z/i)
  when 'Object' then value
  when /\AArray<(?<inner_type>.+)>\z/
    inner_type = Regexp.last_match[:inner_type]
    value.map { |item| _deserialize(inner_type, item) }
  when /\AHash<(?<key_type>.+?), (?<value_type>.+)>\z/
    key_type = Regexp.last_match[:key_type]
    value_type = Regexp.last_match[:value_type]
    value.each_with_object({}) do |(key, item), result|
      result[_deserialize(key_type, key)] = _deserialize(value_type, item)
    end
  else
    klass = PCPServerSDK::Models.const_get(type_name)
    klass.respond_to?(:openapi_any_of) || klass.respond_to?(:openapi_one_of) ? klass.build(value) : klass.build_from_hash(value)
  end
end

.acceptable_attributes ⇒ Object



54
55
56
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 54

def acceptable_attributes
  attribute_map.values
end

.attribute(name, json_name, type, default: nil, enum: nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 22

def attribute(name, json_name, type, default: nil, enum: nil)
  define_method(name) { instance_variable_get("@#{name}") }
  define_method("#{name}=") do |value|
    allowed_values = self.class.attribute_enums[name]
    if !value.nil? && allowed_values && !allowed_values.include?(value)
      raise ArgumentError, "invalid value for \"#{name}\", must be one of #{allowed_values.inspect}."
    end

    instance_variable_set("@#{name}", value)
  end
  @attribute_map[name] = json_name
  @openapi_types[name] = type
  @attribute_defaults[name] = default unless default.nil?
  @attribute_enums[name] = enum if enum
end

.attribute_defaults ⇒ Object



46
47
48
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 46

def attribute_defaults
  @attribute_defaults
end

.attribute_enums ⇒ Object



50
51
52
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 50

def attribute_enums
  @attribute_enums
end

.attribute_map ⇒ Object



38
39
40
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 38

def attribute_map
  @attribute_map
end

.build_from_hash(attributes) ⇒ Object



62
63
64
65
66
67
68
69
70
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 62

def build_from_hash(attributes)
  return nil unless attributes.is_a?(Hash)

  values = attributes.each_with_object({}) { |(key, value), result| result[key.to_s] = value }
  new(openapi_types.each_with_object({}) do |(name, type), result|
    json_name = attribute_map[name].to_s
    result[name] = values.key?(json_name) ? _deserialize(type, values[json_name]) : nil if values.key?(json_name)
  end)
end

.inherited(subclass) ⇒ Object



14
15
16
17
18
19
20
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 14

def inherited(subclass)
  subclass.instance_variable_set(:@attribute_map, attribute_map.dup)
  subclass.instance_variable_set(:@openapi_types, openapi_types.dup)
  subclass.instance_variable_set(:@attribute_defaults, attribute_defaults.dup)
  subclass.instance_variable_set(:@attribute_enums, attribute_enums.dup)
  super
end

.openapi_nullable ⇒ Object



58
59
60
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 58

def openapi_nullable
  Set.new
end

.openapi_types ⇒ Object



42
43
44
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 42

def openapi_types
  @openapi_types
end

Instance Method Details

#==(other) ⇒ Object Also known as: eql?



113
114
115
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 113

def ==(other)
  self.class == other.class && self.class.attribute_map.keys.all? { |name| public_send(name) == other.public_send(name) }
end

#hash ⇒ Object



119
120
121
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 119

def hash
  self.class.attribute_map.keys.map { |name| public_send(name) }.hash
end

#to_hash ⇒ Object Also known as: to_body



127
128
129
130
131
132
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 127

def to_hash
  self.class.attribute_map.each_with_object({}) do |(name, json_name), result|
    value = public_send(name)
    result[json_name] = to_value(value) unless value.nil?
  end
end

#to_s ⇒ Object



123
124
125
# File 'lib/PCP-server-Ruby-SDK/models/model_base.rb', line 123

def to_s
  to_hash.to_s
end