Class: Figo::Session
Overview
Represents a user-bound connection to the figo Connect API and allows access to the user’s data.
Instance Method Summary collapse
-
#initialize(access_token, api_endpoint = $api_endpoint) ⇒ Session
constructor
Create session object with access token.
-
#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:.
Methods included from Figo
#account_sort_order, #accounts, #add_account, #add_notification, #add_payment, #cancel_task, #create_user, #credential_login, #delete_transaction, #find_bank, #get_account, #get_account_balance, #get_account_standing_orders, #get_bank, #get_notification, #get_payment, #get_payment_proposals, #get_securities, #get_security, #get_standing_order, #get_standing_orders, #get_supported_payment_services, #get_sync_url, #get_task_state, #get_transaction, #login_url, #modify_account, #modify_account_balance, #modify_bank, #modify_notification, #modify_payment, #modify_securities, #modify_security, #modify_transaction, #modify_transactions, #modify_user, #notifications, #obtain_access_token, #payments, #remove_account, #remove_bank_pin, #remove_notification, #remove_payment, #remove_user, #resend_verification, #revoke_token, #start_task, #submit_payment, #sync_url, #transactions, #user
Constructor Details
#initialize(access_token, api_endpoint = $api_endpoint) ⇒ Session
Create session object with access token.
118 119 120 121 122 |
# File 'lib/figo.rb', line 118 def initialize(access_token, api_endpoint = $api_endpoint) @access_token = access_token @https = HTTPS.new("figo-#{access_token}", nil) @api_endpoint = api_endpoint end |
Instance Method Details
#query_api(path, data = nil, method = "GET") ⇒ Hash
Helper method for making a REST request.
130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 |
# File 'lib/figo.rb', line 130 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"] = "figo-ruby/1.4.2" 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:
161 162 163 164 165 166 |
# File 'lib/figo.rb', line 161 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 |