Class: AdvancedBilling::ScheduledRenewalItemRequestBodyComponent

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb

Overview

ScheduledRenewalItemRequestBodyComponent Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#check_for_conflict, #get_additional_properties, #process_additional_properties, #process_array, #process_basic_value, #process_hash, #to_hash, #to_json

Constructor Details

#initialize(item_id:, price_point_id: SKIP, quantity: SKIP, custom_price: SKIP, additional_properties: {}) ⇒ ScheduledRenewalItemRequestBodyComponent

Returns a new instance of ScheduledRenewalItemRequestBodyComponent.



57
58
59
60
61
62
63
64
65
66
67
68
69
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 57

def initialize(item_id:, price_point_id: SKIP, quantity: SKIP,
               custom_price: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @item_type = 'Component'
  @item_id = item_id
  @price_point_id = price_point_id unless price_point_id == SKIP
  @quantity = quantity unless quantity == SKIP
  @custom_price = custom_price unless custom_price == SKIP
end

Instance Attribute Details

#custom_priceScheduledRenewalComponentCustomPrice

Custom pricing for a component within a scheduled renewal.



30
31
32
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 30

def custom_price
  @custom_price
end

#item_idInteger

Product or component identifier.

Returns:

  • (Integer)


18
19
20
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 18

def item_id
  @item_id
end

#item_typeString (readonly)

Item type to add. Either Product or Component.

Returns:

  • (String)


14
15
16
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 14

def item_type
  @item_type
end

#price_point_idInteger

Price point identifier.

Returns:

  • (Integer)


22
23
24
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 22

def price_point_id
  @price_point_id
end

#quantityInteger

Optional quantity for the item.

Returns:

  • (Integer)


26
27
28
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 26

def quantity
  @quantity
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 72

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  item_id = hash.key?('item_id') ? hash['item_id'] : nil
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  quantity = hash.key?('quantity') ? hash['quantity'] : SKIP
  custom_price = ScheduledRenewalComponentCustomPrice.from_hash(hash['custom_price']) if
    hash['custom_price']

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  ScheduledRenewalItemRequestBodyComponent.new(item_id: item_id,
                                               price_point_id: price_point_id,
                                               quantity: quantity,
                                               custom_price: custom_price,
                                               additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



33
34
35
36
37
38
39
40
41
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 33

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['item_type'] = 'item_type'
  @_hash['item_id'] = 'item_id'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['quantity'] = 'quantity'
  @_hash['custom_price'] = 'custom_price'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 53

def self.nullables
  []
end

.optionalsObject

An array for optional fields



44
45
46
47
48
49
50
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 44

def self.optionals
  %w[
    price_point_id
    quantity
    custom_price
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 96

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.item_type,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.item_id,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['item_type'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['item_id'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



125
126
127
128
129
130
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 125

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} item_type: #{@item_type.inspect}, item_id: #{@item_id.inspect},"\
  " price_point_id: #{@price_point_id.inspect}, quantity: #{@quantity.inspect}, custom_price:"\
  " #{@custom_price.inspect}, additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



117
118
119
120
121
122
# File 'lib/advanced_billing/models/scheduled_renewal_item_request_body_component.rb', line 117

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} item_type: #{@item_type}, item_id: #{@item_id}, price_point_id:"\
  " #{@price_point_id}, quantity: #{@quantity}, custom_price: #{@custom_price},"\
  " additional_properties: #{get_additional_properties}>"
end