Sha256: 35e6ee06600861b016ca517d1e9105c3024c8c4917b8db84fc30369eba2a6707
Contents?: true
Size: 949 Bytes
Versions: 2
Compression:
Stored size: 949 Bytes
Contents
# frozen_string_literal: true require_relative '../response/investors_response' module ONEAccess module Request class InvestorsRequestHandler def initialize(url:, limit: PAGE_SIZE) @url = url @limit = limit end def each offset = 0 loop do http_response = Http::HttpClient.get(url, build_params(offset)) response = Response::InvestorsResponse.from_json(http_response.body) response&.data&.each do |investor| yield investor end break unless more_records?(response.meta) offset += 1 end end private PAGE_SIZE = 100 attr_reader :url attr_reader :limit def build_params(offset) { limit: limit, offset: offset, } end def more_records?(meta) meta.offset < (meta.total / meta.limit).ceil - 1 end end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
oneaccess-1.3.1 | lib/oneaccess/request/investors_request_handler.rb |
oneaccess-1.3.0 | lib/oneaccess/request/investors_request_handler.rb |