ynab 1.13.0 → 1.18.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (98) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +1 -0
  3. data/lib/ynab.rb +6 -1
  4. data/lib/ynab/api/accounts_api.rb +3 -3
  5. data/lib/ynab/api/budgets_api.rb +6 -3
  6. data/lib/ynab/api/categories_api.rb +7 -7
  7. data/lib/ynab/api/deprecated_api.rb +1 -1
  8. data/lib/ynab/api/months_api.rb +3 -3
  9. data/lib/ynab/api/payee_locations_api.rb +1 -1
  10. data/lib/ynab/api/payees_api.rb +3 -3
  11. data/lib/ynab/api/scheduled_transactions_api.rb +3 -3
  12. data/lib/ynab/api/transactions_api.rb +77 -25
  13. data/lib/ynab/api/user_api.rb +1 -1
  14. data/lib/ynab/api_client.rb +3 -2
  15. data/lib/ynab/configuration.rb +2 -3
  16. data/lib/ynab/models/account.rb +3 -7
  17. data/lib/ynab/models/account_response.rb +3 -2
  18. data/lib/ynab/models/account_response_data.rb +3 -2
  19. data/lib/ynab/models/accounts_response.rb +3 -2
  20. data/lib/ynab/models/accounts_response_data.rb +3 -2
  21. data/lib/ynab/models/budget_detail.rb +3 -2
  22. data/lib/ynab/models/budget_detail_response.rb +3 -2
  23. data/lib/ynab/models/budget_detail_response_data.rb +3 -2
  24. data/lib/ynab/models/budget_settings.rb +3 -2
  25. data/lib/ynab/models/budget_settings_response.rb +3 -2
  26. data/lib/ynab/models/budget_settings_response_data.rb +3 -2
  27. data/lib/ynab/models/budget_summary.rb +19 -6
  28. data/lib/ynab/models/budget_summary_response.rb +3 -2
  29. data/lib/ynab/models/budget_summary_response_data.rb +3 -7
  30. data/lib/ynab/models/bulk_response.rb +3 -2
  31. data/lib/ynab/models/bulk_response_data.rb +3 -2
  32. data/lib/ynab/models/bulk_response_data_bulk.rb +4 -3
  33. data/lib/ynab/models/bulk_transactions.rb +3 -2
  34. data/lib/ynab/models/categories_response.rb +3 -2
  35. data/lib/ynab/models/categories_response_data.rb +3 -2
  36. data/lib/ynab/models/category.rb +7 -36
  37. data/lib/ynab/models/category_group.rb +3 -2
  38. data/lib/ynab/models/category_group_with_categories.rb +3 -2
  39. data/lib/ynab/models/category_response.rb +3 -2
  40. data/lib/ynab/models/category_response_data.rb +3 -2
  41. data/lib/ynab/models/currency_format.rb +3 -2
  42. data/lib/ynab/models/date_format.rb +3 -2
  43. data/lib/ynab/models/error_detail.rb +3 -2
  44. data/lib/ynab/models/error_response.rb +3 -2
  45. data/lib/ynab/models/hybrid_transaction.rb +4 -58
  46. data/lib/ynab/models/hybrid_transactions_response.rb +3 -2
  47. data/lib/ynab/models/hybrid_transactions_response_data.rb +3 -2
  48. data/lib/ynab/models/month_detail.rb +5 -14
  49. data/lib/ynab/models/month_detail_response.rb +3 -2
  50. data/lib/ynab/models/month_detail_response_data.rb +3 -2
  51. data/lib/ynab/models/month_summaries_response.rb +3 -2
  52. data/lib/ynab/models/month_summaries_response_data.rb +3 -2
  53. data/lib/ynab/models/month_summary.rb +5 -14
  54. data/lib/ynab/models/payee.rb +4 -8
  55. data/lib/ynab/models/payee_location.rb +3 -2
  56. data/lib/ynab/models/payee_location_response.rb +3 -2
  57. data/lib/ynab/models/payee_location_response_data.rb +3 -2
  58. data/lib/ynab/models/payee_locations_response.rb +3 -2
  59. data/lib/ynab/models/payee_locations_response_data.rb +3 -2
  60. data/lib/ynab/models/payee_response.rb +3 -2
  61. data/lib/ynab/models/payee_response_data.rb +3 -2
  62. data/lib/ynab/models/payees_response.rb +3 -2
  63. data/lib/ynab/models/payees_response_data.rb +3 -2
  64. data/lib/ynab/models/save_category_response.rb +3 -2
  65. data/lib/ynab/models/save_category_response_data.rb +3 -2
  66. data/lib/ynab/models/save_month_category.rb +3 -2
  67. data/lib/ynab/models/save_month_category_wrapper.rb +3 -2
  68. data/lib/ynab/models/save_sub_transaction.rb +259 -0
  69. data/lib/ynab/models/save_transaction.rb +23 -10
  70. data/lib/ynab/models/save_transaction_wrapper.rb +3 -2
  71. data/lib/ynab/models/save_transactions_response.rb +3 -2
  72. data/lib/ynab/models/save_transactions_response_data.rb +4 -3
  73. data/lib/ynab/models/save_transactions_wrapper.rb +3 -2
  74. data/lib/ynab/models/scheduled_sub_transaction.rb +3 -22
  75. data/lib/ynab/models/scheduled_transaction_detail.rb +3 -37
  76. data/lib/ynab/models/scheduled_transaction_response.rb +3 -2
  77. data/lib/ynab/models/scheduled_transaction_response_data.rb +3 -2
  78. data/lib/ynab/models/scheduled_transaction_summary.rb +3 -27
  79. data/lib/ynab/models/scheduled_transactions_response.rb +3 -2
  80. data/lib/ynab/models/scheduled_transactions_response_data.rb +3 -2
  81. data/lib/ynab/models/sub_transaction.rb +22 -23
  82. data/lib/ynab/models/transaction_detail.rb +3 -52
  83. data/lib/ynab/models/transaction_response.rb +3 -2
  84. data/lib/ynab/models/transaction_response_data.rb +3 -2
  85. data/lib/ynab/models/transaction_summary.rb +3 -42
  86. data/lib/ynab/models/transactions_import_response.rb +189 -0
  87. data/lib/ynab/models/transactions_import_response_data.rb +192 -0
  88. data/lib/ynab/models/transactions_response.rb +3 -2
  89. data/lib/ynab/models/transactions_response_data.rb +3 -2
  90. data/lib/ynab/models/update_transaction.rb +415 -0
  91. data/lib/ynab/models/update_transactions_wrapper.rb +191 -0
  92. data/lib/ynab/models/user.rb +3 -2
  93. data/lib/ynab/models/user_response.rb +3 -2
  94. data/lib/ynab/models/user_response_data.rb +3 -2
  95. data/lib/ynab/version.rb +1 -1
  96. data/spec/api/transactions_spec.rb +11 -0
  97. data/spec/fixtures/vcr_cassettes/import_transactions.yml +50 -0
  98. metadata +10 -3
@@ -0,0 +1,192 @@
1
+ =begin
2
+ #YNAB API Endpoints
3
+
4
+ #Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.youneedabudget.com
5
+
6
+ OpenAPI spec version: 1.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.14
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module YNAB
16
+ class TransactionsImportResponseData
17
+ # The list of transaction ids that were imported.
18
+ attr_accessor :transaction_ids
19
+
20
+ # Attribute mapping from ruby-style variable name to JSON key.
21
+ def self.attribute_map
22
+ {
23
+ :'transaction_ids' => :'transaction_ids'
24
+ }
25
+ end
26
+
27
+ # Attribute type mapping.
28
+ def self.swagger_types
29
+ {
30
+ :'transaction_ids' => :'Array<String>'
31
+ }
32
+ end
33
+
34
+ # Initializes the object
35
+ # @param [Hash] attributes Model attributes in the form of hash
36
+ def initialize(attributes = {})
37
+ return unless attributes.is_a?(Hash)
38
+
39
+ # convert string to symbol for hash key
40
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
41
+
42
+ if attributes.has_key?(:'transaction_ids')
43
+ if (value = attributes[:'transaction_ids']).is_a?(Array)
44
+ self.transaction_ids = value
45
+ end
46
+ end
47
+ end
48
+
49
+ # Show invalid properties with the reasons. Usually used together with valid?
50
+ # @return Array for valid properties with the reasons
51
+ def list_invalid_properties
52
+ invalid_properties = Array.new
53
+ if @transaction_ids.nil?
54
+ invalid_properties.push('invalid value for "transaction_ids", transaction_ids cannot be nil.')
55
+ end
56
+
57
+ invalid_properties
58
+ end
59
+
60
+ # Check to see if the all the properties in the model are valid
61
+ # @return true if the model is valid
62
+ def valid?
63
+ return false if @transaction_ids.nil?
64
+ true
65
+ end
66
+
67
+ # Checks equality by comparing each attribute.
68
+ # @param [Object] Object to be compared
69
+ def ==(o)
70
+ return true if self.equal?(o)
71
+ self.class == o.class &&
72
+ transaction_ids == o.transaction_ids
73
+ end
74
+
75
+ # @see the `==` method
76
+ # @param [Object] Object to be compared
77
+ def eql?(o)
78
+ self == o
79
+ end
80
+
81
+ # Calculates hash code according to all attributes.
82
+ # @return [Fixnum] Hash code
83
+ def hash
84
+ [transaction_ids].hash
85
+ end
86
+
87
+ # Builds the object from hash
88
+ # @param [Hash] attributes Model attributes in the form of hash
89
+ # @return [Object] Returns the model itself
90
+ def build_from_hash(attributes)
91
+ return nil unless attributes.is_a?(Hash)
92
+ self.class.swagger_types.each_pair do |key, type|
93
+ if type =~ /\AArray<(.*)>/i
94
+ # check to ensure the input is an array given that the attribute
95
+ # is documented as an array but the input is not
96
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
97
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
98
+ end
99
+ elsif !attributes[self.class.attribute_map[key]].nil?
100
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
101
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
102
+ end
103
+
104
+ self
105
+ end
106
+
107
+ # Deserializes the data based on type
108
+ # @param string type Data type
109
+ # @param string value Value to be deserialized
110
+ # @return [Object] Deserialized data
111
+ def _deserialize(type, value)
112
+ case type.to_sym
113
+ when :DateTime
114
+ DateTime.parse(value)
115
+ when :Date
116
+ Date.parse(value)
117
+ when :String
118
+ value.to_s
119
+ when :Integer
120
+ value.to_i
121
+ when :Float
122
+ value.to_f
123
+ when :BOOLEAN
124
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
125
+ true
126
+ else
127
+ false
128
+ end
129
+ when :Object
130
+ # generic object (usually a Hash), return directly
131
+ value
132
+ when /\AArray<(?<inner_type>.+)>\z/
133
+ inner_type = Regexp.last_match[:inner_type]
134
+ value.map { |v| _deserialize(inner_type, v) }
135
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
136
+ k_type = Regexp.last_match[:k_type]
137
+ v_type = Regexp.last_match[:v_type]
138
+ {}.tap do |hash|
139
+ value.each do |k, v|
140
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
141
+ end
142
+ end
143
+ else # model
144
+ temp_model = YNAB.const_get(type).new
145
+ temp_model.build_from_hash(value)
146
+ end
147
+ end
148
+
149
+ # Returns the string representation of the object
150
+ # @return [String] String presentation of the object
151
+ def to_s
152
+ to_hash.to_s
153
+ end
154
+
155
+ # to_body is an alias to to_hash (backward compatibility)
156
+ # @return [Hash] Returns the object in the form of hash
157
+ def to_body
158
+ to_hash
159
+ end
160
+
161
+ # Returns the object in the form of hash
162
+ # @return [Hash] Returns the object in the form of hash
163
+ def to_hash
164
+ hash = {}
165
+ self.class.attribute_map.each_pair do |attr, param|
166
+ value = self.send(attr)
167
+ next if value.nil?
168
+ hash[param] = _to_hash(value)
169
+ end
170
+ hash
171
+ end
172
+
173
+ # Outputs non-array value in the form of hash
174
+ # For object, use to_hash. Otherwise, just return the value
175
+ # @param [Object] value Any valid value
176
+ # @return [Hash] Returns the value in the form of hash
177
+ def _to_hash(value)
178
+ if value.is_a?(Array)
179
+ value.compact.map { |v| _to_hash(v) }
180
+ elsif value.is_a?(Hash)
181
+ {}.tap do |hash|
182
+ value.each { |k, v| hash[k] = _to_hash(v) }
183
+ end
184
+ elsif value.respond_to? :to_hash
185
+ value.to_hash
186
+ else
187
+ value
188
+ end
189
+ end
190
+
191
+ end
192
+ end
@@ -6,7 +6,7 @@
6
6
  OpenAPI spec version: 1.0.0
7
7
 
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.0-SNAPSHOT
9
+ Swagger Codegen version: 2.4.14
10
10
 
11
11
  =end
12
12
 
@@ -88,7 +88,7 @@ module YNAB
88
88
  return nil unless attributes.is_a?(Hash)
89
89
  self.class.swagger_types.each_pair do |key, type|
90
90
  if type =~ /\AArray<(.*)>/i
91
- # check to ensure the input is an array given that the the attribute
91
+ # check to ensure the input is an array given that the attribute
92
92
  # is documented as an array but the input is not
93
93
  if attributes[self.class.attribute_map[key]].is_a?(Array)
94
94
  self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
@@ -184,5 +184,6 @@ module YNAB
184
184
  value
185
185
  end
186
186
  end
187
+
187
188
  end
188
189
  end
@@ -6,7 +6,7 @@
6
6
  OpenAPI spec version: 1.0.0
7
7
 
8
8
  Generated by: https://github.com/swagger-api/swagger-codegen.git
9
- Swagger Codegen version: 2.4.0-SNAPSHOT
9
+ Swagger Codegen version: 2.4.14
10
10
 
11
11
  =end
12
12
 
@@ -105,7 +105,7 @@ module YNAB
105
105
  return nil unless attributes.is_a?(Hash)
106
106
  self.class.swagger_types.each_pair do |key, type|
107
107
  if type =~ /\AArray<(.*)>/i
108
- # check to ensure the input is an array given that the the attribute
108
+ # check to ensure the input is an array given that the attribute
109
109
  # is documented as an array but the input is not
110
110
  if attributes[self.class.attribute_map[key]].is_a?(Array)
111
111
  self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
@@ -201,5 +201,6 @@ module YNAB
201
201
  value
202
202
  end
203
203
  end
204
+
204
205
  end
205
206
  end
@@ -0,0 +1,415 @@
1
+ =begin
2
+ #YNAB API Endpoints
3
+
4
+ #Our API uses a REST based design, leverages the JSON data format, and relies upon HTTPS for transport. We respond with meaningful HTTP response codes and if an error occurs, we include error details in the response body. API Documentation is at https://api.youneedabudget.com
5
+
6
+ OpenAPI spec version: 1.0.0
7
+
8
+ Generated by: https://github.com/swagger-api/swagger-codegen.git
9
+ Swagger Codegen version: 2.4.14
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module YNAB
16
+ class UpdateTransaction
17
+ attr_accessor :account_id
18
+
19
+ # The transaction date in ISO format (e.g. 2016-12-01). Future dates (scheduled transactions) are not permitted. Split transaction dates cannot be changed and if a different date is supplied it will be ignored.
20
+ attr_accessor :date
21
+
22
+ # The transaction amount in milliunits format. Split transaction amounts cannot be changed and if a different amount is supplied it will be ignored.
23
+ attr_accessor :amount
24
+
25
+ # The payee for the transaction. To create a transfer between two accounts, use the account transfer payee pointing to the target account. Account transfer payees are specified as `tranfer_payee_id` on the account resource.
26
+ attr_accessor :payee_id
27
+
28
+ # The payee name. If a `payee_name` value is provided and `payee_id` has a null value, the `payee_name` value will be used to resolve the payee by either (1) a matching payee rename rule (only if `import_id` is also specified) or (2) a payee with the same name or (3) creation of a new payee.
29
+ attr_accessor :payee_name
30
+
31
+ # The category for the transaction. To configure a split transaction, you can specify null for `category_id` and provide a `subtransactions` array as part of the transaction object. If an existing transaction is a split, the `category_id` cannot be changed. Credit Card Payment categories are not permitted and will be ignored if supplied.
32
+ attr_accessor :category_id
33
+
34
+ attr_accessor :memo
35
+
36
+ # The cleared status of the transaction
37
+ attr_accessor :cleared
38
+
39
+ # Whether or not the transaction is approved. If not supplied, transaction will be unapproved by default.
40
+ attr_accessor :approved
41
+
42
+ # The transaction flag
43
+ attr_accessor :flag_color
44
+
45
+ # If specified, the new transaction will be assigned this `import_id` and considered \"imported\". We will also attempt to match this imported transaction to an existing \"user-entered\" transation on the same account, with the same amount, and with a date +/-10 days from the imported transaction date.<br><br>Transactions imported through File Based Import or Direct Import (not through the API) are assigned an import_id in the format: 'YNAB:[milliunit_amount]:[iso_date]:[occurrence]'. For example, a transaction dated 2015-12-30 in the amount of -$294.23 USD would have an import_id of 'YNAB:-294230:2015-12-30:1'. If a second transaction on the same account was imported and had the same date and same amount, its import_id would be 'YNAB:-294230:2015-12-30:2'. Using a consistent format will prevent duplicates through Direct Import and File Based Import.<br><br>If import_id is omitted or specified as null, the transaction will be treated as a \"user-entered\" transaction. As such, it will be eligible to be matched against transactions later being imported (via DI, FBI, or API).
46
+ attr_accessor :import_id
47
+
48
+ # An array of subtransactions to configure a transaction as a split. Updating `subtransactions` on an existing split transaction is not supported.
49
+ attr_accessor :subtransactions
50
+
51
+ attr_accessor :id
52
+
53
+ class EnumAttributeValidator
54
+ attr_reader :datatype
55
+ attr_reader :allowable_values
56
+
57
+ def initialize(datatype, allowable_values)
58
+ @allowable_values = allowable_values.map do |value|
59
+ case datatype.to_s
60
+ when /Integer/i
61
+ value.to_i
62
+ when /Float/i
63
+ value.to_f
64
+ else
65
+ value
66
+ end
67
+ end
68
+ end
69
+
70
+ def valid?(value)
71
+ !value || allowable_values.include?(value)
72
+ end
73
+ end
74
+
75
+ # Attribute mapping from ruby-style variable name to JSON key.
76
+ def self.attribute_map
77
+ {
78
+ :'account_id' => :'account_id',
79
+ :'date' => :'date',
80
+ :'amount' => :'amount',
81
+ :'payee_id' => :'payee_id',
82
+ :'payee_name' => :'payee_name',
83
+ :'category_id' => :'category_id',
84
+ :'memo' => :'memo',
85
+ :'cleared' => :'cleared',
86
+ :'approved' => :'approved',
87
+ :'flag_color' => :'flag_color',
88
+ :'import_id' => :'import_id',
89
+ :'subtransactions' => :'subtransactions',
90
+ :'id' => :'id'
91
+ }
92
+ end
93
+
94
+ # Attribute type mapping.
95
+ def self.swagger_types
96
+ {
97
+ :'account_id' => :'String',
98
+ :'date' => :'Date',
99
+ :'amount' => :'Integer',
100
+ :'payee_id' => :'String',
101
+ :'payee_name' => :'String',
102
+ :'category_id' => :'String',
103
+ :'memo' => :'String',
104
+ :'cleared' => :'String',
105
+ :'approved' => :'BOOLEAN',
106
+ :'flag_color' => :'String',
107
+ :'import_id' => :'String',
108
+ :'subtransactions' => :'Array<SaveSubTransaction>',
109
+ :'id' => :'String'
110
+ }
111
+ end
112
+
113
+ # Initializes the object
114
+ # @param [Hash] attributes Model attributes in the form of hash
115
+ def initialize(attributes = {})
116
+ return unless attributes.is_a?(Hash)
117
+
118
+ # convert string to symbol for hash key
119
+ attributes = attributes.each_with_object({}) { |(k, v), h| h[k.to_sym] = v }
120
+
121
+ if attributes.has_key?(:'account_id')
122
+ self.account_id = attributes[:'account_id']
123
+ end
124
+
125
+ if attributes.has_key?(:'date')
126
+ self.date = attributes[:'date']
127
+ end
128
+
129
+ if attributes.has_key?(:'amount')
130
+ self.amount = attributes[:'amount']
131
+ end
132
+
133
+ if attributes.has_key?(:'payee_id')
134
+ self.payee_id = attributes[:'payee_id']
135
+ end
136
+
137
+ if attributes.has_key?(:'payee_name')
138
+ self.payee_name = attributes[:'payee_name']
139
+ end
140
+
141
+ if attributes.has_key?(:'category_id')
142
+ self.category_id = attributes[:'category_id']
143
+ end
144
+
145
+ if attributes.has_key?(:'memo')
146
+ self.memo = attributes[:'memo']
147
+ end
148
+
149
+ if attributes.has_key?(:'cleared')
150
+ self.cleared = attributes[:'cleared']
151
+ end
152
+
153
+ if attributes.has_key?(:'approved')
154
+ self.approved = attributes[:'approved']
155
+ end
156
+
157
+ if attributes.has_key?(:'flag_color')
158
+ self.flag_color = attributes[:'flag_color']
159
+ end
160
+
161
+ if attributes.has_key?(:'import_id')
162
+ self.import_id = attributes[:'import_id']
163
+ end
164
+
165
+ if attributes.has_key?(:'subtransactions')
166
+ if (value = attributes[:'subtransactions']).is_a?(Array)
167
+ self.subtransactions = value
168
+ end
169
+ end
170
+
171
+ if attributes.has_key?(:'id')
172
+ self.id = attributes[:'id']
173
+ end
174
+ end
175
+
176
+ # Show invalid properties with the reasons. Usually used together with valid?
177
+ # @return Array for valid properties with the reasons
178
+ def list_invalid_properties
179
+ invalid_properties = Array.new
180
+ if @account_id.nil?
181
+ invalid_properties.push('invalid value for "account_id", account_id cannot be nil.')
182
+ end
183
+
184
+ if @date.nil?
185
+ invalid_properties.push('invalid value for "date", date cannot be nil.')
186
+ end
187
+
188
+ if @amount.nil?
189
+ invalid_properties.push('invalid value for "amount", amount cannot be nil.')
190
+ end
191
+
192
+ if !@payee_name.nil? && @payee_name.to_s.length > 50
193
+ invalid_properties.push('invalid value for "payee_name", the character length must be smaller than or equal to 50.')
194
+ end
195
+
196
+ if !@memo.nil? && @memo.to_s.length > 200
197
+ invalid_properties.push('invalid value for "memo", the character length must be smaller than or equal to 200.')
198
+ end
199
+
200
+ if !@import_id.nil? && @import_id.to_s.length > 36
201
+ invalid_properties.push('invalid value for "import_id", the character length must be smaller than or equal to 36.')
202
+ end
203
+
204
+ if @id.nil?
205
+ invalid_properties.push('invalid value for "id", id cannot be nil.')
206
+ end
207
+
208
+ invalid_properties
209
+ end
210
+
211
+ # Check to see if the all the properties in the model are valid
212
+ # @return true if the model is valid
213
+ def valid?
214
+ return false if @account_id.nil?
215
+ return false if @date.nil?
216
+ return false if @amount.nil?
217
+ return false if !@payee_name.nil? && @payee_name.to_s.length > 50
218
+ return false if !@memo.nil? && @memo.to_s.length > 200
219
+ cleared_validator = EnumAttributeValidator.new('String', ['cleared', 'uncleared', 'reconciled'])
220
+ return false unless cleared_validator.valid?(@cleared)
221
+ flag_color_validator = EnumAttributeValidator.new('String', ['red', 'orange', 'yellow', 'green', 'blue', 'purple'])
222
+ return false unless flag_color_validator.valid?(@flag_color)
223
+ return false if !@import_id.nil? && @import_id.to_s.length > 36
224
+ return false if @id.nil?
225
+ true
226
+ end
227
+
228
+ # Custom attribute writer method with validation
229
+ # @param [Object] payee_name Value to be assigned
230
+ def payee_name=(payee_name)
231
+ if !payee_name.nil? && payee_name.to_s.length > 50
232
+ fail ArgumentError, 'invalid value for "payee_name", the character length must be smaller than or equal to 50.'
233
+ end
234
+
235
+ @payee_name = payee_name
236
+ end
237
+
238
+ # Custom attribute writer method with validation
239
+ # @param [Object] memo Value to be assigned
240
+ def memo=(memo)
241
+ if !memo.nil? && memo.to_s.length > 200
242
+ fail ArgumentError, 'invalid value for "memo", the character length must be smaller than or equal to 200.'
243
+ end
244
+
245
+ @memo = memo
246
+ end
247
+
248
+ # Custom attribute writer method checking allowed values (enum).
249
+ # @param [Object] cleared Object to be assigned
250
+ def cleared=(cleared)
251
+ validator = EnumAttributeValidator.new('String', ['cleared', 'uncleared', 'reconciled'])
252
+ unless validator.valid?(cleared)
253
+ fail ArgumentError, 'invalid value for "cleared", must be one of #{validator.allowable_values}.'
254
+ end
255
+ @cleared = cleared
256
+ end
257
+
258
+ # Custom attribute writer method checking allowed values (enum).
259
+ # @param [Object] flag_color Object to be assigned
260
+ def flag_color=(flag_color)
261
+ validator = EnumAttributeValidator.new('String', ['red', 'orange', 'yellow', 'green', 'blue', 'purple'])
262
+ unless validator.valid?(flag_color)
263
+ fail ArgumentError, 'invalid value for "flag_color", must be one of #{validator.allowable_values}.'
264
+ end
265
+ @flag_color = flag_color
266
+ end
267
+
268
+ # Custom attribute writer method with validation
269
+ # @param [Object] import_id Value to be assigned
270
+ def import_id=(import_id)
271
+ if !import_id.nil? && import_id.to_s.length > 36
272
+ fail ArgumentError, 'invalid value for "import_id", the character length must be smaller than or equal to 36.'
273
+ end
274
+
275
+ @import_id = import_id
276
+ end
277
+
278
+ # Checks equality by comparing each attribute.
279
+ # @param [Object] Object to be compared
280
+ def ==(o)
281
+ return true if self.equal?(o)
282
+ self.class == o.class &&
283
+ account_id == o.account_id &&
284
+ date == o.date &&
285
+ amount == o.amount &&
286
+ payee_id == o.payee_id &&
287
+ payee_name == o.payee_name &&
288
+ category_id == o.category_id &&
289
+ memo == o.memo &&
290
+ cleared == o.cleared &&
291
+ approved == o.approved &&
292
+ flag_color == o.flag_color &&
293
+ import_id == o.import_id &&
294
+ subtransactions == o.subtransactions &&
295
+ id == o.id
296
+ end
297
+
298
+ # @see the `==` method
299
+ # @param [Object] Object to be compared
300
+ def eql?(o)
301
+ self == o
302
+ end
303
+
304
+ # Calculates hash code according to all attributes.
305
+ # @return [Fixnum] Hash code
306
+ def hash
307
+ [account_id, date, amount, payee_id, payee_name, category_id, memo, cleared, approved, flag_color, import_id, subtransactions, id].hash
308
+ end
309
+
310
+ # Builds the object from hash
311
+ # @param [Hash] attributes Model attributes in the form of hash
312
+ # @return [Object] Returns the model itself
313
+ def build_from_hash(attributes)
314
+ return nil unless attributes.is_a?(Hash)
315
+ self.class.swagger_types.each_pair do |key, type|
316
+ if type =~ /\AArray<(.*)>/i
317
+ # check to ensure the input is an array given that the attribute
318
+ # is documented as an array but the input is not
319
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
320
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
321
+ end
322
+ elsif !attributes[self.class.attribute_map[key]].nil?
323
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
324
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
325
+ end
326
+
327
+ self
328
+ end
329
+
330
+ # Deserializes the data based on type
331
+ # @param string type Data type
332
+ # @param string value Value to be deserialized
333
+ # @return [Object] Deserialized data
334
+ def _deserialize(type, value)
335
+ case type.to_sym
336
+ when :DateTime
337
+ DateTime.parse(value)
338
+ when :Date
339
+ Date.parse(value)
340
+ when :String
341
+ value.to_s
342
+ when :Integer
343
+ value.to_i
344
+ when :Float
345
+ value.to_f
346
+ when :BOOLEAN
347
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
348
+ true
349
+ else
350
+ false
351
+ end
352
+ when :Object
353
+ # generic object (usually a Hash), return directly
354
+ value
355
+ when /\AArray<(?<inner_type>.+)>\z/
356
+ inner_type = Regexp.last_match[:inner_type]
357
+ value.map { |v| _deserialize(inner_type, v) }
358
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
359
+ k_type = Regexp.last_match[:k_type]
360
+ v_type = Regexp.last_match[:v_type]
361
+ {}.tap do |hash|
362
+ value.each do |k, v|
363
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
364
+ end
365
+ end
366
+ else # model
367
+ temp_model = YNAB.const_get(type).new
368
+ temp_model.build_from_hash(value)
369
+ end
370
+ end
371
+
372
+ # Returns the string representation of the object
373
+ # @return [String] String presentation of the object
374
+ def to_s
375
+ to_hash.to_s
376
+ end
377
+
378
+ # to_body is an alias to to_hash (backward compatibility)
379
+ # @return [Hash] Returns the object in the form of hash
380
+ def to_body
381
+ to_hash
382
+ end
383
+
384
+ # Returns the object in the form of hash
385
+ # @return [Hash] Returns the object in the form of hash
386
+ def to_hash
387
+ hash = {}
388
+ self.class.attribute_map.each_pair do |attr, param|
389
+ value = self.send(attr)
390
+ next if value.nil?
391
+ hash[param] = _to_hash(value)
392
+ end
393
+ hash
394
+ end
395
+
396
+ # Outputs non-array value in the form of hash
397
+ # For object, use to_hash. Otherwise, just return the value
398
+ # @param [Object] value Any valid value
399
+ # @return [Hash] Returns the value in the form of hash
400
+ def _to_hash(value)
401
+ if value.is_a?(Array)
402
+ value.compact.map { |v| _to_hash(v) }
403
+ elsif value.is_a?(Hash)
404
+ {}.tap do |hash|
405
+ value.each { |k, v| hash[k] = _to_hash(v) }
406
+ end
407
+ elsif value.respond_to? :to_hash
408
+ value.to_hash
409
+ else
410
+ value
411
+ end
412
+ end
413
+
414
+ end
415
+ end