Class: UkrsibAPI::Resource

Inherits:
Object
  • Object
show all
Defined in:
lib/ukrsib_api/resource.rb

Overview

internal

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Resource

Returns a new instance of Resource.



9
10
11
# File 'lib/ukrsib_api/resource.rb', line 9

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



7
8
9
# File 'lib/ukrsib_api/resource.rb', line 7

def client
  @client
end

Instance Method Details

#form_query(date_from:, date_to:, accounts:, first_result: 0, max_result: 100) ⇒ Hash

Builds the query parameters hash for API requests.

This method generates a hash of query parameters based on the provided options. It is designed to work with multiple endpoints:

  1. **Date Interval Endpoints** (e.g., balances or transactions):

    • Requires :start_date (formatted as DD-MM-YYYY)

    • Optionally includes :end_date (formatted as DD-MM-YYYY)

    • :acc (account IBAN) is optional; if omitted, data for all active accounts are returned.

  2. **Interim/Final Endpoints** (for getting partial or final data):

    • Date parameters are omitted.

    • Only :acc, :follow_id, and :limit are used.

Additionally, if the API response contains:

  • “exist_next_page” as true, then the “next_page_id” value should be passed in subsequent requests using the :follow_id parameter.

Parameters:

  • start_date (Date, nil)

    the starting date (required for date interval endpoints)

  • end_date (Date, nil)

    the ending date (optional)

  • account (String, nil)

    the account number (IBAN); mapped to :acc in the query

  • follow_id (String, nil)

    identifier for the next page of results (pagination)

  • limit (Integer)

    number of records per page (default: 20, maximum recommended: 100)

Returns:

  • (Hash)

    the query parameters hash to be appended to the request URL



39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/ukrsib_api/resource.rb', line 39

def form_query(date_from:, date_to:, accounts:, first_result: 0, max_result: 100)
  params = {}
  # For date interval endpoints, only add date parameters if provided.
  params[:dateFrom] = date_from.to_time.to_i * 1000 if date_from
  params[:dateTo]   = date_to.to_time.to_i * 1000 if date_to
  # Account number is expected under the key :acc by the API.
  params[:accounts] = accounts.join(",") if accounts.any?

  # Set limit for results per page.
  params[:firstResult] = first_result
  params[:maxResult] = max_result
  params
end