Class: Figo::Session

Inherits:
Object
  • Object
show all
Includes:
Figo
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

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.

Parameters:

  • access_token (String)

    the 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.

Parameters:

  • path (String)

    the URL path on the server

  • data (hash) (defaults to: nil)

    this optional object will be used as JSON-encoded POST content.

  • method (String) (defaults to: "GET")

    the HTTP method

Returns:

  • (Hash)

    JSON response



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