Class: UkrsibAPI::Resource
- Inherits:
-
Object
- Object
- UkrsibAPI::Resource
- Defined in:
- lib/ukrsib_api/resource.rb
Overview
internal
Direct Known Subclasses
UkrsibAPI::Resources::BalanceResource, UkrsibAPI::Resources::StatementsV3Resource
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#form_query(date_from:, date_to:, accounts:, first_result: 0, max_result: 100) ⇒ Hash
Builds the query parameters hash for API requests.
-
#initialize(client) ⇒ Resource
constructor
A new instance of Resource.
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
#client ⇒ Object (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:
-
**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.
-
-
**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.
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 |