Class: AdvancedBilling::CouponUsage

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

Overview

CouponUsage Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(id: SKIP, name: SKIP, signups: SKIP, savings: SKIP, savings_in_cents: SKIP, revenue: SKIP, revenue_in_cents: SKIP, additional_properties: {}) ⇒ CouponUsage

Returns a new instance of CouponUsage.



77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/advanced_billing/models/coupon_usage.rb', line 77

def initialize(id: SKIP, name: SKIP, signups: SKIP, savings: SKIP,
               savings_in_cents: SKIP, revenue: SKIP,
               revenue_in_cents: SKIP, additional_properties: {})
  @id = id unless id == SKIP
  @name = name unless name == SKIP
  @signups = signups unless signups == SKIP
  @savings = savings unless savings == SKIP
  @savings_in_cents = savings_in_cents unless savings_in_cents == SKIP
  @revenue = revenue unless revenue == SKIP
  @revenue_in_cents = revenue_in_cents unless revenue_in_cents == SKIP

  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end
end

Instance Attribute Details

#idInteger

The Chargify id of the product

Returns:

  • (Integer)


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

def id
  @id
end

#nameString

Name of the product

Returns:

  • (String)


18
19
20
# File 'lib/advanced_billing/models/coupon_usage.rb', line 18

def name
  @name
end

#revenueInteger

Total revenue of the all subscriptions that have received a discount from this coupon.

Returns:

  • (Integer)


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

def revenue
  @revenue
end

#revenue_in_centsInteger

Total revenue of the all subscriptions that have received a discount from this coupon.

Returns:

  • (Integer)


40
41
42
# File 'lib/advanced_billing/models/coupon_usage.rb', line 40

def revenue_in_cents
  @revenue_in_cents
end

#savingsInteger

Dollar amount of customer savings as a result of the coupon.

Returns:

  • (Integer)


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

def savings
  @savings
end

#savings_in_centsInteger

Dollar amount of customer savings as a result of the coupon.

Returns:

  • (Integer)


30
31
32
# File 'lib/advanced_billing/models/coupon_usage.rb', line 30

def savings_in_cents
  @savings_in_cents
end

#signupsInteger

Number of times the coupon has been applied

Returns:

  • (Integer)


22
23
24
# File 'lib/advanced_billing/models/coupon_usage.rb', line 22

def signups
  @signups
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
# File 'lib/advanced_billing/models/coupon_usage.rb', line 95

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : SKIP
  name = hash.key?('name') ? hash['name'] : SKIP
  signups = hash.key?('signups') ? hash['signups'] : SKIP
  savings = hash.key?('savings') ? hash['savings'] : SKIP
  savings_in_cents =
    hash.key?('savings_in_cents') ? hash['savings_in_cents'] : SKIP
  revenue = hash.key?('revenue') ? hash['revenue'] : SKIP
  revenue_in_cents =
    hash.key?('revenue_in_cents') ? hash['revenue_in_cents'] : SKIP

  # Clean out expected properties from Hash.
  names.each_value { |k| hash.delete(k) }

  # Create object from extracted values.
  CouponUsage.new(id: id,
                  name: name,
                  signups: signups,
                  savings: savings,
                  savings_in_cents: savings_in_cents,
                  revenue: revenue,
                  revenue_in_cents: revenue_in_cents,
                  additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



43
44
45
46
47
48
49
50
51
52
53
# File 'lib/advanced_billing/models/coupon_usage.rb', line 43

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['name'] = 'name'
  @_hash['signups'] = 'signups'
  @_hash['savings'] = 'savings'
  @_hash['savings_in_cents'] = 'savings_in_cents'
  @_hash['revenue'] = 'revenue'
  @_hash['revenue_in_cents'] = 'revenue_in_cents'
  @_hash
end

.nullablesObject

An array for nullable fields



69
70
71
72
73
74
75
# File 'lib/advanced_billing/models/coupon_usage.rb', line 69

def self.nullables
  %w[
    savings
    savings_in_cents
    revenue
  ]
end

.optionalsObject

An array for optional fields



56
57
58
59
60
61
62
63
64
65
66
# File 'lib/advanced_billing/models/coupon_usage.rb', line 56

def self.optionals
  %w[
    id
    name
    signups
    savings
    savings_in_cents
    revenue
    revenue_in_cents
  ]
end