Class: ModernTreasury::Connection

Inherits:
BaseModel
  • Object
show all
Defined in:
lib/modern_treasury/models/connection.rb

Overview

Connection 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(id:, object:, live_mode:, created_at:, updated_at:, discarded_at:, vendor_id:, vendor_customer_id:, vendor_name:) ⇒ Connection

Returns a new instance of Connection.



81
82
83
84
85
86
87
88
89
90
91
92
# File 'lib/modern_treasury/models/connection.rb', line 81

def initialize(id:, object:, live_mode:, created_at:, updated_at:,
               discarded_at:, vendor_id:, vendor_customer_id:, vendor_name:)
  @id = id
  @object = object
  @live_mode = live_mode
  @created_at = created_at
  @updated_at = updated_at
  @discarded_at = discarded_at
  @vendor_id = vendor_id
  @vendor_customer_id = vendor_customer_id
  @vendor_name = vendor_name
end

Instance Attribute Details

#created_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


29
30
31
# File 'lib/modern_treasury/models/connection.rb', line 29

def created_at
  @created_at
end

#discarded_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


39
40
41
# File 'lib/modern_treasury/models/connection.rb', line 39

def discarded_at
  @discarded_at
end

#idUUID | String

TODO: Write general description for this method

Returns:

  • (UUID | String)


15
16
17
# File 'lib/modern_treasury/models/connection.rb', line 15

def id
  @id
end

#live_modeTrueClass | FalseClass

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (TrueClass | FalseClass)


24
25
26
# File 'lib/modern_treasury/models/connection.rb', line 24

def live_mode
  @live_mode
end

#objectString

TODO: Write general description for this method

Returns:

  • (String)


19
20
21
# File 'lib/modern_treasury/models/connection.rb', line 19

def object
  @object
end

#updated_atDateTime

This field will be true if this object exists in the live environment or false if it exists in the test environment.

Returns:

  • (DateTime)


34
35
36
# File 'lib/modern_treasury/models/connection.rb', line 34

def updated_at
  @updated_at
end

#vendor_customer_idUUID | String

An identifier given to this connection by the bank.

Returns:

  • (UUID | String)


47
48
49
# File 'lib/modern_treasury/models/connection.rb', line 47

def vendor_customer_id
  @vendor_customer_id
end

#vendor_idUUID | String

Unique identifier for the bank or vendor.

Returns:

  • (UUID | String)


43
44
45
# File 'lib/modern_treasury/models/connection.rb', line 43

def vendor_id
  @vendor_id
end

#vendor_nameString

A human-friendly name for the bank or vendor.

Returns:

  • (String)


51
52
53
# File 'lib/modern_treasury/models/connection.rb', line 51

def vendor_name
  @vendor_name
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
122
123
124
125
126
# File 'lib/modern_treasury/models/connection.rb', line 95

def self.from_hash(hash)
  return nil unless hash

  # Extract variables from the hash.
  id = hash.key?('id') ? hash['id'] : nil
  object = hash.key?('object') ? hash['object'] : nil
  live_mode = hash.key?('live_mode') ? hash['live_mode'] : nil
  created_at = if hash.key?('created_at')
                 (DateTimeHelper.from_rfc3339(hash['created_at']) if hash['created_at'])
               end
  updated_at = if hash.key?('updated_at')
                 (DateTimeHelper.from_rfc3339(hash['updated_at']) if hash['updated_at'])
               end
  discarded_at = if hash.key?('discarded_at')
                   (DateTimeHelper.from_rfc3339(hash['discarded_at']) if hash['discarded_at'])
                 end
  vendor_id = hash.key?('vendor_id') ? hash['vendor_id'] : nil
  vendor_customer_id =
    hash.key?('vendor_customer_id') ? hash['vendor_customer_id'] : nil
  vendor_name = hash.key?('vendor_name') ? hash['vendor_name'] : nil

  # Create object from extracted values.
  Connection.new(id: id,
                 object: object,
                 live_mode: live_mode,
                 created_at: created_at,
                 updated_at: updated_at,
                 discarded_at: discarded_at,
                 vendor_id: vendor_id,
                 vendor_customer_id: vendor_customer_id,
                 vendor_name: vendor_name)
end

.namesObject

A mapping from model property names to API property names.



54
55
56
57
58
59
60
61
62
63
64
65
66
# File 'lib/modern_treasury/models/connection.rb', line 54

def self.names
  @_hash = {} if @_hash.nil?
  @_hash['id'] = 'id'
  @_hash['object'] = 'object'
  @_hash['live_mode'] = 'live_mode'
  @_hash['created_at'] = 'created_at'
  @_hash['updated_at'] = 'updated_at'
  @_hash['discarded_at'] = 'discarded_at'
  @_hash['vendor_id'] = 'vendor_id'
  @_hash['vendor_customer_id'] = 'vendor_customer_id'
  @_hash['vendor_name'] = 'vendor_name'
  @_hash
end

.nullablesObject

An array for nullable fields



74
75
76
77
78
79
# File 'lib/modern_treasury/models/connection.rb', line 74

def self.nullables
  %w[
    discarded_at
    vendor_customer_id
  ]
end

.optionalsObject

An array for optional fields



69
70
71
# File 'lib/modern_treasury/models/connection.rb', line 69

def self.optionals
  []
end

.validate(value) ⇒ Object

Validates an instance of the object from a given value.

Parameters:

  • The (Connection | Hash)

    value against the validation is performed.



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
179
180
181
182
183
184
185
186
187
188
# File 'lib/modern_treasury/models/connection.rb', line 142

def self.validate(value)
  if value.instance_of? self
    return (
      APIHelper.valid_type?(value.id,
                            ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.object,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.live_mode,
                              ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
        APIHelper.valid_type?(value.created_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.updated_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.discarded_at,
                              ->(val) { val.instance_of? DateTime }) and
        APIHelper.valid_type?(value.vendor_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.vendor_customer_id,
                              ->(val) { val.instance_of? String }) and
        APIHelper.valid_type?(value.vendor_name,
                              ->(val) { val.instance_of? String })
    )
  end

  return false unless value.instance_of? Hash

  (
    APIHelper.valid_type?(value['id'],
                          ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['object'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['live_mode'],
                            ->(val) { val.instance_of? TrueClass or val.instance_of? FalseClass }) and
      APIHelper.valid_type?(value['created_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['updated_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['discarded_at'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['vendor_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['vendor_customer_id'],
                            ->(val) { val.instance_of? String }) and
      APIHelper.valid_type?(value['vendor_name'],
                            ->(val) { val.instance_of? String })
  )
end

Instance Method Details

#inspectObject

Provides a debugging-friendly string with detailed object information.



199
200
201
202
203
204
205
206
# File 'lib/modern_treasury/models/connection.rb', line 199

def inspect
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id.inspect}, object: #{@object.inspect}, live_mode:"\
  " #{@live_mode.inspect}, created_at: #{@created_at.inspect}, updated_at:"\
  " #{@updated_at.inspect}, discarded_at: #{@discarded_at.inspect}, vendor_id:"\
  " #{@vendor_id.inspect}, vendor_customer_id: #{@vendor_customer_id.inspect}, vendor_name:"\
  " #{@vendor_name.inspect}>"
end

#to_custom_created_atObject



128
129
130
# File 'lib/modern_treasury/models/connection.rb', line 128

def to_custom_created_at
  DateTimeHelper.to_rfc3339(created_at)
end

#to_custom_discarded_atObject



136
137
138
# File 'lib/modern_treasury/models/connection.rb', line 136

def to_custom_discarded_at
  DateTimeHelper.to_rfc3339(discarded_at)
end

#to_custom_updated_atObject



132
133
134
# File 'lib/modern_treasury/models/connection.rb', line 132

def to_custom_updated_at
  DateTimeHelper.to_rfc3339(updated_at)
end

#to_sObject

Provides a human-readable string representation of the object.



191
192
193
194
195
196
# File 'lib/modern_treasury/models/connection.rb', line 191

def to_s
  class_name = self.class.name.split('::').last
  "<#{class_name} id: #{@id}, object: #{@object}, live_mode: #{@live_mode}, created_at:"\
  " #{@created_at}, updated_at: #{@updated_at}, discarded_at: #{@discarded_at}, vendor_id:"\
  " #{@vendor_id}, vendor_customer_id: #{@vendor_customer_id}, vendor_name: #{@vendor_name}>"
end