Sha256: 251a9fcb66d326d90c45ccffb2905c6b00937b0d01e8c298117a7ffd58ec8eb6

Contents?: true

Size: 1.51 KB

Versions: 10

Compression:

Stored size: 1.51 KB

Contents

# frozen_string_literal: true

module HackerOne
  module Client
    module Incremental
      class Activities
        include ResourceHelper

        attr_reader :program, :updated_at_after, :page_size

        def initialize(program, updated_at_after: nil, page_size: 25)
          @program = program
          @updated_at_after = updated_at_after
          @page_size = page_size
        end

        def traverse
          loop do
            activities.each do |activity|
              yield activity
            end

            break if next_page.nil?
          end
        end

        def activities
          @activities ||= current_page[:data].map do |activity_json|
            HackerOne::Client::Activities.build activity_json
          end
        end

        def next_page
          return nil unless next_cursor.present?

          # Set cursor to next page
          @updated_at_after = next_cursor

          # Remove memoization
          @current_page = nil
          @activities = nil

          # Fetch new page
          current_page

          activities
        end

        private

        def current_page
          @current_page ||= make_get_request(
            "incremental/activities",
            extract_data: false,
            params: {
              handle: program.handle,
              first: page_size,
              updated_at_after: updated_at_after
            }
          )
        end

        def next_cursor
          current_page[:meta][:max_updated_at]
        end
      end
    end
  end
end

Version data entries

10 entries across 10 versions & 1 rubygems

Version Path
hackerone-client-0.23.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.22.1 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.22.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.21.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.20.1 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.20.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.19.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.18.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.17.0 lib/hackerone/client/incremental/activities.rb
hackerone-client-0.16.0 lib/hackerone/client/incremental/activities.rb