Class: AdvancedBilling::OfferItem

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

Overview

OfferItem Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(component_id: SKIP, price_point_id: SKIP, starting_quantity: SKIP, editable: SKIP, component_unit_price: SKIP, component_name: SKIP, price_point_name: SKIP, currency_prices: SKIP, interval: SKIP, interval_unit: SKIP, additional_properties: {}) ⇒ OfferItem

Returns a new instance of OfferItem.



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

def initialize(component_id: SKIP, price_point_id: SKIP,
               starting_quantity: SKIP, editable: SKIP,
               component_unit_price: SKIP, component_name: SKIP,
               price_point_name: SKIP, currency_prices: SKIP,
               interval: SKIP, interval_unit: SKIP,
               additional_properties: {})
  @component_id = component_id unless component_id == SKIP
  @price_point_id = price_point_id unless price_point_id == SKIP
  @starting_quantity = starting_quantity unless starting_quantity == SKIP
  @editable = editable unless editable == SKIP
  @component_unit_price = component_unit_price unless component_unit_price == SKIP
  @component_name = component_name unless component_name == SKIP
  @price_point_name = price_point_name unless price_point_name == SKIP
  @currency_prices = currency_prices unless currency_prices == SKIP
  @interval = interval unless interval == SKIP
  @interval_unit = interval_unit unless interval_unit == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#component_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def component_id
  @component_id
end

#component_nameString

TODO: Write general description for this method

Returns:

  • (String)


34
35
36
# File 'lib/advanced_billing/models/offer_item.rb', line 34

def component_name
  @component_name
end

#component_unit_priceString

TODO: Write general description for this method

Returns:

  • (String)


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

def component_unit_price
  @component_unit_price
end

#currency_pricesArray[CurrencyPrice]

TODO: Write general description for this method

Returns:



42
43
44
# File 'lib/advanced_billing/models/offer_item.rb', line 42

def currency_prices
  @currency_prices
end

#editableTrueClass | FalseClass

TODO: Write general description for this method

Returns:

  • (TrueClass | FalseClass)


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

def editable
  @editable
end

#intervalInteger

The numerical interval. i.e. an interval of ‘30’ coupled with an interval_unit of day would mean this component price point would renew every 30 days. This property is only available for sites with Multifrequency enabled.

Returns:

  • (Integer)


49
50
51
# File 'lib/advanced_billing/models/offer_item.rb', line 49

def interval
  @interval
end

#interval_unitIntervalUnit

A string representing the interval unit for this component price point, either month or day. This property is only available for sites with Multifrequency enabled.

Returns:



55
56
57
# File 'lib/advanced_billing/models/offer_item.rb', line 55

def interval_unit
  @interval_unit
end

#price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def price_point_id
  @price_point_id
end

#price_point_nameString

TODO: Write general description for this method

Returns:

  • (String)


38
39
40
# File 'lib/advanced_billing/models/offer_item.rb', line 38

def price_point_name
  @price_point_name
end

#starting_quantityString

TODO: Write general description for this method

Returns:

  • (String)


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

def starting_quantity
  @starting_quantity
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
# File 'lib/advanced_billing/models/offer_item.rb', line 120

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  component_id = hash.key?('component_id') ? hash['component_id'] : SKIP
  price_point_id =
    hash.key?('price_point_id') ? hash['price_point_id'] : SKIP
  starting_quantity =
    hash.key?('starting_quantity') ? hash['starting_quantity'] : SKIP
  editable = hash.key?('editable') ? hash['editable'] : SKIP
  component_unit_price =
    hash.key?('component_unit_price') ? hash['component_unit_price'] : SKIP
  component_name =
    hash.key?('component_name') ? hash['component_name'] : SKIP
  price_point_name =
    hash.key?('price_point_name') ? hash['price_point_name'] : SKIP
  # Parameter is an array, so we need to iterate through it
  currency_prices = nil
  unless hash['currency_prices'].nil?
    currency_prices = []
    hash['currency_prices'].each do |structure|
      currency_prices << (CurrencyPrice.from_hash(structure) if structure)
    end
  end

  currency_prices = SKIP unless hash.key?('currency_prices')
  interval = hash.key?('interval') ? hash['interval'] : SKIP
  interval_unit = hash.key?('interval_unit') ? hash['interval_unit'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  OfferItem.new(component_id: component_id,
                price_point_id: price_point_id,
                starting_quantity: starting_quantity,
                editable: editable,
                component_unit_price: component_unit_price,
                component_name: component_name,
                price_point_name: price_point_name,
                currency_prices: currency_prices,
                interval: interval,
                interval_unit: interval_unit,
                additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['component_id'] = 'component_id'
  @_hash['price_point_id'] = 'price_point_id'
  @_hash['starting_quantity'] = 'starting_quantity'
  @_hash['editable'] = 'editable'
  @_hash['component_unit_price'] = 'component_unit_price'
  @_hash['component_name'] = 'component_name'
  @_hash['price_point_name'] = 'price_point_name'
  @_hash['currency_prices'] = 'currency_prices'
  @_hash['interval'] = 'interval'
  @_hash['interval_unit'] = 'interval_unit'
  @_hash
end

.nullablesObject

An array for nullable fields



90
91
92
93
94
# File 'lib/advanced_billing/models/offer_item.rb', line 90

def self.nullables
  %w[
    interval_unit
  ]
end

.optionalsObject

An array for optional fields



74
75
76
77
78
79
80
81
82
83
84
85
86
87
# File 'lib/advanced_billing/models/offer_item.rb', line 74

def self.optionals
  %w[
    component_id
    price_point_id
    starting_quantity
    editable
    component_unit_price
    component_name
    price_point_name
    currency_prices
    interval
    interval_unit
  ]
end