summaryrefslogtreecommitdiff
path: root/lib/bulk_imports/groups/extractors/subgroups_extractor.rb
blob: b01fb6f68ac69369f2dcf1dd6857177db2a39e7f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# frozen_string_literal: true

module BulkImports
  module Groups
    module Extractors
      class SubgroupsExtractor
        def initialize(*args); end

        def extract(context)
          encoded_parent_path = ERB::Util.url_encode(context.entity.source_full_path)

          response = http_client(context.configuration)
            .each_page(:get, "groups/#{encoded_parent_path}/subgroups")
            .flat_map(&:itself)

          BulkImports::Pipeline::ExtractedData.new(data: response)
        end

        private

        def http_client(configuration)
          @http_client ||= BulkImports::Clients::Http.new(
            uri: configuration.url,
            token: configuration.access_token,
            per_page: 100
          )
        end
      end
    end
  end
end