ynab 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (194) hide show
  1. checksums.yaml +7 -0
  2. data/Gemfile +7 -0
  3. data/Gemfile.lock +44 -0
  4. data/LICENSE.md +201 -0
  5. data/README.md +57 -0
  6. data/Rakefile +31 -0
  7. data/config.json +10 -0
  8. data/docs/Account.md +16 -0
  9. data/docs/AccountResponse.md +8 -0
  10. data/docs/AccountWrapper.md +8 -0
  11. data/docs/AccountsApi.md +121 -0
  12. data/docs/AccountsResponse.md +8 -0
  13. data/docs/AccountsWrapper.md +8 -0
  14. data/docs/BudgetDetail.md +22 -0
  15. data/docs/BudgetDetailResponse.md +8 -0
  16. data/docs/BudgetDetailWrapper.md +9 -0
  17. data/docs/BudgetSummary.md +12 -0
  18. data/docs/BudgetSummaryResponse.md +8 -0
  19. data/docs/BudgetSummaryWrapper.md +8 -0
  20. data/docs/BudgetsApi.md +116 -0
  21. data/docs/BulkIdWrapper.md +8 -0
  22. data/docs/BulkIds.md +9 -0
  23. data/docs/BulkResponse.md +8 -0
  24. data/docs/BulkTransactionCreateResponse.md +8 -0
  25. data/docs/BulkTransactionIds.md +8 -0
  26. data/docs/BulkTransactions.md +8 -0
  27. data/docs/CategoriesApi.md +121 -0
  28. data/docs/CategoriesResponse.md +8 -0
  29. data/docs/Category.md +15 -0
  30. data/docs/CategoryGroup.md +10 -0
  31. data/docs/CategoryGroupWithCategories.md +11 -0
  32. data/docs/CategoryGroupsWrapper.md +8 -0
  33. data/docs/CategoryResponse.md +8 -0
  34. data/docs/CategoryWrapper.md +8 -0
  35. data/docs/CurrencyFormat.md +8 -0
  36. data/docs/DateFormat.md +8 -0
  37. data/docs/ErrorDetail.md +10 -0
  38. data/docs/ErrorResponse.md +8 -0
  39. data/docs/MonthDetail.md +12 -0
  40. data/docs/MonthDetailResponse.md +8 -0
  41. data/docs/MonthDetailWrapper.md +8 -0
  42. data/docs/MonthSummariesResponse.md +8 -0
  43. data/docs/MonthSummariesWrapper.md +8 -0
  44. data/docs/MonthSummary.md +11 -0
  45. data/docs/MonthsApi.md +121 -0
  46. data/docs/Payee.md +10 -0
  47. data/docs/PayeeLocation.md +11 -0
  48. data/docs/PayeeLocationResponse.md +8 -0
  49. data/docs/PayeeLocationWrapper.md +8 -0
  50. data/docs/PayeeLocationsApi.md +179 -0
  51. data/docs/PayeeLocationsResponse.md +8 -0
  52. data/docs/PayeeLocationsWrapper.md +8 -0
  53. data/docs/PayeeResponse.md +8 -0
  54. data/docs/PayeeWrapper.md +8 -0
  55. data/docs/PayeesApi.md +121 -0
  56. data/docs/PayeesResponse.md +8 -0
  57. data/docs/PayeesWrapper.md +8 -0
  58. data/docs/SaveTransaction.md +18 -0
  59. data/docs/SaveTransactionWrapper.md +8 -0
  60. data/docs/ScheduledSubTransaction.md +14 -0
  61. data/docs/ScheduledTransactionDetail.md +19 -0
  62. data/docs/ScheduledTransactionResponse.md +8 -0
  63. data/docs/ScheduledTransactionSummary.md +18 -0
  64. data/docs/ScheduledTransactionWrapper.md +8 -0
  65. data/docs/ScheduledTransactionsApi.md +121 -0
  66. data/docs/ScheduledTransactionsResponse.md +8 -0
  67. data/docs/ScheduledTransactionsWrapper.md +8 -0
  68. data/docs/SubTransaction.md +14 -0
  69. data/docs/TransactionDetail.md +20 -0
  70. data/docs/TransactionResponse.md +8 -0
  71. data/docs/TransactionSummary.md +19 -0
  72. data/docs/TransactionWrapper.md +8 -0
  73. data/docs/TransactionsApi.md +428 -0
  74. data/docs/TransactionsResponse.md +8 -0
  75. data/docs/TransactionsWrapper.md +8 -0
  76. data/examples/budget-list.rb +25 -0
  77. data/examples/budget-month.rb +36 -0
  78. data/examples/category-balance.rb +27 -0
  79. data/lib/ynab.rb +136 -0
  80. data/lib/ynab/api/accounts_api.rb +135 -0
  81. data/lib/ynab/api/budgets_api.rb +126 -0
  82. data/lib/ynab/api/categories_api.rb +135 -0
  83. data/lib/ynab/api/months_api.rb +135 -0
  84. data/lib/ynab/api/payee_locations_api.rb +194 -0
  85. data/lib/ynab/api/payees_api.rb +135 -0
  86. data/lib/ynab/api/scheduled_transactions_api.rb +135 -0
  87. data/lib/ynab/api/transactions_api.rb +451 -0
  88. data/lib/ynab/api_client.rb +392 -0
  89. data/lib/ynab/api_error.rb +38 -0
  90. data/lib/ynab/configuration.rb +209 -0
  91. data/lib/ynab/models/account.rb +343 -0
  92. data/lib/ynab/models/account_response.rb +193 -0
  93. data/lib/ynab/models/account_wrapper.rb +193 -0
  94. data/lib/ynab/models/accounts_response.rb +193 -0
  95. data/lib/ynab/models/accounts_wrapper.rb +195 -0
  96. data/lib/ynab/models/budget_detail.rb +345 -0
  97. data/lib/ynab/models/budget_detail_response.rb +193 -0
  98. data/lib/ynab/models/budget_detail_wrapper.rb +208 -0
  99. data/lib/ynab/models/budget_summary.rb +235 -0
  100. data/lib/ynab/models/budget_summary_response.rb +193 -0
  101. data/lib/ynab/models/budget_summary_wrapper.rb +195 -0
  102. data/lib/ynab/models/bulk_id_wrapper.rb +193 -0
  103. data/lib/ynab/models/bulk_ids.rb +213 -0
  104. data/lib/ynab/models/bulk_response.rb +193 -0
  105. data/lib/ynab/models/bulk_transaction_create_response.rb +193 -0
  106. data/lib/ynab/models/bulk_transaction_ids.rb +195 -0
  107. data/lib/ynab/models/bulk_transactions.rb +195 -0
  108. data/lib/ynab/models/categories_response.rb +193 -0
  109. data/lib/ynab/models/category.rb +295 -0
  110. data/lib/ynab/models/category_group.rb +222 -0
  111. data/lib/ynab/models/category_group_with_categories.rb +239 -0
  112. data/lib/ynab/models/category_groups_wrapper.rb +195 -0
  113. data/lib/ynab/models/category_response.rb +193 -0
  114. data/lib/ynab/models/category_wrapper.rb +193 -0
  115. data/lib/ynab/models/currency_format.rb +193 -0
  116. data/lib/ynab/models/date_format.rb +193 -0
  117. data/lib/ynab/models/error_detail.rb +221 -0
  118. data/lib/ynab/models/error_response.rb +193 -0
  119. data/lib/ynab/models/month_detail.rb +253 -0
  120. data/lib/ynab/models/month_detail_response.rb +193 -0
  121. data/lib/ynab/models/month_detail_wrapper.rb +193 -0
  122. data/lib/ynab/models/month_summaries_response.rb +193 -0
  123. data/lib/ynab/models/month_summaries_wrapper.rb +195 -0
  124. data/lib/ynab/models/month_summary.rb +236 -0
  125. data/lib/ynab/models/payee.rb +222 -0
  126. data/lib/ynab/models/payee_location.rb +235 -0
  127. data/lib/ynab/models/payee_location_response.rb +193 -0
  128. data/lib/ynab/models/payee_location_wrapper.rb +193 -0
  129. data/lib/ynab/models/payee_locations_response.rb +193 -0
  130. data/lib/ynab/models/payee_locations_wrapper.rb +195 -0
  131. data/lib/ynab/models/payee_response.rb +193 -0
  132. data/lib/ynab/models/payee_wrapper.rb +193 -0
  133. data/lib/ynab/models/payees_response.rb +193 -0
  134. data/lib/ynab/models/payees_wrapper.rb +195 -0
  135. data/lib/ynab/models/save_transaction.rb +346 -0
  136. data/lib/ynab/models/save_transaction_wrapper.rb +193 -0
  137. data/lib/ynab/models/scheduled_sub_transaction.rb +279 -0
  138. data/lib/ynab/models/scheduled_transaction_detail.rb +387 -0
  139. data/lib/ynab/models/scheduled_transaction_response.rb +193 -0
  140. data/lib/ynab/models/scheduled_transaction_summary.rb +370 -0
  141. data/lib/ynab/models/scheduled_transaction_wrapper.rb +193 -0
  142. data/lib/ynab/models/scheduled_transactions_response.rb +193 -0
  143. data/lib/ynab/models/scheduled_transactions_wrapper.rb +195 -0
  144. data/lib/ynab/models/sub_transaction.rb +279 -0
  145. data/lib/ynab/models/transaction_detail.rb +401 -0
  146. data/lib/ynab/models/transaction_response.rb +193 -0
  147. data/lib/ynab/models/transaction_summary.rb +384 -0
  148. data/lib/ynab/models/transaction_wrapper.rb +193 -0
  149. data/lib/ynab/models/transactions_response.rb +193 -0
  150. data/lib/ynab/models/transactions_wrapper.rb +195 -0
  151. data/lib/ynab/version.rb +15 -0
  152. data/pkg/ynab-0.1.0.gem +0 -0
  153. data/spec-v1-swagger.json +2121 -0
  154. data/spec/api/accounts_spec.rb +56 -0
  155. data/spec/api/budgets_spec.rb +55 -0
  156. data/spec/api/categories_spec.rb +57 -0
  157. data/spec/api/months_spec.rb +57 -0
  158. data/spec/api/payee_locations_spec.rb +57 -0
  159. data/spec/api/payees_spec.rb +56 -0
  160. data/spec/api/scheduled_transactions_spec.rb +56 -0
  161. data/spec/api/transactions_spec.rb +122 -0
  162. data/spec/fixtures/.DS_Store +0 -0
  163. data/spec/fixtures/vcr_cassettes/account.yml +46 -0
  164. data/spec/fixtures/vcr_cassettes/accounts.yml +46 -0
  165. data/spec/fixtures/vcr_cassettes/accounts_unauthorized.yml +49 -0
  166. data/spec/fixtures/vcr_cassettes/budget.yml +1413 -0
  167. data/spec/fixtures/vcr_cassettes/budgets.yml +49 -0
  168. data/spec/fixtures/vcr_cassettes/budgets_unauthorized.yml +49 -0
  169. data/spec/fixtures/vcr_cassettes/bulk_transactions.yml +46 -0
  170. data/spec/fixtures/vcr_cassettes/categories.yml +67 -0
  171. data/spec/fixtures/vcr_cassettes/categories_unauthorized.yml +49 -0
  172. data/spec/fixtures/vcr_cassettes/category.yml +46 -0
  173. data/spec/fixtures/vcr_cassettes/create_transaction.yml +46 -0
  174. data/spec/fixtures/vcr_cassettes/month.yml +59 -0
  175. data/spec/fixtures/vcr_cassettes/months.yml +47 -0
  176. data/spec/fixtures/vcr_cassettes/months_unauthorized.yml +49 -0
  177. data/spec/fixtures/vcr_cassettes/payee.yml +47 -0
  178. data/spec/fixtures/vcr_cassettes/payee_location.yml +46 -0
  179. data/spec/fixtures/vcr_cassettes/payee_locations.yml +46 -0
  180. data/spec/fixtures/vcr_cassettes/payee_locations_unauthorized.yml +49 -0
  181. data/spec/fixtures/vcr_cassettes/payees.yml +51 -0
  182. data/spec/fixtures/vcr_cassettes/payees_unauthorized.yml +49 -0
  183. data/spec/fixtures/vcr_cassettes/scheduled_transaction.yml +46 -0
  184. data/spec/fixtures/vcr_cassettes/scheduled_transactions.yml +46 -0
  185. data/spec/fixtures/vcr_cassettes/scheduled_transactions_unauthorized.yml +49 -0
  186. data/spec/fixtures/vcr_cassettes/transaction.yml +46 -0
  187. data/spec/fixtures/vcr_cassettes/transactions.yml +46 -0
  188. data/spec/fixtures/vcr_cassettes/transactions_unauthorized.yml +49 -0
  189. data/spec/fixtures/vcr_cassettes/update_transaction.yml +46 -0
  190. data/spec/spec_helper.rb +18 -0
  191. data/swagger-templates/api_client.mustache +386 -0
  192. data/swagger-templates/gemspec.mustache +37 -0
  193. data/ynab.gemspec +40 -0
  194. metadata +353 -0
@@ -0,0 +1,279 @@
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.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module YnabApi
16
+
17
+ class SubTransaction
18
+ attr_accessor :id
19
+
20
+ attr_accessor :transaction_id
21
+
22
+ # The sub-transaction amount in milliunits format
23
+ attr_accessor :amount
24
+
25
+ attr_accessor :memo
26
+
27
+ attr_accessor :payee_id
28
+
29
+ attr_accessor :category_id
30
+
31
+ # If a transfer, the account_id which the subtransaction transfers to
32
+ attr_accessor :transfer_account_id
33
+
34
+
35
+ # Attribute mapping from ruby-style variable name to JSON key.
36
+ def self.attribute_map
37
+ {
38
+ :'id' => :'id',
39
+ :'transaction_id' => :'transaction_id',
40
+ :'amount' => :'amount',
41
+ :'memo' => :'memo',
42
+ :'payee_id' => :'payee_id',
43
+ :'category_id' => :'category_id',
44
+ :'transfer_account_id' => :'transfer_account_id'
45
+ }
46
+ end
47
+
48
+ # Attribute type mapping.
49
+ def self.swagger_types
50
+ {
51
+ :'id' => :'String',
52
+ :'transaction_id' => :'String',
53
+ :'amount' => :'Float',
54
+ :'memo' => :'String',
55
+ :'payee_id' => :'String',
56
+ :'category_id' => :'String',
57
+ :'transfer_account_id' => :'String'
58
+ }
59
+ end
60
+
61
+ # Initializes the object
62
+ # @param [Hash] attributes Model attributes in the form of hash
63
+ def initialize(attributes = {})
64
+ return unless attributes.is_a?(Hash)
65
+
66
+ # convert string to symbol for hash key
67
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
68
+
69
+ if attributes.has_key?(:'id')
70
+ self.id = attributes[:'id']
71
+ end
72
+
73
+ if attributes.has_key?(:'transaction_id')
74
+ self.transaction_id = attributes[:'transaction_id']
75
+ end
76
+
77
+ if attributes.has_key?(:'amount')
78
+ self.amount = attributes[:'amount']
79
+ end
80
+
81
+ if attributes.has_key?(:'memo')
82
+ self.memo = attributes[:'memo']
83
+ end
84
+
85
+ if attributes.has_key?(:'payee_id')
86
+ self.payee_id = attributes[:'payee_id']
87
+ end
88
+
89
+ if attributes.has_key?(:'category_id')
90
+ self.category_id = attributes[:'category_id']
91
+ end
92
+
93
+ if attributes.has_key?(:'transfer_account_id')
94
+ self.transfer_account_id = attributes[:'transfer_account_id']
95
+ end
96
+
97
+ end
98
+
99
+ # Show invalid properties with the reasons. Usually used together with valid?
100
+ # @return Array for valid properties with the reasons
101
+ def list_invalid_properties
102
+ invalid_properties = Array.new
103
+ if @id.nil?
104
+ invalid_properties.push("invalid value for 'id', id cannot be nil.")
105
+ end
106
+
107
+ if @transaction_id.nil?
108
+ invalid_properties.push("invalid value for 'transaction_id', transaction_id cannot be nil.")
109
+ end
110
+
111
+ if @amount.nil?
112
+ invalid_properties.push("invalid value for 'amount', amount cannot be nil.")
113
+ end
114
+
115
+ if @memo.nil?
116
+ invalid_properties.push("invalid value for 'memo', memo cannot be nil.")
117
+ end
118
+
119
+ if @payee_id.nil?
120
+ invalid_properties.push("invalid value for 'payee_id', payee_id cannot be nil.")
121
+ end
122
+
123
+ if @category_id.nil?
124
+ invalid_properties.push("invalid value for 'category_id', category_id cannot be nil.")
125
+ end
126
+
127
+ if @transfer_account_id.nil?
128
+ invalid_properties.push("invalid value for 'transfer_account_id', transfer_account_id cannot be nil.")
129
+ end
130
+
131
+ return invalid_properties
132
+ end
133
+
134
+ # Check to see if the all the properties in the model are valid
135
+ # @return true if the model is valid
136
+ def valid?
137
+ return false if @id.nil?
138
+ return false if @transaction_id.nil?
139
+ return false if @amount.nil?
140
+ return false if @memo.nil?
141
+ return false if @payee_id.nil?
142
+ return false if @category_id.nil?
143
+ return false if @transfer_account_id.nil?
144
+ return true
145
+ end
146
+
147
+ # Checks equality by comparing each attribute.
148
+ # @param [Object] Object to be compared
149
+ def ==(o)
150
+ return true if self.equal?(o)
151
+ self.class == o.class &&
152
+ id == o.id &&
153
+ transaction_id == o.transaction_id &&
154
+ amount == o.amount &&
155
+ memo == o.memo &&
156
+ payee_id == o.payee_id &&
157
+ category_id == o.category_id &&
158
+ transfer_account_id == o.transfer_account_id
159
+ end
160
+
161
+ # @see the `==` method
162
+ # @param [Object] Object to be compared
163
+ def eql?(o)
164
+ self == o
165
+ end
166
+
167
+ # Calculates hash code according to all attributes.
168
+ # @return [Fixnum] Hash code
169
+ def hash
170
+ [id, transaction_id, amount, memo, payee_id, category_id, transfer_account_id].hash
171
+ end
172
+
173
+ # Builds the object from hash
174
+ # @param [Hash] attributes Model attributes in the form of hash
175
+ # @return [Object] Returns the model itself
176
+ def build_from_hash(attributes)
177
+ return nil unless attributes.is_a?(Hash)
178
+ self.class.swagger_types.each_pair do |key, type|
179
+ if type =~ /\AArray<(.*)>/i
180
+ # check to ensure the input is an array given that the the attribute
181
+ # is documented as an array but the input is not
182
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
183
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
184
+ end
185
+ elsif !attributes[self.class.attribute_map[key]].nil?
186
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
187
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
188
+ end
189
+
190
+ self
191
+ end
192
+
193
+ # Deserializes the data based on type
194
+ # @param string type Data type
195
+ # @param string value Value to be deserialized
196
+ # @return [Object] Deserialized data
197
+ def _deserialize(type, value)
198
+ case type.to_sym
199
+ when :DateTime
200
+ DateTime.parse(value)
201
+ when :Date
202
+ Date.parse(value)
203
+ when :String
204
+ value.to_s
205
+ when :Integer
206
+ value.to_i
207
+ when :Float
208
+ value.to_f
209
+ when :BOOLEAN
210
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
211
+ true
212
+ else
213
+ false
214
+ end
215
+ when :Object
216
+ # generic object (usually a Hash), return directly
217
+ value
218
+ when /\AArray<(?<inner_type>.+)>\z/
219
+ inner_type = Regexp.last_match[:inner_type]
220
+ value.map { |v| _deserialize(inner_type, v) }
221
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
222
+ k_type = Regexp.last_match[:k_type]
223
+ v_type = Regexp.last_match[:v_type]
224
+ {}.tap do |hash|
225
+ value.each do |k, v|
226
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
227
+ end
228
+ end
229
+ else # model
230
+ temp_model = YnabApi.const_get(type).new
231
+ temp_model.build_from_hash(value)
232
+ end
233
+ end
234
+
235
+ # Returns the string representation of the object
236
+ # @return [String] String presentation of the object
237
+ def to_s
238
+ to_hash.to_s
239
+ end
240
+
241
+ # to_body is an alias to to_hash (backward compatibility)
242
+ # @return [Hash] Returns the object in the form of hash
243
+ def to_body
244
+ to_hash
245
+ end
246
+
247
+ # Returns the object in the form of hash
248
+ # @return [Hash] Returns the object in the form of hash
249
+ def to_hash
250
+ hash = {}
251
+ self.class.attribute_map.each_pair do |attr, param|
252
+ value = self.send(attr)
253
+ next if value.nil?
254
+ hash[param] = _to_hash(value)
255
+ end
256
+ hash
257
+ end
258
+
259
+ # Outputs non-array value in the form of hash
260
+ # For object, use to_hash. Otherwise, just return the value
261
+ # @param [Object] value Any valid value
262
+ # @return [Hash] Returns the value in the form of hash
263
+ def _to_hash(value)
264
+ if value.is_a?(Array)
265
+ value.compact.map{ |v| _to_hash(v) }
266
+ elsif value.is_a?(Hash)
267
+ {}.tap do |hash|
268
+ value.each { |k, v| hash[k] = _to_hash(v) }
269
+ end
270
+ elsif value.respond_to? :to_hash
271
+ value.to_hash
272
+ else
273
+ value
274
+ end
275
+ end
276
+
277
+ end
278
+
279
+ end
@@ -0,0 +1,401 @@
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.3.1
10
+
11
+ =end
12
+
13
+ require 'date'
14
+
15
+ module YnabApi
16
+
17
+ class TransactionDetail
18
+ attr_accessor :id
19
+
20
+ attr_accessor :date
21
+
22
+ # The transaction amount in milliunits format
23
+ attr_accessor :amount
24
+
25
+ attr_accessor :memo
26
+
27
+ # The cleared status of the transaction
28
+ attr_accessor :cleared
29
+
30
+ # Whether or not the transaction is approved
31
+ attr_accessor :approved
32
+
33
+ attr_accessor :flag_color
34
+
35
+ attr_accessor :account_id
36
+
37
+ attr_accessor :payee_id
38
+
39
+ attr_accessor :category_id
40
+
41
+ attr_accessor :transfer_account_id
42
+
43
+ # If the Transaction was imported, this field is a unique (by account) import identifier. If this transaction was imported through File Based Import or Direct Import and not through the API, the import_id will have the format: 'YNAB:[milliunit_amount]:[iso_date]:[occurance]'. 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'.
44
+ attr_accessor :import_id
45
+
46
+ # If a split transaction, the sub-transactions.
47
+ attr_accessor :subtransactions
48
+
49
+ class EnumAttributeValidator
50
+ attr_reader :datatype
51
+ attr_reader :allowable_values
52
+
53
+ def initialize(datatype, allowable_values)
54
+ @allowable_values = allowable_values.map do |value|
55
+ case datatype.to_s
56
+ when /Integer/i
57
+ value.to_i
58
+ when /Float/i
59
+ value.to_f
60
+ else
61
+ value
62
+ end
63
+ end
64
+ end
65
+
66
+ def valid?(value)
67
+ !value || allowable_values.include?(value)
68
+ end
69
+ end
70
+
71
+ # Attribute mapping from ruby-style variable name to JSON key.
72
+ def self.attribute_map
73
+ {
74
+ :'id' => :'id',
75
+ :'date' => :'date',
76
+ :'amount' => :'amount',
77
+ :'memo' => :'memo',
78
+ :'cleared' => :'cleared',
79
+ :'approved' => :'approved',
80
+ :'flag_color' => :'flag_color',
81
+ :'account_id' => :'account_id',
82
+ :'payee_id' => :'payee_id',
83
+ :'category_id' => :'category_id',
84
+ :'transfer_account_id' => :'transfer_account_id',
85
+ :'import_id' => :'import_id',
86
+ :'subtransactions' => :'subtransactions'
87
+ }
88
+ end
89
+
90
+ # Attribute type mapping.
91
+ def self.swagger_types
92
+ {
93
+ :'id' => :'String',
94
+ :'date' => :'Date',
95
+ :'amount' => :'Float',
96
+ :'memo' => :'String',
97
+ :'cleared' => :'String',
98
+ :'approved' => :'BOOLEAN',
99
+ :'flag_color' => :'String',
100
+ :'account_id' => :'String',
101
+ :'payee_id' => :'String',
102
+ :'category_id' => :'String',
103
+ :'transfer_account_id' => :'String',
104
+ :'import_id' => :'String',
105
+ :'subtransactions' => :'Array<SubTransaction>'
106
+ }
107
+ end
108
+
109
+ # Initializes the object
110
+ # @param [Hash] attributes Model attributes in the form of hash
111
+ def initialize(attributes = {})
112
+ return unless attributes.is_a?(Hash)
113
+
114
+ # convert string to symbol for hash key
115
+ attributes = attributes.each_with_object({}){|(k,v), h| h[k.to_sym] = v}
116
+
117
+ if attributes.has_key?(:'id')
118
+ self.id = attributes[:'id']
119
+ end
120
+
121
+ if attributes.has_key?(:'date')
122
+ self.date = attributes[:'date']
123
+ end
124
+
125
+ if attributes.has_key?(:'amount')
126
+ self.amount = attributes[:'amount']
127
+ end
128
+
129
+ if attributes.has_key?(:'memo')
130
+ self.memo = attributes[:'memo']
131
+ end
132
+
133
+ if attributes.has_key?(:'cleared')
134
+ self.cleared = attributes[:'cleared']
135
+ end
136
+
137
+ if attributes.has_key?(:'approved')
138
+ self.approved = attributes[:'approved']
139
+ end
140
+
141
+ if attributes.has_key?(:'flag_color')
142
+ self.flag_color = attributes[:'flag_color']
143
+ end
144
+
145
+ if attributes.has_key?(:'account_id')
146
+ self.account_id = attributes[:'account_id']
147
+ end
148
+
149
+ if attributes.has_key?(:'payee_id')
150
+ self.payee_id = attributes[:'payee_id']
151
+ end
152
+
153
+ if attributes.has_key?(:'category_id')
154
+ self.category_id = attributes[:'category_id']
155
+ end
156
+
157
+ if attributes.has_key?(:'transfer_account_id')
158
+ self.transfer_account_id = attributes[:'transfer_account_id']
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
+ end
172
+
173
+ # Show invalid properties with the reasons. Usually used together with valid?
174
+ # @return Array for valid properties with the reasons
175
+ def list_invalid_properties
176
+ invalid_properties = Array.new
177
+ if @id.nil?
178
+ invalid_properties.push("invalid value for 'id', id cannot be nil.")
179
+ end
180
+
181
+ if @date.nil?
182
+ invalid_properties.push("invalid value for 'date', date cannot be nil.")
183
+ end
184
+
185
+ if @amount.nil?
186
+ invalid_properties.push("invalid value for 'amount', amount cannot be nil.")
187
+ end
188
+
189
+ if @memo.nil?
190
+ invalid_properties.push("invalid value for 'memo', memo cannot be nil.")
191
+ end
192
+
193
+ if @cleared.nil?
194
+ invalid_properties.push("invalid value for 'cleared', cleared cannot be nil.")
195
+ end
196
+
197
+ if @approved.nil?
198
+ invalid_properties.push("invalid value for 'approved', approved cannot be nil.")
199
+ end
200
+
201
+ if @flag_color.nil?
202
+ invalid_properties.push("invalid value for 'flag_color', flag_color cannot be nil.")
203
+ end
204
+
205
+ if @account_id.nil?
206
+ invalid_properties.push("invalid value for 'account_id', account_id cannot be nil.")
207
+ end
208
+
209
+ if @payee_id.nil?
210
+ invalid_properties.push("invalid value for 'payee_id', payee_id cannot be nil.")
211
+ end
212
+
213
+ if @category_id.nil?
214
+ invalid_properties.push("invalid value for 'category_id', category_id cannot be nil.")
215
+ end
216
+
217
+ if @transfer_account_id.nil?
218
+ invalid_properties.push("invalid value for 'transfer_account_id', transfer_account_id cannot be nil.")
219
+ end
220
+
221
+ if @import_id.nil?
222
+ invalid_properties.push("invalid value for 'import_id', import_id cannot be nil.")
223
+ end
224
+
225
+ if @subtransactions.nil?
226
+ invalid_properties.push("invalid value for 'subtransactions', subtransactions cannot be nil.")
227
+ end
228
+
229
+ return invalid_properties
230
+ end
231
+
232
+ # Check to see if the all the properties in the model are valid
233
+ # @return true if the model is valid
234
+ def valid?
235
+ return false if @id.nil?
236
+ return false if @date.nil?
237
+ return false if @amount.nil?
238
+ return false if @memo.nil?
239
+ return false if @cleared.nil?
240
+ cleared_validator = EnumAttributeValidator.new('String', ["cleared", "uncleared", "reconciled"])
241
+ return false unless cleared_validator.valid?(@cleared)
242
+ return false if @approved.nil?
243
+ return false if @flag_color.nil?
244
+ return false if @account_id.nil?
245
+ return false if @payee_id.nil?
246
+ return false if @category_id.nil?
247
+ return false if @transfer_account_id.nil?
248
+ return false if @import_id.nil?
249
+ return false if @subtransactions.nil?
250
+ return true
251
+ end
252
+
253
+ # Custom attribute writer method checking allowed values (enum).
254
+ # @param [Object] cleared Object to be assigned
255
+ def cleared=(cleared)
256
+ validator = EnumAttributeValidator.new('String', ["cleared", "uncleared", "reconciled"])
257
+ unless validator.valid?(cleared)
258
+ fail ArgumentError, "invalid value for 'cleared', must be one of #{validator.allowable_values}."
259
+ end
260
+ @cleared = cleared
261
+ end
262
+
263
+ # Checks equality by comparing each attribute.
264
+ # @param [Object] Object to be compared
265
+ def ==(o)
266
+ return true if self.equal?(o)
267
+ self.class == o.class &&
268
+ id == o.id &&
269
+ date == o.date &&
270
+ amount == o.amount &&
271
+ memo == o.memo &&
272
+ cleared == o.cleared &&
273
+ approved == o.approved &&
274
+ flag_color == o.flag_color &&
275
+ account_id == o.account_id &&
276
+ payee_id == o.payee_id &&
277
+ category_id == o.category_id &&
278
+ transfer_account_id == o.transfer_account_id &&
279
+ import_id == o.import_id &&
280
+ subtransactions == o.subtransactions
281
+ end
282
+
283
+ # @see the `==` method
284
+ # @param [Object] Object to be compared
285
+ def eql?(o)
286
+ self == o
287
+ end
288
+
289
+ # Calculates hash code according to all attributes.
290
+ # @return [Fixnum] Hash code
291
+ def hash
292
+ [id, date, amount, memo, cleared, approved, flag_color, account_id, payee_id, category_id, transfer_account_id, import_id, subtransactions].hash
293
+ end
294
+
295
+ # Builds the object from hash
296
+ # @param [Hash] attributes Model attributes in the form of hash
297
+ # @return [Object] Returns the model itself
298
+ def build_from_hash(attributes)
299
+ return nil unless attributes.is_a?(Hash)
300
+ self.class.swagger_types.each_pair do |key, type|
301
+ if type =~ /\AArray<(.*)>/i
302
+ # check to ensure the input is an array given that the the attribute
303
+ # is documented as an array but the input is not
304
+ if attributes[self.class.attribute_map[key]].is_a?(Array)
305
+ self.send("#{key}=", attributes[self.class.attribute_map[key]].map{ |v| _deserialize($1, v) } )
306
+ end
307
+ elsif !attributes[self.class.attribute_map[key]].nil?
308
+ self.send("#{key}=", _deserialize(type, attributes[self.class.attribute_map[key]]))
309
+ end # or else data not found in attributes(hash), not an issue as the data can be optional
310
+ end
311
+
312
+ self
313
+ end
314
+
315
+ # Deserializes the data based on type
316
+ # @param string type Data type
317
+ # @param string value Value to be deserialized
318
+ # @return [Object] Deserialized data
319
+ def _deserialize(type, value)
320
+ case type.to_sym
321
+ when :DateTime
322
+ DateTime.parse(value)
323
+ when :Date
324
+ Date.parse(value)
325
+ when :String
326
+ value.to_s
327
+ when :Integer
328
+ value.to_i
329
+ when :Float
330
+ value.to_f
331
+ when :BOOLEAN
332
+ if value.to_s =~ /\A(true|t|yes|y|1)\z/i
333
+ true
334
+ else
335
+ false
336
+ end
337
+ when :Object
338
+ # generic object (usually a Hash), return directly
339
+ value
340
+ when /\AArray<(?<inner_type>.+)>\z/
341
+ inner_type = Regexp.last_match[:inner_type]
342
+ value.map { |v| _deserialize(inner_type, v) }
343
+ when /\AHash<(?<k_type>.+?), (?<v_type>.+)>\z/
344
+ k_type = Regexp.last_match[:k_type]
345
+ v_type = Regexp.last_match[:v_type]
346
+ {}.tap do |hash|
347
+ value.each do |k, v|
348
+ hash[_deserialize(k_type, k)] = _deserialize(v_type, v)
349
+ end
350
+ end
351
+ else # model
352
+ temp_model = YnabApi.const_get(type).new
353
+ temp_model.build_from_hash(value)
354
+ end
355
+ end
356
+
357
+ # Returns the string representation of the object
358
+ # @return [String] String presentation of the object
359
+ def to_s
360
+ to_hash.to_s
361
+ end
362
+
363
+ # to_body is an alias to to_hash (backward compatibility)
364
+ # @return [Hash] Returns the object in the form of hash
365
+ def to_body
366
+ to_hash
367
+ end
368
+
369
+ # Returns the object in the form of hash
370
+ # @return [Hash] Returns the object in the form of hash
371
+ def to_hash
372
+ hash = {}
373
+ self.class.attribute_map.each_pair do |attr, param|
374
+ value = self.send(attr)
375
+ next if value.nil?
376
+ hash[param] = _to_hash(value)
377
+ end
378
+ hash
379
+ end
380
+
381
+ # Outputs non-array value in the form of hash
382
+ # For object, use to_hash. Otherwise, just return the value
383
+ # @param [Object] value Any valid value
384
+ # @return [Hash] Returns the value in the form of hash
385
+ def _to_hash(value)
386
+ if value.is_a?(Array)
387
+ value.compact.map{ |v| _to_hash(v) }
388
+ elsif value.is_a?(Hash)
389
+ {}.tap do |hash|
390
+ value.each { |k, v| hash[k] = _to_hash(v) }
391
+ end
392
+ elsif value.respond_to? :to_hash
393
+ value.to_hash
394
+ else
395
+ value
396
+ end
397
+ end
398
+
399
+ end
400
+
401
+ end