Class: AdvancedBilling::CouponRequest

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

Overview

CouponRequest Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

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

Constructor Details

#initialize(coupon: SKIP, restricted_products: SKIP, restricted_components: SKIP, additional_properties: {}) ⇒ CouponRequest

Returns a new instance of CouponRequest.



51
52
53
54
55
56
57
58
59
60
61
# File 'lib/advanced_billing/models/coupon_request.rb', line 51

def initialize(coupon: SKIP, restricted_products: SKIP,
               restricted_components: SKIP, additional_properties: {})
  # Add additional model properties to the instance.

  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @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

#couponCouponPayload

TODO: Write general description for this method

Returns:



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

def coupon
  @coupon
end

#restricted_componentsHash[String, TrueClass | FalseClass]

An object where the keys are component IDs or handles (prefixed with ‘handle:’), and the values are booleans indicating if the coupon should be applicable to the component

Returns:

  • (Hash[String, TrueClass | FalseClass])


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

def restricted_components
  @restricted_components
end

#restricted_productsHash[String, TrueClass | FalseClass]

An object where the keys are product IDs or handles (prefixed with ‘handle:’), and the values are booleans indicating if the coupon should be applicable to the product

Returns:

  • (Hash[String, TrueClass | FalseClass])


20
21
22
# File 'lib/advanced_billing/models/coupon_request.rb', line 20

def restricted_products
  @restricted_products
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/advanced_billing/models/coupon_request.rb', line 64

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.

  coupon = CouponPayload.from_hash(hash['coupon']) if hash['coupon']
  restricted_products =
    hash.key?('restricted_products') ? hash['restricted_products'] : SKIP
  restricted_components =
    hash.key?('restricted_components') ? hash['restricted_components'] : SKIP

  # Clean out expected properties from Hash.

  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.

  CouponRequest.new(coupon: coupon,
                    restricted_products: restricted_products,
                    restricted_components: restricted_components,
                    additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



29
30
31
32
33
34
35
# File 'lib/advanced_billing/models/coupon_request.rb', line 29

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



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

def self.nullables
  []
end

.optionalsObject

An array for optional fields



38
39
40
41
42
43
44
# File 'lib/advanced_billing/models/coupon_request.rb', line 38

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

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



93
94
95
96
97
98
# File 'lib/advanced_billing/models/coupon_request.rb', line 93

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon: #{@coupon.inspect}, restricted_products:"\
  " #{@restricted_products.inspect}, restricted_components: #{@restricted_components.inspect},"\
  " additional_properties: #{get_additional_properties}>"
end

#to_sObject

Provides a human-readable string representation of the object.



85
86
87
88
89
90
# File 'lib/advanced_billing/models/coupon_request.rb', line 85

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} coupon: #{@coupon}, restricted_products: #{@restricted_products},"\
  " restricted_components: #{@restricted_components}, additional_properties:"\
  " #{get_additional_properties}>"
end