Class: ApiReference::AutoCollection

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

Overview

AutoCollection 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(next_attempt_at:, previously_attempted_at:, enabled:, num_attempts:, additional_properties: nil) ⇒ AutoCollection

Returns a new instance of AutoCollection.



62
63
64
65
66
67
68
69
70
71
72
# File 'lib/api_reference/models/auto_collection.rb', line 62

def initialize(next_attempt_at:, previously_attempted_at:, enabled:,
               num_attempts:, additional_properties: nil)
  # Add additional model properties to the instance
  additional_properties = {} if additional_properties.nil?

  @next_attempt_at = next_attempt_at
  @previously_attempted_at = previously_attempted_at
  @enabled = enabled
  @num_attempts = num_attempts
  @additional_properties = additional_properties
end

Instance Attribute Details

#enabledTrueClass | FalseClass

True only if auto-collection is enabled for this invoice.

Returns:

  • (TrueClass | FalseClass)


31
32
33
# File 'lib/api_reference/models/auto_collection.rb', line 31

def enabled
  @enabled
end

#next_attempt_atDateTime

If the invoice is scheduled for auto-collection, this field will reflect when the next attempt will occur. If dunning has been exhausted, or auto-collection is not enabled for this invoice, this field will be null.

Returns:

  • (DateTime)


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

def next_attempt_at
  @next_attempt_at
end

#num_attemptsInteger

Number of auto-collection payment attempts.

Returns:

  • (Integer)


35
36
37
# File 'lib/api_reference/models/auto_collection.rb', line 35

def num_attempts
  @num_attempts
end

#previously_attempted_atDateTime

If Orb has ever attempted payment auto-collection for this invoice, this field will reflect when that attempt occurred. In conjunction with next_attempt_at, this can be used to tell whether the invoice is currently in dunning (that is, previously_attempted_at is non-null, and next_attempt_time is non-null), or if dunning has been exhausted (previously_attempted_at is non-null, but next_attempt_time is null).

Returns:

  • (DateTime)


27
28
29
# File 'lib/api_reference/models/auto_collection.rb', line 27

def previously_attempted_at
  @previously_attempted_at
end

Class Method Details

.from_hash(hash) ⇒ Object

Creates an instance of the object from a hash.



75
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
# File 'lib/api_reference/models/auto_collection.rb', line 75

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  next_attempt_at = if hash.key?('next_attempt_at')
                      (DateTimeHelper.from_rfc3339(hash['next_attempt_at']) if hash['next_attempt_at'])
                    end
  previously_attempted_at = if hash.key?('previously_attempted_at')
                              (DateTimeHelper.from_rfc3339(hash['previously_attempted_at']) if hash['previously_attempted_at'])
                            end
  enabled = hash.key?('enabled') ? hash['enabled'] : nil
  num_attempts = hash.key?('num_attempts') ? hash['num_attempts'] : nil

  # Create a new hash for additional properties, removing known properties.
  new_hash = hash.reject { |k, _| names.value?(k) }

  additional_properties = APIHelper.get_additional_properties(
    new_hash, proc { |value| value }
  )

  # Create object from extracted values.
  AutoCollection.new(next_attempt_at: next_attempt_at,
                     previously_attempted_at: previously_attempted_at,
                     enabled: enabled,
                     num_attempts: num_attempts,
                     additional_properties: additional_properties)
end

.namesObject

A mapping from model property names to API property names.



38
39
40
41
42
43
44
45
# File 'lib/api_reference/models/auto_collection.rb', line 38

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['next_attempt_at'] = 'next_attempt_at'
  @_hash['previously_attempted_at'] = 'previously_attempted_at'
  @_hash['enabled'] = 'enabled'
  @_hash['num_attempts'] = 'num_attempts'
  @_hash
end

.nullablesObject

An array for nullable fields



53
54
55
56
57
58
59
60
# File 'lib/api_reference/models/auto_collection.rb', line 53

def self.nullables
  %w[
    next_attempt_at
    previously_attempted_at
    enabled
    num_attempts
  ]
end

.optionalsObject

An array for optional fields



48
49
50
# File 'lib/api_reference/models/auto_collection.rb', line 48

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (AutoCollection | Hash)

    value against the validation is performed.



113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
# File 'lib/api_reference/models/auto_collection.rb', line 113

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.next_attempt_at,
                            ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.previously_attempted_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.enabled,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.num_attempts,
                              ->(val) { val.instance_of? Integer })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['next_attempt_at'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['previously_attempted_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['enabled'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['num_attempts'],
                            ->(val) { val.instance_of? Integer })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



150
151
152
153
154
155
# File 'lib/api_reference/models/auto_collection.rb', line 150

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} next_attempt_at: #{@next_attempt_at.inspect}, previously_attempted_at:"\
  " #{@previously_attempted_at.inspect}, enabled: #{@enabled.inspect}, num_attempts:"\
  " #{@num_attempts.inspect}, additional_properties: #{@additional_properties}>"
end

#to_custom_next_attempt_atObject



103
104
105
# File 'lib/api_reference/models/auto_collection.rb', line 103

def to_custom_next_attempt_at
  DateTimeHelper.to_rfc3339(next_attempt_at)
end

#to_custom_previously_attempted_atObject



107
108
109
# File 'lib/api_reference/models/auto_collection.rb', line 107

def to_custom_previously_attempted_at
  DateTimeHelper.to_rfc3339(previously_attempted_at)
end

#to_sObject

Provides a human-readable string representation of the object.



142
143
144
145
146
147
# File 'lib/api_reference/models/auto_collection.rb', line 142

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} next_attempt_at: #{@next_attempt_at}, previously_attempted_at:"\
  " #{@previously_attempted_at}, enabled: #{@enabled}, num_attempts: #{@num_attempts},"\
  " additional_properties: #{@additional_properties}>"
end