Sha256: 79c05671508561ba82cbdf0e3bb32b28311abc3e7f108778cf4d746e4764bb2f

Contents?: true

Size: 1015 Bytes

Versions: 2

Compression:

Stored size: 1015 Bytes

Contents

# frozen_string_literal: true

require 'codat/base_model'
require 'codat/models/bank_statement'
require 'codat/models/metadata'

module Codat
  module Models
    # Bank statements for a given company. This endpoint will return an array of records and also
    # metadata (page size, page number and total results).
    class BankStatementList < BaseModel
      ENDPOINT = '/companies/:company_id/data/bankStatements'

      attr_reader :records, :metadata

      def self.for(company_id:, account_id:, page: 1)
        url = format_url(ENDPOINT, company_id: company_id.to_s.strip)

        result = get(url, accountId: account_id.to_s.strip, page: page.to_s.strip)

        return nil unless successful_response?(result)

        new(json: result.body)
      end

      def initialize(json:)
        super

        records = json.delete(:results) || []

        @records = records.map { |bank_statement| BankStatement.new(json: bank_statement) }

        @metadata = Metadata.new(json:)
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
codat-0.1.8 lib/codat/models/bank_statement_list.rb
codat-0.1.7 lib/codat/models/bank_statement_list.rb