Class: AdvancedBilling::SiteStatistics

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

Overview

SiteStatistics Model.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from BaseModel

#to_hash, #to_json

Constructor Details

#initialize(total_subscriptions: SKIP, subscriptions_today: SKIP, total_revenue: SKIP, revenue_today: SKIP, revenue_this_month: SKIP, revenue_this_year: SKIP, total_canceled_subscriptions: SKIP, total_active_subscriptions: SKIP, total_past_due_subscriptions: SKIP, total_unpaid_subscriptions: SKIP, total_dunning_subscriptions: SKIP, additional_properties: {}) ⇒ SiteStatistics



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
122
123
124
125
126
127
128
129
130
131
132
133
134
# File 'lib/advanced_billing/models/site_statistics.rb', line 95

def initialize(total_subscriptions: SKIP, subscriptions_today: SKIP,
               total_revenue: SKIP, revenue_today: SKIP,
               revenue_this_month: SKIP, revenue_this_year: SKIP,
               total_canceled_subscriptions: SKIP,
               total_active_subscriptions: SKIP,
               total_past_due_subscriptions: SKIP,
               total_unpaid_subscriptions: SKIP,
               total_dunning_subscriptions: SKIP, additional_properties: {})
  @total_subscriptions = total_subscriptions unless total_subscriptions == SKIP
  @subscriptions_today = subscriptions_today unless subscriptions_today == SKIP
  @total_revenue = total_revenue unless total_revenue == SKIP
  @revenue_today = revenue_today unless revenue_today == SKIP
  @revenue_this_month = revenue_this_month unless revenue_this_month == SKIP
  @revenue_this_year = revenue_this_year unless revenue_this_year == SKIP
  unless total_canceled_subscriptions == SKIP
    @total_canceled_subscriptions =
      total_canceled_subscriptions
  end
  unless total_active_subscriptions == SKIP
    @total_active_subscriptions =
      total_active_subscriptions
  end
  unless total_past_due_subscriptions == SKIP
    @total_past_due_subscriptions =
      total_past_due_subscriptions
  end
  unless total_unpaid_subscriptions == SKIP
    @total_unpaid_subscriptions =
      total_unpaid_subscriptions
  end
  unless total_dunning_subscriptions == SKIP
    @total_dunning_subscriptions =
      total_dunning_subscriptions
  end

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

Instance Attribute Details

#revenue_this_monthString

TODO: Write general description for this method



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

def revenue_this_month
  @revenue_this_month
end

#revenue_this_yearString

TODO: Write general description for this method



34
35
36
# File 'lib/advanced_billing/models/site_statistics.rb', line 34

def revenue_this_year
  @revenue_this_year
end

#revenue_todayString

TODO: Write general description for this method



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

def revenue_today
  @revenue_today
end

#subscriptions_todayInteger

TODO: Write general description for this method



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

def subscriptions_today
  @subscriptions_today
end

#total_active_subscriptionsInteger

TODO: Write general description for this method



42
43
44
# File 'lib/advanced_billing/models/site_statistics.rb', line 42

def total_active_subscriptions
  @total_active_subscriptions
end

#total_canceled_subscriptionsInteger

TODO: Write general description for this method



38
39
40
# File 'lib/advanced_billing/models/site_statistics.rb', line 38

def total_canceled_subscriptions
  @total_canceled_subscriptions
end

#total_dunning_subscriptionsInteger

TODO: Write general description for this method



54
55
56
# File 'lib/advanced_billing/models/site_statistics.rb', line 54

def total_dunning_subscriptions
  @total_dunning_subscriptions
end

#total_past_due_subscriptionsInteger

TODO: Write general description for this method



46
47
48
# File 'lib/advanced_billing/models/site_statistics.rb', line 46

def total_past_due_subscriptions
  @total_past_due_subscriptions
end

#total_revenueString

TODO: Write general description for this method



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

def total_revenue
  @total_revenue
end

#total_subscriptionsInteger

TODO: Write general description for this method



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

def total_subscriptions
  @total_subscriptions
end

#total_unpaid_subscriptionsInteger

TODO: Write general description for this method



50
51
52
# File 'lib/advanced_billing/models/site_statistics.rb', line 50

def total_unpaid_subscriptions
  @total_unpaid_subscriptions
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



137
138
139
140
141
142
143
144
145
146
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
# File 'lib/advanced_billing/models/site_statistics.rb', line 137

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  total_subscriptions =
    hash.key?('total_subscriptions') ? hash['total_subscriptions'] : SKIP
  subscriptions_today =
    hash.key?('subscriptions_today') ? hash['subscriptions_today'] : SKIP
  total_revenue = hash.key?('total_revenue') ? hash['total_revenue'] : SKIP
  revenue_today = hash.key?('revenue_today') ? hash['revenue_today'] : SKIP
  revenue_this_month =
    hash.key?('revenue_this_month') ? hash['revenue_this_month'] : SKIP
  revenue_this_year =
    hash.key?('revenue_this_year') ? hash['revenue_this_year'] : SKIP
  total_canceled_subscriptions =
    hash.key?('total_canceled_subscriptions') ? hash['total_canceled_subscriptions'] : SKIP
  total_active_subscriptions =
    hash.key?('total_active_subscriptions') ? hash['total_active_subscriptions'] : SKIP
  total_past_due_subscriptions =
    hash.key?('total_past_due_subscriptions') ? hash['total_past_due_subscriptions'] : SKIP
  total_unpaid_subscriptions =
    hash.key?('total_unpaid_subscriptions') ? hash['total_unpaid_subscriptions'] : SKIP
  total_dunning_subscriptions =
    hash.key?('total_dunning_subscriptions') ? hash['total_dunning_subscriptions'] : SKIP

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

  # Create object from extracted values.
  SiteStatistics.new(total_subscriptions: total_subscriptions,
                     subscriptions_today: subscriptions_today,
                     total_revenue: total_revenue,
                     revenue_today: revenue_today,
                     revenue_this_month: revenue_this_month,
                     revenue_this_year: revenue_this_year,
                     total_canceled_subscriptions: total_canceled_subscriptions,
                     total_active_subscriptions: total_active_subscriptions,
                     total_past_due_subscriptions: total_past_due_subscriptions,
                     total_unpaid_subscriptions: total_unpaid_subscriptions,
                     total_dunning_subscriptions: total_dunning_subscriptions,
                     additional_properties: hash)
end

.namesObject

A mapping from model property names to API property names.



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

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['total_subscriptions'] = 'total_subscriptions'
  @_hash['subscriptions_today'] = 'subscriptions_today'
  @_hash['total_revenue'] = 'total_revenue'
  @_hash['revenue_today'] = 'revenue_today'
  @_hash['revenue_this_month'] = 'revenue_this_month'
  @_hash['revenue_this_year'] = 'revenue_this_year'
  @_hash['total_canceled_subscriptions'] = 'total_canceled_subscriptions'
  @_hash['total_active_subscriptions'] = 'total_active_subscriptions'
  @_hash['total_past_due_subscriptions'] = 'total_past_due_subscriptions'
  @_hash['total_unpaid_subscriptions'] = 'total_unpaid_subscriptions'
  @_hash['total_dunning_subscriptions'] = 'total_dunning_subscriptions'
  @_hash
end

.nullablesObject

An array for nullable fields



91
92
93
# File 'lib/advanced_billing/models/site_statistics.rb', line 91

def self.nullables
  []
end

.optionalsObject

An array for optional fields



74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
# File 'lib/advanced_billing/models/site_statistics.rb', line 74

def self.optionals
  %w[
    total_subscriptions
    subscriptions_today
    total_revenue
    revenue_today
    revenue_this_month
    revenue_this_year
    total_canceled_subscriptions
    total_active_subscriptions
    total_past_due_subscriptions
    total_unpaid_subscriptions
    total_dunning_subscriptions
  ]
end