Sha256: f04d4095b2e6556e6ab36e2733c04e4792ed3e9707307a220705da1c40a8dd9f

Contents?: true

Size: 1016 Bytes

Versions: 5

Compression:

Stored size: 1016 Bytes

Contents

# frozen_string_literal: true

module Tikkie
  module Api
    module Responses
      # Response when requesting payment requests (list).
      class PaymentRequests < Base
        include Enumerable
        include Tikkie::Api::Responses::Pagination

        def initialize(response, options = {})
          super(response)

          @offset = options[:offset]
          @limit = options[:limit]
          @total_elements = data[:totalElements]
          @elements = payment_requests.count
        end

        def each(&block)
          payment_requests.each(&block)
        end

        private

        def payment_requests
          @payment_requests ||= begin
            payment_requests = []

            if data[:paymentRequests]
              data[:paymentRequests].each do |payment_request|
                payment_requests << Tikkie::Api::Responses::PaymentRequest.new(payment_request)
              end
            end

            payment_requests
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
tikkie-api-0.2.2 lib/tikkie/api/responses/payment_requests.rb
tikkie-api-0.2.1 lib/tikkie/api/responses/payment_requests.rb
tikkie-api-0.2.0 lib/tikkie/api/responses/payment_requests.rb
tikkie-api-0.1.1 lib/tikkie/api/responses/payment_requests.rb
tikkie-api-0.1.0 lib/tikkie/api/responses/payment_requests.rb