figo 1.1.1 → 1.2.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/lib/models.rb CHANGED
@@ -1,16 +1,16 @@
1
1
  #
2
2
  # Copyright (c) 2013 figo GmbH
3
- #
3
+ #
4
4
  # Permission is hereby granted, free of charge, to any person obtaining a copy
5
5
  # of this software and associated documentation files (the "Software"), to deal
6
6
  # in the Software without restriction, including without limitation the rights
7
7
  # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
8
  # copies of the Software, and to permit persons to whom the Software is
9
9
  # furnished to do so, subject to the following conditions:
10
- #
10
+ #
11
11
  # The above copyright notice and this permission notice shall be included in
12
12
  # all copies or substantial portions of the Software.
13
- #
13
+ #
14
14
  # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
15
  # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
16
  # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
@@ -18,43 +18,23 @@
18
18
  # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
19
  # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20
20
  # THE SOFTWARE.
21
- #
21
+ #
22
22
 
23
23
  require "date"
24
24
  require "flt"
25
25
 
26
26
 
27
27
  module Figo
28
-
29
28
  # Set decimal precision to two digits.
30
29
  Flt::DecNum.context.precision = 2
31
30
 
32
- # Account type enumeration.
33
- class AccountType
34
- GIRO = "Giro account"
35
- SAVINGS = "Savings account"
36
- CREDIT_CARD = "Credit card"
37
- LOAN = "Loan account"
38
- PAYPAL = "PayPal"
39
- CASH_BOOK = "Cash book"
40
- UNKNOWN = "Unknown"
41
- end
42
-
43
- # Transaction type enumeration.
44
- class TransactionType
45
- TRANSFER = "Transfer"
46
- STANDING_ORDER = "Standing order"
47
- DIRECT_DEBIT = "Direct debit"
48
- SALARY_OR_RENT = "Salary or rent"
49
- ELECTRONIC_CASH = "Electronic cash"
50
- GELDKARTE = "GeldKarte"
51
- ATM = "ATM"
52
- CHARGES_OR_INTEREST = "Charges or interest"
53
- UNKNOWN = "Unknown"
54
- end
55
-
56
31
  # Abstract base class for model objects.
57
32
  class Base
33
+ # Attributes to be dumped (called by modify and create)
34
+ @dump_attributes = []
35
+ def self.dump_attributes
36
+ @dump_attributes
37
+ end
58
38
 
59
39
  # Instantiate model object from hash.
60
40
  #
@@ -64,6 +44,10 @@ module Figo
64
44
  @session = session
65
45
 
66
46
  hash.each do |key, value|
47
+ key = key.to_s if key.is_a? Symbol
48
+ next unless respond_to? "#{key}="
49
+ next if value.nil?
50
+
67
51
  if key == "status"
68
52
  value = SynchronizationStatus.new(session, value)
69
53
  elsif key == "amount" or key == "balance" or key == "credit_line" or key == "monthly_spending_limit"
@@ -71,127 +55,203 @@ module Figo
71
55
  elsif key.end_with?("_date")
72
56
  value = DateTime.iso8601(value)
73
57
  elsif key.end_with?("_timestamp")
74
- value = Date.iso8601(value)
58
+ value = DateTime.iso8601(value)
75
59
  end
76
- instance_variable_set("@#{key}", value)
60
+ send("#{key}=", value)
61
+ end
62
+ end
63
+
64
+ # Dump committable attributes to a hash
65
+ def dump
66
+ result = {}
67
+ self.class.dump_attributes.each do |attribute|
68
+ value = send attribute
69
+ next if value.nil?
70
+ value = value.to_f if value.is_a? Flt::DecNum
71
+
72
+ result[attribute] = value
77
73
  end
74
+ return result
78
75
  end
76
+ end
77
+
78
+ # Object representing an User
79
+ class User < Base
80
+ @dump_attributes = [:name, :address, :send_newsletter, :language]
81
+
82
+ # Internal figo Connect User ID
83
+ # @return [String]
84
+ attr_accessor :User_id
85
+
86
+ # First and last name
87
+ # @return [String]
88
+ attr_accessor :name
89
+
90
+ # Email address
91
+ # @return [String]
92
+ attr_accessor :email
93
+
94
+ #Postal address for bills, etc.
95
+ # @return [Dict]
96
+ attr_accessor :address
97
+
98
+ # This flag indicates whether the email address has been verified
99
+ # @return [Boolean]
100
+ attr_accessor :verified_email
79
101
 
102
+ # This flag indicates whether the User has agreed to be contacted by email
103
+ # @return [Boolean]
104
+ attr_accessor :send_newsletter
105
+
106
+ # Two-letter code of preferred language
107
+ # @return [String]
108
+ attr_accessor :language
109
+
110
+ # This flag indicates whether the figo Account plan is free or premium
111
+ # @return [Boolean]
112
+ attr_accessor :premium
113
+
114
+ # Timestamp of premium figo Account expiry
115
+ # @return [DateTime]
116
+ attr_accessor :premium_expires_on
117
+
118
+ # Provider for premium subscription or Null of no subscription is active
119
+ # @return [String]
120
+ attr_accessor :premium_subscription
121
+
122
+ # Timestamp of figo Account registration
123
+ # @return [DateTime]
124
+ attr_accessor :join_date
80
125
  end
81
126
 
82
- # Object representing one bank account of the user.
127
+ # Object representing one bank account of the User
83
128
  class Account < Base
129
+ @dump_attributes = [:name, :owner, :auto_sync]
84
130
 
85
- # Internal figo Connect account ID.
131
+ # Internal figo Connect account ID
86
132
  # @return [String]
87
133
  attr_accessor :account_id
88
134
 
89
- # Internal figo Connect bank ID.
135
+ # Internal figo Connect bank ID
90
136
  # @return [String]
91
137
  attr_accessor :bank_id
92
138
 
93
- # Account name.
139
+ # Account name
94
140
  # @return [String]
95
141
  attr_accessor :name
96
142
 
97
- # Account owner.
143
+ # Account owner
98
144
  # @return [String]
99
145
  attr_accessor :owner
100
146
 
101
- # This flag indicates whether the account will be automatically synchronized.
147
+ # This flag indicates whether the account will be automatically synchronized
102
148
  # @return [Boolean]
103
149
  attr_accessor :auto_sync
104
150
 
105
- # Account number.
151
+ # Account number
106
152
  # @return [String]
107
153
  attr_accessor :account_number
108
154
 
109
- # Bank code.
155
+ # Bank code
110
156
  # @return [String]
111
157
  attr_accessor :bank_code
112
158
 
113
- # Bank name.
159
+ # Bank name
114
160
  # @return [String]
115
161
  attr_accessor :bank_name
116
162
 
117
- # Three-character currency code.
163
+ # Three-character currency code
118
164
  # @return [String]
119
165
  attr_accessor :currency
120
166
 
121
- # IBAN.
167
+ # IBAN
122
168
  # @return [String]
123
169
  attr_accessor :iban
124
170
 
125
- # BIC.
171
+ # BIC
126
172
  # @return [String]
127
173
  attr_accessor :bic
128
174
 
129
- # Account type. One of the constants of the `AccountType` object.
175
+ # Account type
130
176
  # @return [String]
131
177
  attr_accessor :type
132
178
 
133
- # Account icon URL.
179
+ # Account icon URL
134
180
  # @return [String]
135
181
  attr_accessor :icon
136
182
 
137
- # This flag indicates whether the balance of this account is added to the total balance of accounts.
138
- # @return [Boolean]
139
- attr_accessor :in_total_balance
183
+ # Account icon URLs for other resolutions
184
+ # @return [Hash]
185
+ attr_accessor :additional_icons
140
186
 
141
- # This flag indicates whether this account is only shown as preview for an unpaid premium plan.
187
+ # This flag indicates whether the balance of this account is added to the total balance of accounts
142
188
  # @return [Boolean]
143
- attr_accessor :preview
189
+ attr_accessor :in_total_balance
144
190
 
145
- # Synchronization status object.
191
+ # Synchronization status object
146
192
  # @return [SynchronizationStatus]
147
193
  attr_accessor :status
148
194
 
149
- # Request balance of this account.
150
- #
151
- # @return [AccountBalance] account balance object
152
- def balance
153
- response = @session.query_api("/rest/accounts/#{@account_id}/balance")
154
- return AccountBalance.new(@session, response)
155
- end
156
-
157
- # Request list of transactions of this account.
195
+ # Request list of transactions of this account
158
196
  #
159
197
  # @param since [String, Date] this parameter can either be a transaction ID or a date
160
198
  # @param start_id [String] do only return transactions which were booked after the start transaction ID
161
199
  # @param count [Integer] limit the number of returned transactions
162
- # @param include_pending [Boolean] this flag indicates whether pending transactions should be included
163
- # in the response; pending transactions are always included as a complete set, regardless of
200
+ # @param include_pending [Boolean] this flag indicates whether pending transactions should be included
201
+ # in the response; pending transactions are always included as a complete set, regardless of
164
202
  # the `since` parameter
165
203
  # @return [Array] an array of `Transaction` objects, one for each transaction of this account
166
204
  def transactions(since = nil, start_id = nil, count = 1000, include_pending = false)
167
- data = {}
168
- data["since"] = (since.is_a?(Date) ? since.to_s : since) unless since.nil?
169
- data["start_id"] = start_id unless start_id.nil?
170
- data["count"] = count.to_s
171
- data["include_pending"] = include_pending ? "1" : "0"
172
- response = @session.query_api("/rest/accounts/#{@account_id}/transactions?" + URI.encode_www_form(data))
173
- return response["transactions"].map {|transaction| Transaction.new(@session, transaction)}
205
+ @session.transactions @account_id, since, start_id, count, include_pending
174
206
  end
175
207
 
176
208
  # Request specific transaction.
177
209
  #
178
210
  # @param transaction_id [String] ID of the transaction to be retrieved
179
211
  # @return [Transaction] transaction object
180
- def transaction(transaction_id)
181
- response = @session.query_api("/rest/accounts/#{@account_id}/transactions/#{transaction_id}")
182
- return response.nil? ? nil : Transaction.new(@session, response)
212
+ def get_transaction(transaction_id)
213
+ @session.get_transaction @acount_id, transaction_id
214
+ end
215
+
216
+ # Retrieve list of payments on this account
217
+ #
218
+ # @return [Payment] an array of `Payment` objects, one for each payment
219
+ def payments
220
+ @session.payments @account_id
183
221
  end
184
222
 
223
+ # Retrieve specific payment on this account
224
+ #
225
+ # @param payment_id [String] ID of the notification to be retrieved
226
+ # @return [Payment] `Payment` object for the respective payment
227
+ def get_payment(payment_id)
228
+ @session.get_payment @account_id, payment_id
229
+ end
230
+
231
+ # Retrieve bank of this account
232
+ #
233
+ # @return [Bank] `Bank` object for the respective bank
234
+ def bank
235
+ @session.get_bank @bank_id
236
+ end
237
+
238
+ # Retrieve balance of this account
239
+ #
240
+ # @return [AccountBalance] `AccountBalance` of this account
241
+ def balance
242
+ @session.get_account_balance @account_id
243
+ end
185
244
  end
186
245
 
187
- # Object representing the balance of a certain bank account of the user.
246
+ # Object representing the balance of a certain bank account of the User
188
247
  class AccountBalance < Base
248
+ @dump_attributes = [:credit_line, :monthly_spending_limit]
189
249
 
190
- # Account balance or `nil` if the balance is not yet known.
250
+ # Account balance or `nil` if the balance is not yet known
191
251
  # @return [DecNum]
192
252
  attr_accessor :balance
193
253
 
194
- # Bank server timestamp of balance or `nil` if the balance is not yet known.
254
+ # Bank server timestamp of balance or `nil` if the balance is not yet known
195
255
  # @return [Date]
196
256
  attr_accessor :balance_date
197
257
 
@@ -199,129 +259,205 @@ module Figo
199
259
  # @return [DecNum]
200
260
  attr_accessor :credit_line
201
261
 
202
- # User-defined spending limit.
262
+ # User-defined spending limit
203
263
  # @return [DecNum]
204
264
  attr_accessor :monthly_spending_limit
205
265
 
206
- # Synchronization status object.
266
+ # Synchronization status object
207
267
  # @return [SynchronizationStatus]
208
268
  attr_accessor :status
269
+ end
270
+
271
+ # Object representing a bank, i.e. an connection to a bank
272
+ class Bank < Base
273
+ @dump_attributes = [:sepa_creditor_id]
209
274
 
275
+ # SEPA direct debit creditor ID
276
+ # @return [String]
277
+ attr_accessor :sepa_creditor_id
278
+
279
+ # This flag indicates whether the user has chosen to save the PIN on the figo Connect server
280
+ # @return [Boolean]
281
+ attr_accessor :save_pin
210
282
  end
211
283
 
212
- # Object representing one bank transaction on a certain bank account of the user.
284
+ # Object representing one bank transaction on a certain bank account of the User
213
285
  class Transaction < Base
286
+ @dump_attributes = []
214
287
 
215
- # Internal figo Connect transaction ID.
288
+ # Internal figo Connect transaction ID
216
289
  # @return [String]
217
290
  attr_accessor :transaction_id
218
291
 
219
- # Internal figo Connect account ID.
292
+ # Internal figo Connect account ID
220
293
  # @return [String]
221
294
  attr_accessor :account_id
222
295
 
223
- # Name of originator or recipient.
296
+ # Name of originator or recipient
224
297
  # @return [String]
225
298
  attr_accessor :name
226
299
 
227
- # Account number of originator or recipient.
300
+ # Account number of originator or recipient
228
301
  # @return [String]
229
302
  attr_accessor :account_number
230
303
 
231
- # Bank code of originator or recipient.
304
+ # Bank code of originator or recipient
232
305
  # @return [String]
233
306
  attr_accessor :bank_code
234
307
 
235
- # Bank name of originator or recipient.
308
+ # Bank name of originator or recipient
236
309
  # @return [String]
237
310
  attr_accessor :bank_name
238
311
 
239
- # Transaction amount.
312
+ # Transaction amount
240
313
  # @return [DecNum]
241
314
  attr_accessor :amount
242
315
 
243
- # Three-character currency code.
316
+ # Three-character currency code
244
317
  # @return [String]
245
318
  attr_accessor :currency
246
319
 
247
- # Booking date.
320
+ # Booking date
248
321
  # @return [Date]
249
322
  attr_accessor :booking_date
250
323
 
251
- # Value date.
324
+ # Value date
252
325
  # @return [Date]
253
326
  attr_accessor :value_date
254
327
 
255
- # Purpose text.
328
+ # Purpose text
256
329
  # @return [String]
257
330
  attr_accessor :purpose
258
331
 
259
- # Transaction type. One of the constants of the `TransactionType` object.
332
+ # Transaction type
260
333
  # @return [String]
261
334
  attr_accessor :type
262
335
 
263
- # Booking text.
336
+ # Booking text
264
337
  # @return [String]
265
338
  attr_accessor :booking_text
266
339
 
267
- # This flag indicates whether the transaction is booked or pending.
340
+ # This flag indicates whether the transaction is booked or pending
268
341
  # @return [Boolean]
269
342
  attr_accessor :booked
270
343
 
271
- # Internal creation timestamp on the figo Connect server.
344
+ # Internal creation timestamp on the figo Connect server
272
345
  # @return [DateTime]
273
346
  attr_accessor :creation_timestamp
274
347
 
275
- # Internal modification timestamp on the figo Connect server.
348
+ # Internal modification timestamp on the figo Connect server
276
349
  # @return [DateTime]
277
350
  attr_accessor :modification_timestamp
278
-
279
- # This flag indicates whether the transaction has already been marked as visited by the user.
280
- # @return [Boolean]
281
- attr_accessor :visited
282
-
283
351
  end
284
352
 
285
- # Object representing the bank server synchronization status.
353
+ # Object representing the bank server synchronization status
286
354
  class SynchronizationStatus < Base
355
+ @dump_attributes = []
287
356
 
288
- # Internal figo Connect status code.
357
+ # Internal figo Connect status code
289
358
  # @return [Integer]
290
359
  attr_accessor :code
291
360
 
292
- # Human-readable error message.
361
+ # Human-readable error message
293
362
  # @return [String]
294
363
  attr_accessor :message
295
364
 
296
- # Timestamp of last synchronization.
365
+ # Timestamp of last synchronization
297
366
  # @return [DateTime]
298
367
  attr_accessor :sync_timestamp
299
368
 
300
- # Timestamp of last successful synchronization.
369
+ # Timestamp of last successful synchronization
301
370
  # @return [DateTime]
302
371
  attr_accessor :success_timestamp
303
-
304
372
  end
305
373
 
306
- # Object representing a configured notification, e.g. a webhook or email hook.
374
+ # Object representing a configured notification, e.g. a webhook or email hook
307
375
  class Notification < Base
376
+ @dump_attributes = [:observe_key, :notify_uri, :state]
308
377
 
309
- # Internal figo Connect notification ID from the notification registration response.
378
+ # Internal figo Connect notification ID from the notification registration response
310
379
  # @return [String]
311
380
  attr_accessor :notification_id
312
381
 
313
- # One of the notification keys specified in the figo Connect API specification.
382
+ # One of the notification keys specified in the figo Connect API specification
314
383
  # @return [String]
315
384
  attr_accessor :observe_key
316
385
 
317
- # Notification messages will be sent to this URL.
386
+ # Notification messages will be sent to this URL
318
387
  # @return [String]
319
388
  attr_accessor :notify_uri
320
389
 
321
- # State similiar to sync and logon process. It will passed as POST payload for webhooks.
390
+ # State similiar to sync and logon process. It will passed as POST payload for webhooks
322
391
  # @return [String]
323
392
  attr_accessor :state
324
-
325
393
  end
326
394
 
395
+ # Object representing a Payment
396
+ class Payment < Base
397
+ @dump_attributes = [:type, :name, :account_number, :bank_code, :amount, :currency, :purpose]
398
+
399
+ # Internal figo Connect payment ID
400
+ # @return [String]
401
+ attr_accessor :payment_id
402
+
403
+ # Internal figo Connect account ID
404
+ # @return [String]
405
+ attr_accessor :account_id
406
+
407
+ # Payment type
408
+ # @return [String]
409
+ attr_accessor :type
410
+
411
+ # Name of creditor or debtor
412
+ # @return [String]
413
+ attr_accessor :name
414
+
415
+ # Account number of creditor or debtor
416
+ # @return [String]
417
+ attr_accessor :account_number
418
+
419
+ # Bank code of creditor or debtor
420
+ # @return [String]
421
+ attr_accessor :bank_code
422
+
423
+ # Bank name of creditor or debtor
424
+ # @return [String]
425
+ attr_accessor :bank_name
426
+
427
+ # Icon of creditor or debtor bank
428
+ # @return [String]
429
+ attr_accessor :bank_icon
430
+
431
+ # Icon of the creditor or debtor bank in other resolutions
432
+ # @return [Hash]
433
+ attr_accessor :bank_additional_icons
434
+
435
+ # Order amount
436
+ # @return [DecNum]
437
+ attr_accessor :amount
438
+
439
+ # Three-character currency code
440
+ # @return [String]
441
+ attr_accessor :currency
442
+
443
+ # Purpose text
444
+ # @return [String]
445
+ attr_accessor :purpose
446
+
447
+ # Timestamp of submission to the bank server
448
+ # @return [DateTime]
449
+ attr_accessor :submission_timestamp
450
+
451
+ # Internal creation timestamp on the figo Connect server
452
+ # @return [DateTime]
453
+ attr_accessor :creation_timestamp
454
+
455
+ # Internal modification timestamp on the figo Connect server
456
+ # @return [DateTime]
457
+ attr_accessor :modification_timestamp
458
+
459
+ # ID of the transaction corresponding to this payment. This field is only set if the payment has been matched to a transaction
460
+ # @return [String]
461
+ attr_accessor :transaction_id
462
+ end
327
463
  end