ynab 1.23.0 → 1.26.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,387 @@
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 SaveTransactionWithId
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 !@payee_name.nil? && @payee_name.to_s.length > 50
181
+ invalid_properties.push('invalid value for "payee_name", the character length must be smaller than or equal to 50.')
182
+ end
183
+
184
+ if !@memo.nil? && @memo.to_s.length > 200
185
+ invalid_properties.push('invalid value for "memo", the character length must be smaller than or equal to 200.')
186
+ end
187
+
188
+ if !@import_id.nil? && @import_id.to_s.length > 36
189
+ invalid_properties.push('invalid value for "import_id", the character length must be smaller than or equal to 36.')
190
+ end
191
+
192
+ invalid_properties
193
+ end
194
+
195
+ # Check to see if the all the properties in the model are valid
196
+ # @return true if the model is valid
197
+ def valid?
198
+ return false if !@payee_name.nil? && @payee_name.to_s.length > 50
199
+ return false if !@memo.nil? && @memo.to_s.length > 200
200
+ cleared_validator = EnumAttributeValidator.new('String', ['cleared', 'uncleared', 'reconciled'])
201
+ return false unless cleared_validator.valid?(@cleared)
202
+ flag_color_validator = EnumAttributeValidator.new('String', ['red', 'orange', 'yellow', 'green', 'blue', 'purple'])
203
+ return false unless flag_color_validator.valid?(@flag_color)
204
+ return false if !@import_id.nil? && @import_id.to_s.length > 36
205
+ true
206
+ end
207
+
208
+ # Custom attribute writer method with validation
209
+ # @param [Object] payee_name Value to be assigned
210
+ def payee_name=(payee_name)
211
+ if !payee_name.nil? && payee_name.to_s.length > 50
212
+ fail ArgumentError, 'invalid value for "payee_name", the character length must be smaller than or equal to 50.'
213
+ end
214
+
215
+ @payee_name = payee_name
216
+ end
217
+
218
+ # Custom attribute writer method with validation
219
+ # @param [Object] memo Value to be assigned
220
+ def memo=(memo)
221
+ if !memo.nil? && memo.to_s.length > 200
222
+ fail ArgumentError, 'invalid value for "memo", the character length must be smaller than or equal to 200.'
223
+ end
224
+
225
+ @memo = memo
226
+ end
227
+
228
+ # Custom attribute writer method checking allowed values (enum).
229
+ # @param [Object] cleared Object to be assigned
230
+ def cleared=(cleared)
231
+ @cleared = cleared
232
+ end
233
+
234
+ # Custom attribute writer method checking allowed values (enum).
235
+ # @param [Object] flag_color Object to be assigned
236
+ def flag_color=(flag_color)
237
+ @flag_color = flag_color
238
+ end
239
+
240
+ # Custom attribute writer method with validation
241
+ # @param [Object] import_id Value to be assigned
242
+ def import_id=(import_id)
243
+ if !import_id.nil? && import_id.to_s.length > 36
244
+ fail ArgumentError, 'invalid value for "import_id", the character length must be smaller than or equal to 36.'
245
+ end
246
+
247
+ @import_id = import_id
248
+ end
249
+
250
+ # Checks equality by comparing each attribute.
251
+ # @param [Object] Object to be compared
252
+ def ==(o)
253
+ return true if self.equal?(o)
254
+ self.class == o.class &&
255
+ account_id == o.account_id &&
256
+ date == o.date &&
257
+ amount == o.amount &&
258
+ payee_id == o.payee_id &&
259
+ payee_name == o.payee_name &&
260
+ category_id == o.category_id &&
261
+ memo == o.memo &&
262
+ cleared == o.cleared &&
263
+ approved == o.approved &&
264
+ flag_color == o.flag_color &&
265
+ import_id == o.import_id &&
266
+ subtransactions == o.subtransactions &&
267
+ id == o.id
268
+ end
269
+
270
+ # @see the `==` method
271
+ # @param [Object] Object to be compared
272
+ def eql?(o)
273
+ self == o
274
+ end
275
+
276
+ # Calculates hash code according to all attributes.
277
+ # @return [Fixnum] Hash code
278
+ def hash
279
+ [account_id, date, amount, payee_id, payee_name, category_id, memo, cleared, approved, flag_color, import_id, subtransactions, id].hash
280
+ end
281
+ # Builds the object from hash
282
+ # @param [Hash] attributes Model attributes in the form of hash
283
+ # @return [Object] Returns the model itself
284
+ def build_from_hash(attributes)
285
+ return nil unless attributes.is_a?(Hash)
286
+ self.class.swagger_types.each_pair do |key, type|
287
+ if type =~ /\AArray<(.*)>/i
288
+ # check to ensure the input is an array given that the attribute
289
+ # is documented as an array but the input is not
290
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
291
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map { |v| _deserialize($1, v) })
292
+ end
293
+ elsif !attributes[self.class.attribute_map[key]].nil?
294
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
295
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
296
+ end
297
+
298
+ self
299
+ end
300
+
301
+ # Deserializes the data based on type
302
+ # @param string type Data type
303
+ # @param string value Value to be deserialized
304
+ # @return [Object] Deserialized data
305
+ def _deserialize(type, value)
306
+ case type.to_sym
307
+ when :DateTime
308
+ DateTime.parse(value)
309
+ when :Date
310
+ Date.parse(value)
311
+ when :String
312
+ value.to_s
313
+ when :Integer
314
+ value.to_i
315
+ when :Float
316
+ value.to_f
317
+ when :BOOLEAN
318
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
319
+ true
320
+ else
321
+ false
322
+ end
323
+ when :Object
324
+ # generic object (usually a Hash), return directly
325
+ value
326
+ when /\AArray<(?<inner_type>.+)>\z/
327
+ inner_type = Regexp.last_match[:inner_type]
328
+ value.map { |v| _deserialize(inner_type, v) }
329
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
330
+ k_type = Regexp.last_match[:k_type]
331
+ v_type = Regexp.last_match[:v_type]
332
+ {}.tap do |hash|
333
+ value.each do |k, v|
334
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
335
+ end
336
+ end
337
+ else # model
338
+ temp_model = YNAB.const_get(type).new
339
+ temp_model.build_from_hash(value)
340
+ end
341
+ end
342
+
343
+ # Returns the string representation of the object
344
+ # @return [String] String presentation of the object
345
+ def to_s
346
+ to_hash.to_s
347
+ end
348
+
349
+ # to_body is an alias to to_hash (backward compatibility)
350
+ # @return [Hash] Returns the object in the form of hash
351
+ def to_body
352
+ to_hash
353
+ end
354
+
355
+ # Returns the object in the form of hash
356
+ # @return [Hash] Returns the object in the form of hash
357
+ def to_hash
358
+ hash = {}
359
+ self.class.attribute_map.each_pair do |attr, param|
360
+ value = self.send(attr)
361
+ next if value.nil?
362
+ hash[param] = _to_hash(value)
363
+ end
364
+ hash
365
+ end
366
+
367
+ # Outputs non-array value in the form of hash
368
+ # For object, use to_hash. Otherwise, just return the value
369
+ # @param [Object] value Any valid value
370
+ # @return [Hash] Returns the value in the form of hash
371
+ def _to_hash(value)
372
+ if value.is_a?(Array)
373
+ value.compact.map { |v| _to_hash(v) }
374
+ elsif value.is_a?(Hash)
375
+ {}.tap do |hash|
376
+ value.each { |k, v| hash[k] = _to_hash(v) }
377
+ end
378
+ elsif value.respond_to? :to_hash
379
+ value.to_hash
380
+ else
381
+ value
382
+ end
383
+ end
384
+
385
+ end
386
+
387
+ end