Class: PbAPI::Resource

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

Overview

internal

Constant Summary collapse

DATE_FORMAT_STRING =
"%d-%m-%Y"

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#clientObject (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:

  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) (defaults to: nil)

    the starting date (required for date interval endpoints)

  • end_date (Date, nil) (defaults to: nil)

    the ending date (optional)

  • account (String, nil) (defaults to: nil)

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

  • follow_id (String, nil) (defaults to: nil)

    identifier for the next page of results (pagination)

  • limit (Integer) (defaults to: 20)

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

Returns:

  • (Hash)

    the query parameters hash to be appended to the request URL



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]       =  if 
  # Pagination parameter.
  params[:followId]  = follow_id if follow_id
  # Set limit for results per page.
  params[:limit]     = limit
  params
end