Class: AdvancedBilling::Offer

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

Overview

Offer 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(id: SKIP, site_id: SKIP, product_family_id: SKIP, product_id: SKIP, product_price_point_id: SKIP, product_revisable_number: SKIP, name: SKIP, handle: SKIP, description: SKIP, created_at: SKIP, updated_at: SKIP, archived_at: SKIP, offer_items: SKIP, offer_discounts: SKIP, product_family_name: SKIP, product_name: SKIP, product_price_point_name: SKIP, product_price_in_cents: SKIP, offer_signup_pages: SKIP, additional_properties: {}) ⇒ Offer

Returns a new instance of Offer.



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
# File 'lib/advanced_billing/models/offer.rb', line 147

def initialize(id: SKIP, site_id: SKIP, product_family_id: SKIP,
               product_id: SKIP, product_price_point_id: SKIP,
               product_revisable_number: SKIP, name: SKIP, handle: SKIP,
               description: SKIP, created_at: SKIP, updated_at: SKIP,
               archived_at: SKIP, offer_items: SKIP, offer_discounts: SKIP,
               product_family_name: SKIP, product_name: SKIP,
               product_price_point_name: SKIP, product_price_in_cents: SKIP,
               offer_signup_pages: SKIP, additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @id = id unless id == SKIP
  @site_id = site_id unless site_id == SKIP
  @product_family_id = product_family_id unless product_family_id == SKIP
  @product_id = product_id unless product_id == SKIP
  @product_price_point_id = product_price_point_id unless product_price_point_id == SKIP
  @product_revisable_number = product_revisable_number unless product_revisable_number == SKIP
  @name = name unless name == SKIP
  @handle = handle unless handle == SKIP
  @description = description unless description == SKIP
  @created_at = created_at unless created_at == SKIP
  @updated_at = updated_at unless updated_at == SKIP
  @archived_at = archived_at unless archived_at == SKIP
  @offer_items = offer_items unless offer_items == SKIP
  @offer_discounts = offer_discounts unless offer_discounts == SKIP
  @product_family_name = product_family_name unless product_family_name == SKIP
  @product_name = product_name unless product_name == SKIP
  @product_price_point_name = product_price_point_name unless product_price_point_name == SKIP
  @product_price_in_cents = product_price_in_cents unless product_price_in_cents == SKIP
  @offer_signup_pages =  unless  == SKIP
end

Instance Attribute Details

#archived_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


59
60
61
# File 'lib/advanced_billing/models/offer.rb', line 59

def archived_at
  @archived_at
end

#created_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


51
52
53
# File 'lib/advanced_billing/models/offer.rb', line 51

def created_at
  @created_at
end

#descriptionString

TODO: Write general description for this method

Returns:

  • (String)


47
48
49
# File 'lib/advanced_billing/models/offer.rb', line 47

def description
  @description
end

#handleString

TODO: Write general description for this method

Returns:

  • (String)


43
44
45
# File 'lib/advanced_billing/models/offer.rb', line 43

def handle
  @handle
end

#idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


15
16
17
# File 'lib/advanced_billing/models/offer.rb', line 15

def id
  @id
end

#nameString

TODO: Write general description for this method

Returns:

  • (String)


39
40
41
# File 'lib/advanced_billing/models/offer.rb', line 39

def name
  @name
end

#offer_discountsArray[OfferDiscount]

TODO: Write general description for this method

Returns:



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

def offer_discounts
  @offer_discounts
end

#offer_itemsArray[OfferItem]

TODO: Write general description for this method

Returns:



63
64
65
# File 'lib/advanced_billing/models/offer.rb', line 63

def offer_items
  @offer_items
end

#offer_signup_pagesArray[OfferSignupPage]

TODO: Write general description for this method

Returns:



87
88
89
# File 'lib/advanced_billing/models/offer.rb', line 87

def 
  @offer_signup_pages
end

#product_family_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


23
24
25
# File 'lib/advanced_billing/models/offer.rb', line 23

def product_family_id
  @product_family_id
end

#product_family_nameString

TODO: Write general description for this method

Returns:

  • (String)


71
72
73
# File 'lib/advanced_billing/models/offer.rb', line 71

def product_family_name
  @product_family_name
end

#product_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


27
28
29
# File 'lib/advanced_billing/models/offer.rb', line 27

def product_id
  @product_id
end

#product_nameString

TODO: Write general description for this method

Returns:

  • (String)


75
76
77
# File 'lib/advanced_billing/models/offer.rb', line 75

def product_name
  @product_name
end

#product_price_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


83
84
85
# File 'lib/advanced_billing/models/offer.rb', line 83

def product_price_in_cents
  @product_price_in_cents
end

#product_price_point_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


31
32
33
# File 'lib/advanced_billing/models/offer.rb', line 31

def product_price_point_id
  @product_price_point_id
end

#product_price_point_nameString

TODO: Write general description for this method

Returns:

  • (String)


79
80
81
# File 'lib/advanced_billing/models/offer.rb', line 79

def product_price_point_name
  @product_price_point_name
end

#product_revisable_numberInteger

TODO: Write general description for this method

Returns:

  • (Integer)


35
36
37
# File 'lib/advanced_billing/models/offer.rb', line 35

def product_revisable_number
  @product_revisable_number
end

#site_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


19
20
21
# File 'lib/advanced_billing/models/offer.rb', line 19

def site_id
  @site_id
end

#updated_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


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

def updated_at
  @updated_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
# File 'lib/advanced_billing/models/offer.rb', line 182

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  site_id = hash.key?('site_id') ? hash['site_id'] : SKIP
  product_family_id =
    hash.key?('product_family_id') ? hash['product_family_id'] : 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
  product_revisable_number =
    hash.key?('product_revisable_number') ? hash['product_revisable_number'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  handle = hash.key?('handle') ? hash['handle'] : SKIP
  description = hash.key?('description') ? hash['description'] : SKIP
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               else
                 SKIP
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               else
                 SKIP
               end
  archived_at = if hash.key?('archived_at')
                  (DateTimeHelper.from_rfc3339(hash['archived_at']) if hash['archived_at'])
                else
                  SKIP
                end
  # Parameter is an array, so we need to iterate through it
  offer_items = nil
  unless hash['offer_items'].nil?
    offer_items = []
    hash['offer_items'].each do |structure|
      offer_items << (OfferItem.from_hash(structure) if structure)
    end
  end

  offer_items = SKIP unless hash.key?('offer_items')
  # Parameter is an array, so we need to iterate through it
  offer_discounts = nil
  unless hash['offer_discounts'].nil?
    offer_discounts = []
    hash['offer_discounts'].each do |structure|
      offer_discounts << (OfferDiscount.from_hash(structure) if structure)
    end
  end

  offer_discounts = SKIP unless hash.key?('offer_discounts')
  product_family_name =
    hash.key?('product_family_name') ? hash['product_family_name'] : SKIP
  product_name = hash.key?('product_name') ? hash['product_name'] : SKIP
  product_price_point_name =
    hash.key?('product_price_point_name') ? hash['product_price_point_name'] : SKIP
  product_price_in_cents =
    hash.key?('product_price_in_cents') ? hash['product_price_in_cents'] : SKIP
  # Parameter is an array, so we need to iterate through it
   = nil
  unless hash['offer_signup_pages'].nil?
     = []
    hash['offer_signup_pages'].each do |structure|
       << (OfferSignupPage.from_hash(structure) if structure)
    end
  end

   = SKIP unless hash.key?('offer_signup_pages')

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

  # Create object from extracted values.
  Offer.new(id: id,
            site_id: site_id,
            product_family_id: product_family_id,
            product_id: product_id,
            product_price_point_id: product_price_point_id,
            product_revisable_number: product_revisable_number,
            name: name,
            handle: handle,
            description: description,
            created_at: created_at,
            updated_at: updated_at,
            archived_at: archived_at,
            offer_items: offer_items,
            offer_discounts: offer_discounts,
            product_family_name: product_family_name,
            product_name: product_name,
            product_price_point_name: product_price_point_name,
            product_price_in_cents: product_price_in_cents,
            offer_signup_pages: ,
            additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
# File 'lib/advanced_billing/models/offer.rb', line 90

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['site_id'] = 'site_id'
  @_hash['product_family_id'] = 'product_family_id'
  @_hash['product_id'] = 'product_id'
  @_hash['product_price_point_id'] = 'product_price_point_id'
  @_hash['product_revisable_number'] = 'product_revisable_number'
  @_hash['name'] = 'name'
  @_hash['handle'] = 'handle'
  @_hash['description'] = 'description'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['archived_at'] = 'archived_at'
  @_hash['offer_items'] = 'offer_items'
  @_hash['offer_discounts'] = 'offer_discounts'
  @_hash['product_family_name'] = 'product_family_name'
  @_hash['product_name'] = 'product_name'
  @_hash['product_price_point_name'] = 'product_price_point_name'
  @_hash['product_price_in_cents'] = 'product_price_in_cents'
  @_hash['offer_signup_pages'] = 'offer_signup_pages'
  @_hash
end

.nullablesObject

An array for nullable fields



140
141
142
143
144
145
# File 'lib/advanced_billing/models/offer.rb', line 140

def self.nullables
  %w[
    description
    archived_at
  ]
end

.optionalsObject

An array for optional fields



115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/advanced_billing/models/offer.rb', line 115

def self.optionals
  %w[
    id
    site_id
    product_family_id
    product_id
    product_price_point_id
    product_revisable_number
    name
    handle
    description
    created_at
    updated_at
    archived_at
    offer_items
    offer_discounts
    product_family_name
    product_name
    product_price_point_name
    product_price_in_cents
    offer_signup_pages
  ]
end

Instance Method Details

#to_custom_archived_atObject



285
286
287
# File 'lib/advanced_billing/models/offer.rb', line 285

def to_custom_archived_at
  DateTimeHelper.to_rfc3339(archived_at)
end

#to_custom_created_atObject



277
278
279
# File 'lib/advanced_billing/models/offer.rb', line 277

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_updated_atObject



281
282
283
# File 'lib/advanced_billing/models/offer.rb', line 281

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end