Class: Figo::Session
- Inherits:
-
Object
- Object
- Figo::Session
- Defined in:
- lib/figo.rb
Overview
Represents a user-bound connection to the figo Connect API and allows access to the user’s data.
Instance Method Summary collapse
-
#accounts ⇒ Array
Retrieve all accounts.
-
#add_notification(notification) ⇒ Notification
Register a new notification.
-
#add_payment(payment) ⇒ Payment
Create new payment.
-
#get_account(account_id) ⇒ Account
Retrieve specific account.
-
#get_account_balance(account_id) ⇒ AccountBalance
Retrieve balance of an account.
-
#get_bank(bank_id) ⇒ Bank
Retrieve specific bank.
-
#get_notification(notification_id) ⇒ Notification
Retrieve specific notification.
-
#get_payment(account_id, payment_id) ⇒ Payment
Retrieve specific payment.
-
#get_transaction(account_id, transaction_id) ⇒ Transaction
Retrieve a specific transaction.
-
#initialize(access_token) ⇒ Session
constructor
Create session object with access token.
-
#modify_account(account) ⇒ Account
Modify specific account.
-
#modify_account_balance(account_id, account_balance) ⇒ AccountBalance
Modify balance or account limits.
-
#modify_bank(bank) ⇒ Bank
Modify bank.
-
#modify_notification(notification) ⇒ Notification
Modify notification.
-
#modify_payment(payment) ⇒ Payment
Modify payment.
-
#modify_user(user) ⇒ User
Modify the current user.
-
#notifications ⇒ Notification
Retrieve list of registered notifications.
-
#payments(account_id = nil) ⇒ Payment
Retrieve list of all payments (on all accounts or one).
-
#query_api(path, data = nil, method = "GET") ⇒ Hash
Helper method for making a REST request.
-
#query_api_object(type, path, data = nil, method = "GET", array_name = nil) ⇒ Object
:nodoc:.
-
#remove_account(account) ⇒ Object
Remove specific account.
-
#remove_bank_pin(bank) ⇒ nil
Remove stored PIN from bank.
-
#remove_notification(notification) ⇒ Object
Unregister notification.
-
#remove_payment(payment) ⇒ Object
Remove payment.
-
#remove_user ⇒ Object
Remove the current user Note: this has immidiate effect and you wont be able to interact with the user after this call.
-
#submit_payment(payment, tan_scheme_id, state, redirect_uri = nil) ⇒ String
Submit payment.
-
#sync_url(redirect_uri, state, if_not_synced_since = 0) ⇒ String
Retrieve the URL a user should open in the web browser to start the synchronization process.
-
#transactions(account_id = nil, since = nil, count = 1000, offset = 0, include_pending = false) ⇒ Array
Retrieve list of transactions (on all or a specific account).
-
#user ⇒ User
Retrieve current User.
Constructor Details
Instance Method Details
#accounts ⇒ Array
Retrieve all accounts
291 292 293 |
# File 'lib/figo.rb', line 291 def accounts query_api_object Account, "/rest/accounts", nil, "GET", "accounts" end |
#add_notification(notification) ⇒ Notification
Register a new notification.
416 417 418 |
# File 'lib/figo.rb', line 416 def add_notification(notification) query_api_object Notification, "/rest/notifications", notification.dump(), "POST" end |
#add_payment(payment) ⇒ Payment
Create new payment
456 457 458 |
# File 'lib/figo.rb', line 456 def add_payment(payment) query_api_object Payment, "/rest/accounts/#{payment.account_id}/payments", payment.dump(), "POST" end |
#get_account(account_id) ⇒ Account
Retrieve specific account.
299 300 301 |
# File 'lib/figo.rb', line 299 def get_account(account_id) query_api_object Account, "/rest/accounts/#{account_id}" end |
#get_account_balance(account_id) ⇒ AccountBalance
Retrieve balance of an account.
321 322 323 |
# File 'lib/figo.rb', line 321 def get_account_balance(account_id) query_api_object AccountBalance, "/rest/accounts/#{account_id}/balance" end |
#get_bank(bank_id) ⇒ Bank
Retrieve specific bank
337 338 339 |
# File 'lib/figo.rb', line 337 def get_bank(bank_id) query_api_object Bank, "/rest/banks/#{bank_id}" end |
#get_notification(notification_id) ⇒ Notification
Retrieve specific notification.
408 409 410 |
# File 'lib/figo.rb', line 408 def get_notification(notification_id) query_api_object Notification, "/rest/notifications/#{notification_id}" end |
#get_payment(account_id, payment_id) ⇒ Payment
Retrieve specific payment.
448 449 450 |
# File 'lib/figo.rb', line 448 def get_payment(account_id, payment_id) query_api_object Payment, "/rest/accounts/#{account_id}/payments/#{payment_id}" end |
#get_transaction(account_id, transaction_id) ⇒ Transaction
Retrieve a specific transaction
379 380 381 |
# File 'lib/figo.rb', line 379 def get_transaction(account_id, transaction_id) query_api_object Transaction, "/rest/accounts/#{account_id}/transactions/#{transaction_id}" end |
#modify_account(account) ⇒ Account
Modify specific account
307 308 309 |
# File 'lib/figo.rb', line 307 def modify_account(account) query_api_object Account, "/rest/accounts/#{account.account_id}", account.dump(), "PUT" end |
#modify_account_balance(account_id, account_balance) ⇒ AccountBalance
Modify balance or account limits
330 331 332 |
# File 'lib/figo.rb', line 330 def modify_account_balance(account_id, account_balance) query_api_object AccountBalance, "/rest/accounts/#{account_id}/balance", account_balance.dump(), "PUT" end |
#modify_bank(bank) ⇒ Bank
Modify bank
345 346 347 |
# File 'lib/figo.rb', line 345 def modify_bank(bank) query_api_object Bank, "/rest/banks/#{bank.bank_id}", bank.dump(), "PUT" end |
#modify_notification(notification) ⇒ Notification
Modify notification.
424 425 426 |
# File 'lib/figo.rb', line 424 def modify_notification(notification) query_api_object Notification, "/rest/notifications/#{notification.notification_id}", notification.dump(), "PUT" end |
#modify_payment(payment) ⇒ Payment
Modify payment
464 465 466 |
# File 'lib/figo.rb', line 464 def modify_payment(payment) query_api_object Payment, "/rest/accounts/#{payment.account_id}/payments/#{payment.payment_id}", payment.dump(), "PUT" end |
#modify_user(user) ⇒ User
Modify the current user
278 279 280 |
# File 'lib/figo.rb', line 278 def modify_user(user) query_api_object User, "/rest/user", user.dump(), "PUT" end |
#notifications ⇒ Notification
Retrieve list of registered notifications.
400 401 402 |
# File 'lib/figo.rb', line 400 def notifications query_api_object Notification, "/rest/notifications", nil, "GET", "notifications" end |
#payments(account_id = nil) ⇒ Payment
Retrieve list of all payments (on all accounts or one)
439 440 441 |
# File 'lib/figo.rb', line 439 def payments(account_id = nil) query_api_object Payment, account_id.nil? ? "/rest/payments" : "/rest/accounts/#{account_id}/payments", nil, "GET", "payments" end |
#query_api(path, data = nil, method = "GET") ⇒ Hash
Helper method for making a REST request.
230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 |
# File 'lib/figo.rb', line 230 def query_api(path, data=nil, method="GET") # :nodoc: uri = URI("https://#{$api_endpoint}#{path}") # Setup HTTP request. request = case method when "POST" Net::HTTP::Post.new(path) when "PUT" Net::HTTP::Put.new(path) when "DELETE" Net::HTTP::Delete.new(path) else Net::HTTP::Get.new(path) end request["Authorization"] = "Bearer #{@access_token}" request["Accept"] = "application/json" request["Content-Type"] = "application/json" request["User-Agent"] = "ruby-figo" request.body = JSON.generate(data) unless data.nil? # Send HTTP request. response = @https.request(uri, request) # Evaluate HTTP response. return nil if response.nil? return nil if response.body.nil? return response.body == "" ? nil : JSON.parse(response.body) end |
#query_api_object(type, path, data = nil, method = "GET", array_name = nil) ⇒ Object
:nodoc:
260 261 262 263 264 265 |
# File 'lib/figo.rb', line 260 def query_api_object(type, path, data=nil, method="GET", array_name=nil) # :nodoc: response = query_api path, data, method return nil if response.nil? return type.new(self, response) if array_name.nil? return response[array_name].map {|entry| type.new(self, entry)} end |
#remove_account(account) ⇒ Object
Remove specific account
314 315 316 |
# File 'lib/figo.rb', line 314 def remove_account(account) query_api account.is_a?(String) ? "/rest/accounts/#{account}" : "/rest/accounts/#{account.account_id}", nil, "DELETE" end |
#remove_bank_pin(bank) ⇒ nil
Remove stored PIN from bank
353 354 355 |
# File 'lib/figo.rb', line 353 def remove_bank_pin(bank) query_app bank.is_a?(String) ? "/rest/banks/#{bank}/submit": "/rest/banks/#{bank.bank_id}/submit", nil, "POST" end |
#remove_notification(notification) ⇒ Object
Unregister notification.
431 432 433 |
# File 'lib/figo.rb', line 431 def remove_notification(notification) query_api notification.is_a?(String) ? "/rest/notifications/#{notification}" : "/rest/notifications/#{notification.notification_id}", nil, "DELETE" end |
#remove_payment(payment) ⇒ Object
Remove payment
485 486 487 |
# File 'lib/figo.rb', line 485 def remove_payment(payment) query_api "/rest/accounts/#{payment.account_id}/payments/#{payment.payment_id}", nil, "DELETE" end |
#remove_user ⇒ Object
Remove the current user Note: this has immidiate effect and you wont be able to interact with the user after this call
284 285 286 |
# File 'lib/figo.rb', line 284 def remove_user query_api "/rest/user", nil, "DELETE" end |
#submit_payment(payment, tan_scheme_id, state, redirect_uri = nil) ⇒ String
Submit payment
474 475 476 477 478 479 480 |
# File 'lib/figo.rb', line 474 def submit_payment(payment, tan_scheme_id, state, redirect_uri = nil) params = {"tan_scheme_id" => tan_scheme_id, "state" => state} params['redirect_uri'] = redirect_uri unless redirect_uri.nil? response = query_api "/rest/accounts/#{payment.account_id}/payments/#{payment.payment_id}/submit", params, "POST" return "https://#{$api_endpoint}/task/start?id=#{response["task_token"]}" end |
#sync_url(redirect_uri, state, if_not_synced_since = 0) ⇒ String
Retrieve the URL a user should open in the web browser to start the synchronization process.
392 393 394 395 |
# File 'lib/figo.rb', line 392 def sync_url(redirect_uri, state, if_not_synced_since = 0) response = query_api "/rest/sync", {"redirect_uri" => redirect_uri, "state" => state, "if_not_synced_since" => if_not_synced_since}, "POST" return "https://#{$api_endpoint}/task/start?id=#{response["task_token"]}" end |
#transactions(account_id = nil, since = nil, count = 1000, offset = 0, include_pending = false) ⇒ Array
Retrieve list of transactions (on all or a specific account)
367 368 369 370 371 372 |
# File 'lib/figo.rb', line 367 def transactions(account_id = nil, since = nil, count = 1000, offset = 0, include_pending = false) data = {"count" => count.to_s, "offset" => offset.to_s, "include_pending" => include_pending ? "1" : "0"} data["since"] = ((since.is_a?(Date) ? since.to_s : since) unless since.nil?) query_api_object Transaction, (account_id.nil? ? "/rest/transactions?" : "/rest/accounts/#{account_id}/transactions?") + URI.encode_www_form(data), nil, "GET", "transactions" end |