Class: ApiReference::NewCoupon

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/api_reference/models/new_coupon.rb

Overview

NewCoupon 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(redemption_code:, discount:, duration_in_months: SKIP, max_redemptions: SKIP) ⇒ NewCoupon

Returns a new instance of NewCoupon.



56
57
58
59
60
61
62
# File 'lib/api_reference/models/new_coupon.rb', line 56

def initialize(redemption_code:, discount:, duration_in_months: SKIP,
               max_redemptions: SKIP)
  @redemption_code = redemption_code
  @discount = discount
  @duration_in_months = duration_in_months unless duration_in_months == SKIP
  @max_redemptions = max_redemptions unless max_redemptions == SKIP
end

Instance Attribute Details

#discountObject

This string can be used to redeem this coupon for a given subscription.

Returns:

  • (Object)


18
19
20
# File 'lib/api_reference/models/new_coupon.rb', line 18

def discount
  @discount
end

#duration_in_monthsInteger

This allows for a coupon's discount to apply for a limited time (determined in months); a null value here means "unlimited time".

Returns:

  • (Integer)


23
24
25
# File 'lib/api_reference/models/new_coupon.rb', line 23

def duration_in_months
  @duration_in_months
end

#max_redemptionsInteger

The maximum number of redemptions allowed for this coupon before it is exhausted;null here means "unlimited".

Returns:

  • (Integer)


28
29
30
# File 'lib/api_reference/models/new_coupon.rb', line 28

def max_redemptions
  @max_redemptions
end

#redemption_codeString

This string can be used to redeem this coupon for a given subscription.

Returns:

  • (String)


14
15
16
# File 'lib/api_reference/models/new_coupon.rb', line 14

def redemption_code
  @redemption_code
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



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

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  redemption_code =
    hash.key?('redemption_code') ? hash['redemption_code'] : nil
  discount = hash.key?('discount') ? APIHelper.deserialize_union_type(
    UnionTypeLookUp.get(:NewCouponDiscount), hash['discount']
  ) : nil
  duration_in_months =
    hash.key?('duration_in_months') ? hash['duration_in_months'] : SKIP
  max_redemptions =
    hash.key?('max_redemptions') ? hash['max_redemptions'] : SKIP

  # Create object from extracted values.
  NewCoupon.new(redemption_code: redemption_code,
                discount: discount,
                duration_in_months: duration_in_months,
                max_redemptions: max_redemptions)
end

.namesObject

A mapping from model property names to API property names.



31
32
33
34
35
36
37
38
# File 'lib/api_reference/models/new_coupon.rb', line 31

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['redemption_code'] = 'redemption_code'
  @_hash['discount'] = 'discount'
  @_hash['duration_in_months'] = 'duration_in_months'
  @_hash['max_redemptions'] = 'max_redemptions'
  @_hash
end

.nullablesObject

An array for nullable fields



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

def self.nullables
  %w[
    duration_in_months
    max_redemptions
  ]
end

.optionalsObject

An array for optional fields



41
42
43
44
45
46
# File 'lib/api_reference/models/new_coupon.rb', line 41

def self.optionals
  %w[
    duration_in_months
    max_redemptions
  ]
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (NewCoupon | Hash)

    value against the validation is performed.



88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
# File 'lib/api_reference/models/new_coupon.rb', line 88

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.redemption_code,
                            ->(val) { val.instance_of? String }) and
        UnionTypeLookUp.get(:NewCouponDiscount)
                       .validate(value.discount)
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['redemption_code'],
                          ->(val) { val.instance_of? String }) and
      UnionTypeLookUp.get(:NewCouponDiscount)
                     .validate(value['discount'])
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



116
117
118
119
120
121
# File 'lib/api_reference/models/new_coupon.rb', line 116

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} redemption_code: #{@redemption_code.inspect}, discount:"\
  " #{@discount.inspect}, duration_in_months: #{@duration_in_months.inspect}, max_redemptions:"\
  " #{@max_redemptions.inspect}>"
end

#to_sObject

Provides a human-readable string representation of the object.



109
110
111
112
113
# File 'lib/api_reference/models/new_coupon.rb', line 109

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} redemption_code: #{@redemption_code}, discount: #{@discount},"\
  " duration_in_months: #{@duration_in_months}, max_redemptions: #{@max_redemptions}>"
end