Class: AdvancedBilling::CreateOffer

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

Overview

CreateOffer Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

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

Constructor Details

#initialize(name:, handle:, product_id:, description: SKIP, product_price_point_id: SKIP, components: SKIP, coupons: SKIP, additional_properties: {}) ⇒ CreateOffer

Returns a new instance of CreateOffer.



68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
# File 'lib/advanced_billing/models/create_offer.rb', line 68

def initialize(name:, handle:, product_id:, description: SKIP,
               product_price_point_id: SKIP, components: SKIP,
               coupons: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @name = name
  @handle = handle
  @description = description unless description == SKIP
  @product_id = product_id
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  @components = components unless components == SKIP
  @coupons = coupons unless coupons == SKIP
end

Instance Attribute Details

#componentsArray[CreateOfferComponent]

TODO: Write general description for this method

Returns:



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

def components
  @components
end

#couponsArray[String]

TODO: Write general description for this method

Returns:

  • (Array[String])


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

def coupons
  @coupons
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


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

def description
  @description
end

#handleString

TODO: Write general description for this method

Returns:

  • (String)


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

def handle
  @handle
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


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

def name
  @name
end

#product_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def product_id
  @product_id
end

#product_price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def product_price_point_id
  @product_price_point_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
# File 'lib/advanced_billing/models/create_offer.rb', line 86

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : nil
  handle = hash.key?('handle') ? hash['handle'] : nil
  product_id = hash.key?('product_id') ? hash['product_id'] : nil
  description = hash.key?('description') ? hash['description'] : SKIP
  product_price_point_id =
    hash.key?('product_price_point_id') ? hash['product_price_point_id'] : SKIP
  # Parameter is an array, so we need to iterate through it
  components = nil
  unless hash['components'].nil?
    components = []
    hash['components'].each do |structure|
      components << (CreateOfferComponent.from_hash(structure) if structure)
    end
  end

  components = SKIP unless hash.key?('components')
  coupons = hash.key?('coupons') ? hash['coupons'] : SKIP

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

  # Create object from extracted values.
  CreateOffer.new(name: name,
                  handle: handle,
                  product_id: product_id,
                  description: description,
                  product_price_point_id: product_price_point_id,
                  components: components,
                  coupons: coupons,
                  additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



41
42
43
44
45
46
47
48
49
50
51
# File 'lib/advanced_billing/models/create_offer.rb', line 41

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['description'] = 'description'
  @_hash['product_id'] = 'product_id'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['components'] = 'components'
  @_hash['coupons'] = 'coupons'
  @_hash
end

.nullablesObject

An array for nullable fields



64
65
66
# File 'lib/advanced_billing/models/create_offer.rb', line 64

def self.nullables
  []
end

.optionalsObject

An array for optional fields



54
55
56
57
58
59
60
61
# File 'lib/advanced_billing/models/create_offer.rb', line 54

def self.optionals
  %w[
    description
    product_price_point_id
    components
    coupons
  ]
end