Class: AdvancedBilling::DunnerData

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

Overview

DunnerData 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(state:, subscription_id:, revenue_at_risk_in_cents:, created_at:, attempts:, last_attempted_at:, additional_properties: {}) ⇒ DunnerData

Returns a new instance of DunnerData.



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

def initialize(state:, subscription_id:, revenue_at_risk_in_cents:,
               created_at:, attempts:, last_attempted_at:,
               additional_properties: {})
  # Add additional model properties to the instance.
  additional_properties.each do |_name, _value|
    instance_variable_set("@#{_name}", _value)
  end

  @state = state
  @subscription_id = subscription_id
  @revenue_at_risk_in_cents = revenue_at_risk_in_cents
  @created_at = created_at
  @attempts = attempts
  @last_attempted_at = last_attempted_at
end

Instance Attribute Details

#attemptsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


31
32
33
# File 'lib/advanced_billing/models/dunner_data.rb', line 31

def attempts
  @attempts
end

#created_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


27
28
29
# File 'lib/advanced_billing/models/dunner_data.rb', line 27

def created_at
  @created_at
end

#last_attempted_atDateTime

TODO: Write general description for this method

Returns:

  • (DateTime)


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

def last_attempted_at
  @last_attempted_at
end

#revenue_at_risk_in_centsInteger

TODO: Write general description for this method

Returns:

  • (Integer)


23
24
25
# File 'lib/advanced_billing/models/dunner_data.rb', line 23

def revenue_at_risk_in_cents
  @revenue_at_risk_in_cents
end

#stateString

TODO: Write general description for this method

Returns:

  • (String)


15
16
17
# File 'lib/advanced_billing/models/dunner_data.rb', line 15

def state
  @state
end

#subscription_idInteger

TODO: Write general description for this method

Returns:

  • (Integer)


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

def subscription_id
  @subscription_id
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
# File 'lib/advanced_billing/models/dunner_data.rb', line 76

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  state = hash.key?('state') ? hash['state'] : nil
  subscription_id =
    hash.key?('subscription_id') ? hash['subscription_id'] : nil
  revenue_at_risk_in_cents =
    hash.key?('revenue_at_risk_in_cents') ? hash['revenue_at_risk_in_cents'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  attempts = hash.key?('attempts') ? hash['attempts'] : nil
  last_attempted_at = if hash.key?('last_attempted_at')
                        (DateTimeHelper.from_rfc3339(hash['last_attempted_at']) if hash['last_attempted_at'])
                      end

  # Clean out expected properties from Hash.
  additional_properties = hash.reject { |k, _| names.value?(k) }

  # Create object from extracted values.
  DunnerData.new(state: state,
                 subscription_id: subscription_id,
                 revenue_at_risk_in_cents: revenue_at_risk_in_cents,
                 created_at: created_at,
                 attempts: attempts,
                 last_attempted_at: last_attempted_at,
                 additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
46
47
# File 'lib/advanced_billing/models/dunner_data.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['state'] = 'state'
  @_hash['subscription_id'] = 'subscription_id'
  @_hash['revenue_at_risk_in_cents'] = 'revenue_at_risk_in_cents'
  @_hash['created_at'] = 'created_at'
  @_hash['attempts'] = 'attempts'
  @_hash['last_attempted_at'] = 'last_attempted_at'
  @_hash
end

.nullablesObject

An array for nullable fields



55
56
57
# File 'lib/advanced_billing/models/dunner_data.rb', line 55

def self.nullables
  []
end

.optionalsObject

An array for optional fields



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

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (DunnerData | Hash)

    value against the validation is performed.



116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
# File 'lib/advanced_billing/models/dunner_data.rb', line 116

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.state,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.subscription_id,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.revenue_at_risk_in_cents,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.attempts,
                              ->(val) { val.instance_of? Integer }) and
        APIHelper.valid_type?(value.last_attempted_at,
                              ->(val) { val.instance_of? DateTime })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['state'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['subscription_id'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['revenue_at_risk_in_cents'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['attempts'],
                            ->(val) { val.instance_of? Integer }) and
      APIHelper.valid_type?(value['last_attempted_at'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#to_custom_created_atObject



106
107
108
# File 'lib/advanced_billing/models/dunner_data.rb', line 106

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_last_attempted_atObject



110
111
112
# File 'lib/advanced_billing/models/dunner_data.rb', line 110

def to_custom_last_attempted_at
  DateTimeHelper.to_rfc3339(last_attempted_at)
end