Class: Figo::Connection

Inherits:
Object
  • Object
show all
Includes:
Figo
Defined in:
lib/figo.rb

Overview

Represents a non user-bound connection to the figo Connect API.

It’s main purpose is to let user login via OAuth 2.0.

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(client_id, client_secret, redirect_uri = nil, api_endpoint = $api_endpoint) ⇒ Connection

Create connection object with client credentials.

Parameters:

  • client_id (String)

    the client ID

  • client_secret (String)

    the client secret

  • redirect_uri (String) (defaults to: nil)

    optional redirect URI



46
47
48
49
50
51
52
# File 'lib/figo.rb', line 46

def initialize(client_id, client_secret, redirect_uri = nil, api_endpoint = $api_endpoint)
  @client_id = client_id
  @client_secret = client_secret
  @redirect_uri = redirect_uri
  @https = HTTPS.new("figo-#{client_id}", nil)
  @api_endpoint = api_endpoint
end

Instance Method Details

#query_api(path, data = nil) ⇒ Hash

Helper method for making a OAuth 2.0 request.

Parameters:

  • path (String)

    the URL path on the server

  • data (Hash) (defaults to: nil)

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

Returns:

  • (Hash)

    JSON response



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/figo.rb', line 59

def query_api(path, data = nil)
  uri = URI("https://#{@api_endpoint}#{path}")

  # Setup HTTP request.
  request = Net::HTTP::Post.new(path)
  request.basic_auth(@client_id, @client_secret)
  request["Accept"] = "application/json"
  request["Content-Type"] = "application/x-www-form-urlencoded"
  request["User-Agent"] =  "figo-ruby/1.4.2"
  request.body = URI.encode_www_form(data) unless data.nil?

  # Send HTTP request.
  response = @https.request(uri, request)

  # Evaluate HTTP response.
  return response.body == "" ? {} : JSON.parse(response.body)
end