Class: AdvancedBilling::CreateOrUpdateCoupon

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

Overview

CreateOrUpdateCoupon Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(coupon = SKIP, restricted_products = SKIP, restricted_components = SKIP) ⇒ CreateOrUpdateCoupon

Returns a new instance of CreateOrUpdateCoupon.



49
50
51
52
53
54
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 49

def initialize(coupon = SKIP, restricted_products = SKIP,
               restricted_components = SKIP)
  @coupon = coupon unless coupon == SKIP
  @restricted_products = restricted_products unless restricted_products == SKIP
  @restricted_components = restricted_components unless restricted_components == SKIP
end

Instance Attribute Details

#couponObject

TODO: Write general description for this method

Returns:

  • (Object)


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

def coupon
  @coupon
end

#restricted_componentsHash[String, TrueClass | FalseClass]

An object where the keys are component_ids and the values are booleans indicating if the coupon should be applicable to the component

Returns:

  • (Hash[String, TrueClass | FalseClass])


24
25
26
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 24

def restricted_components
  @restricted_components
end

#restricted_productsHash[String, TrueClass | FalseClass]

An object where the keys are product_ids and the values are booleans indicating if the coupon should be applicable to the product

Returns:

  • (Hash[String, TrueClass | FalseClass])


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

def restricted_products
  @restricted_products
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  coupon = hash.key?('coupon') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:CreateOrUpdateCouponCoupon), hash['coupon']
  ) : SKIP
  restricted_products =
    hash.key?('restricted_products') ? hash['restricted_products'] : SKIP
  restricted_components =
    hash.key?('restricted_components') ? hash['restricted_components'] : SKIP

  # Create object from extracted values.

  CreateOrUpdateCoupon.new(coupon,
                           restricted_products,
                           restricted_components)
end

.namesObject

A mapping from model property names to API property names.



27
28
29
30
31
32
33
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 27

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['coupon'] = 'coupon'
  @_hash['restricted_products'] = 'restricted_products'
  @_hash['restricted_components'] = 'restricted_components'
  @_hash
end

.nullablesObject

An array for nullable fields



45
46
47
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 45

def self.nullables
  []
end

.optionalsObject

An array for optional fields



36
37
38
39
40
41
42
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 36

def self.optionals
  %w[
    coupon
    restricted_products
    restricted_components
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:



77
78
79
80
81
82
83
# File 'lib/advanced_billing/models/create_or_update_coupon.rb', line 77

def self.validate(value)
  return true if value.instance_of? self

  return false unless value.instance_of? Hash

  true
end