=begin #MoneyKit API #No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) The version of the OpenAPI document: 2023-02-18 Generated by: https://openapi-generator.tech OpenAPI Generator version: 7.1.0 =end require 'date' require 'time' module MoneyKit class Transaction # The unique ID for this transaction. attr_accessor :transaction_id # The ID of the account in which this transaction occurred. attr_accessor :account_id # The amount of this transaction, denominated in account currency. This amount is always non-negative. The `type` field indicates whether it is entering or leaving the account. attr_accessor :amount attr_accessor :type # The ISO-4217 currency code of the transaction. attr_accessor :currency # The effective (posted) date of the transaction, in ISO-8601 format. For pending transactions, this date is when the transaction was initiated. attr_accessor :date # If the institution has provided the actual time of the transaction, this field contains the full date and time of the transaction, in ISO-8601 format. If the time is not available, this field will be null.
Note that the time is generally reported in the timezone of the institution or the account holder.
attr_accessor :datetime
# A normalized, cleaned transaction description suitable for presentation to the end user. Commonly this will be the merchant or counterparty name.
attr_accessor :description
# The raw transaction description as provided by the institution, where available.
attr_accessor :raw_description
# If true, this transaction is pending or unsettled and has not yet affected the account. Commonly these are credit card transactions, particularly approvals (holds) such as for hotel or restaurant reservations placed in advance where the final amount is still to be determined.
attr_accessor :pending
# The category for this transaction, given as a dotted string indicating a hierarchical categorization. See Transaction Categories for the list of possible transaction types.
attr_accessor :category
class EnumAttributeValidator
attr_reader :datatype
attr_reader :allowable_values
def initialize(datatype, allowable_values)
@allowable_values = allowable_values.map do |value|
case datatype.to_s
when /Integer/i
value.to_i
when /Float/i
value.to_f
else
value
end
end
end
def valid?(value)
!value || allowable_values.include?(value)
end
end
# Attribute mapping from ruby-style variable name to JSON key.
def self.attribute_map
{
:'transaction_id' => :'transaction_id',
:'account_id' => :'account_id',
:'amount' => :'amount',
:'type' => :'type',
:'currency' => :'currency',
:'date' => :'date',
:'datetime' => :'datetime',
:'description' => :'description',
:'raw_description' => :'raw_description',
:'pending' => :'pending',
:'category' => :'category'
}
end
# Returns all the JSON keys this model knows about
def self.acceptable_attributes
attribute_map.values
end
# Attribute type mapping.
def self.openapi_types
{
:'transaction_id' => :'String',
:'account_id' => :'String',
:'amount' => :'String',
:'type' => :'TransactionType',
:'currency' => :'String',
:'date' => :'Date',
:'datetime' => :'Time',
:'description' => :'String',
:'raw_description' => :'String',
:'pending' => :'Boolean',
:'category' => :'String'
}
end
# List of attributes with nullable: true
def self.openapi_nullable
Set.new([
])
end
# Initializes the object
# @param [Hash] attributes Model attributes in the form of hash
def initialize(attributes = {})
if (!attributes.is_a?(Hash))
fail ArgumentError, "The input argument (attributes) must be a hash in `MoneyKit::Transaction` initialize method"
end
# check to see if the attribute exists and convert string to symbol for hash key
attributes = attributes.each_with_object({}) { |(k, v), h|
if (!self.class.attribute_map.key?(k.to_sym))
fail ArgumentError, "`#{k}` is not a valid attribute in `MoneyKit::Transaction`. Please check the name to make sure it's valid. List of attributes: " + self.class.attribute_map.keys.inspect
end
h[k.to_sym] = v
}
if attributes.key?(:'transaction_id')
self.transaction_id = attributes[:'transaction_id']
else
self.transaction_id = nil
end
if attributes.key?(:'account_id')
self.account_id = attributes[:'account_id']
else
self.account_id = nil
end
if attributes.key?(:'amount')
self.amount = attributes[:'amount']
else
self.amount = nil
end
if attributes.key?(:'type')
self.type = attributes[:'type']
else
self.type = nil
end
if attributes.key?(:'currency')
self.currency = attributes[:'currency']
else
self.currency = nil
end
if attributes.key?(:'date')
self.date = attributes[:'date']
else
self.date = nil
end
if attributes.key?(:'datetime')
self.datetime = attributes[:'datetime']
end
if attributes.key?(:'description')
self.description = attributes[:'description']
end
if attributes.key?(:'raw_description')
self.raw_description = attributes[:'raw_description']
end
if attributes.key?(:'pending')
self.pending = attributes[:'pending']
else
self.pending = nil
end
if attributes.key?(:'category')
self.category = attributes[:'category']
end
end
# Show invalid properties with the reasons. Usually used together with valid?
# @return Array for valid properties with the reasons
def list_invalid_properties
warn '[DEPRECATED] the `list_invalid_properties` method is obsolete'
invalid_properties = Array.new
if @transaction_id.nil?
invalid_properties.push('invalid value for "transaction_id", transaction_id cannot be nil.')
end
if @account_id.nil?
invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
end
if @amount.nil?
invalid_properties.push('invalid value for "amount", amount cannot be nil.')
end
if @type.nil?
invalid_properties.push('invalid value for "type", type cannot be nil.')
end
if @currency.nil?
invalid_properties.push('invalid value for "currency", currency cannot be nil.')
end
if @date.nil?
invalid_properties.push('invalid value for "date", date cannot be nil.')
end
if @pending.nil?
invalid_properties.push('invalid value for "pending", pending cannot be nil.')
end
invalid_properties
end
# Check to see if the all the properties in the model are valid
# @return true if the model is valid
def valid?
warn '[DEPRECATED] the `valid?` method is obsolete'
return false if @transaction_id.nil?
return false if @account_id.nil?
return false if @amount.nil?
return false if @type.nil?
return false if @currency.nil?
return false if @date.nil?
return false if @pending.nil?
true
end
# Checks equality by comparing each attribute.
# @param [Object] Object to be compared
def ==(o)
return true if self.equal?(o)
self.class == o.class &&
transaction_id == o.transaction_id &&
account_id == o.account_id &&
amount == o.amount &&
type == o.type &&
currency == o.currency &&
date == o.date &&
datetime == o.datetime &&
description == o.description &&
raw_description == o.raw_description &&
pending == o.pending &&
category == o.category
end
# @see the `==` method
# @param [Object] Object to be compared
def eql?(o)
self == o
end
# Calculates hash code according to all attributes.
# @return [Integer] Hash code
def hash
[transaction_id, account_id, amount, type, currency, date, datetime, description, raw_description, pending, category].hash
end
# Builds the object from hash
# @param [Hash] attributes Model attributes in the form of hash
# @return [Object] Returns the model itself
def self.build_from_hash(attributes)
return nil unless attributes.is_a?(Hash)
attributes = attributes.transform_keys(&:to_sym)
transformed_hash = {}
openapi_types.each_pair do |key, type|
if attributes.key?(attribute_map[key]) && attributes[attribute_map[key]].nil?
transformed_hash["#{key}"] = nil
elsif type =~ /\AArray<(.*)>/i
# check to ensure the input is an array given that the attribute
# is documented as an array but the input is not
if attributes[attribute_map[key]].is_a?(Array)
transformed_hash["#{key}"] = attributes[attribute_map[key]].map { |v| _deserialize($1, v) }
end
elsif !attributes[attribute_map[key]].nil?
transformed_hash["#{key}"] = _deserialize(type, attributes[attribute_map[key]])
end
end
new(transformed_hash)
end
# Deserializes the data based on type
# @param string type Data type
# @param string value Value to be deserialized
# @return [Object] Deserialized data
def self._deserialize(type, value)
case type.to_sym
when :Time
Time.parse(value)
when :Date
Date.parse(value)
when :String
value.to_s
when :Integer
value.to_i
when :Float
value.to_f
when :Boolean
if value.to_s =~ /\A(true|t|yes|y|1)\z/i
true
else
false
end
when :Object
# generic object (usually a Hash), return directly
value
when /\AArray<(?