class Nordigen::NordigenClient

Constants

BASE_URL

Attributes

agreement[R]
institution[R]
requisition[R]
secret_id[R]
secret_key[R]

Public Class Methods

new(secret_id:, secret_key:) click to toggle source
# File lib/nordigen-ruby.rb, line 22
def initialize(secret_id:, secret_key:)
    @secret_id = secret_id
    @secret_key = secret_key
    @institution = InstitutionsApi.new(client=self)
    @agreement = AgreementsApi.new(client=self)
    @requisition = RequisitionsApi.new(client=self)
end

Public Instance Methods

account(account_id) click to toggle source
# File lib/nordigen-ruby.rb, line 76
def account(account_id)
    # Create Account instance
    return AccountApi.new(client: self, account_id: account_id)
end
exchange_token(refresh_token) click to toggle source
# File lib/nordigen-ruby.rb, line 66
def exchange_token(refresh_token)
    # Exchange refresh token for access token
    payload = {"refresh": refresh_token}
    response = self.request.post("token/refresh/", payload).body
    @@headers["Authorization"] = "Bearer #{response.access}"
    request.headers = @@headers
    return response
end
generate_token() click to toggle source
# File lib/nordigen-ruby.rb, line 50
def generate_token
    # Generate new access & refresh token
    payload = {
        "secret_key": @secret_key,
        "secret_id": @secret_id
    }
    response = self.request.post("token/new/", payload)
    if !response.success?
        raise Exception.new response.body
    end

    @@headers["Authorization"] = "Bearer #{response.body.access}"
    request.headers = @@headers
    return response.body
end
get_token() click to toggle source
# File lib/nordigen-ruby.rb, line 45
def get_token
    # Get token
    return request.headers["Authorization"]
end
init_session(redirect_url:, institution_id:, reference_id:, max_historical_days: 90) click to toggle source
# File lib/nordigen-ruby.rb, line 81
def init_session(redirect_url:, institution_id:, reference_id:, max_historical_days: 90)
    # Factory method that creates authorization in a specific institution
    # and are responsible for the following steps:
    #   * Creates agreement
    #   * Creates requisiton

    # Create agreement
    new_agreement = @agreement.create_agreement(
        institution_id: institution_id,
        max_historical_days: max_historical_days
    )
    # Create requisition
    new_requsition = @requisition.create_requisition(
        redirect_url: redirect_url,
        reference: reference_id,
        institution_id: institution_id
)

    return new_requsition
end
request() click to toggle source
# File lib/nordigen-ruby.rb, line 30
def request
    # HTTP client request
    @request ||= Faraday.new do |conn|
        conn.url_prefix = BASE_URL
        conn.headers = @@headers
        conn.request :json
        conn.response :json, parser_options: { object_class: OpenStruct }
    end
end
set_token(access_token) click to toggle source
# File lib/nordigen-ruby.rb, line 40
def set_token(access_token)
    # Use existing token
    @@headers["Authorization"] = "Bearer #{access_token}"
end