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

#to_hash, #to_json

Constructor Details

#initialize(name = SKIP, handle = SKIP, description = SKIP, product_id = SKIP, product_price_point_id = SKIP, components = SKIP, coupons = SKIP) ⇒ CreateOffer

Returns a new instance of CreateOffer.



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

def initialize(name = SKIP, handle = SKIP, description = SKIP,
               product_id = SKIP, product_price_point_id = SKIP,
               components = SKIP, coupons = SKIP)
  @name = name unless name == SKIP
  @handle = handle unless handle == SKIP
  @description = description unless description == SKIP
  @product_id = product_id unless product_id == SKIP
  @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.



84
85
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
# File 'lib/advanced_billing/models/create_offer.rb', line 84

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  name = hash.key?('name') ? hash['name'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  product_id = hash.key?('product_id') ? hash['product_id'] : 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

  # Create object from extracted values.
  CreateOffer.new(name,
                  handle,
                  description,
                  product_id,
                  product_price_point_id,
                  components,
                  coupons)
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



67
68
69
# File 'lib/advanced_billing/models/create_offer.rb', line 67

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

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