Class: PbAPI::Resource
- Inherits:
-
Object
- Object
- PbAPI::Resource
- Defined in:
- lib/pb_api/resource.rb
Overview
internal
Direct Known Subclasses
PbAPI::Resources::BalanceResource, PbAPI::Resources::TransactionResource
Constant Summary collapse
- DATE_FORMAT_STRING =
"%d-%m-%Y"
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
-
#form_query(start_date: nil, end_date: nil, account: nil, follow_id: nil, limit: 20) ⇒ 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.
10 11 12 |
# File 'lib/pb_api/resource.rb', line 10 def initialize(client) @client = client end |
Instance Attribute Details
#client ⇒ Object (readonly)
Returns the value of attribute client.
8 9 10 |
# File 'lib/pb_api/resource.rb', line 8 def client @client end |
Instance Method Details
#form_query(start_date: nil, end_date: nil, account: nil, follow_id: nil, limit: 20) ⇒ 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.
40 41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/pb_api/resource.rb', line 40 def form_query(start_date: nil, end_date: nil, account: nil, follow_id: nil, limit: 20) params = {} # For date interval endpoints, only add date parameters if provided. params[:startDate] = start_date.strftime(DATE_FORMAT_STRING) if start_date params[:endDate] = end_date.strftime(DATE_FORMAT_STRING) if end_date # Account number is expected under the key :acc by the API. params[:acc] = account if account # Pagination parameter. params[:followId] = follow_id if follow_id # Set limit for results per page. params[:limit] = limit params end |