Welcome to mirror list, hosted at ThFree Co, Russian Federation.

pagination_parser.rb « sentry_client « error_tracking « lib - gitlab.com/gitlab-org/gitlab-foss.git - Unnamed repository; edit this file 'description' to name the repository.
summaryrefslogtreecommitdiff
blob: 090707c21abf986299a08e1d2393242e7f21bad2 (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
# frozen_string_literal: true

module ErrorTracking
  class SentryClient
    module PaginationParser
      PATTERN = /rel="(?<direction>\w+)";\sresults="(?<results>\w+)";\scursor="(?<cursor>.+)"/

      def self.parse(headers)
        links = headers['link'].to_s.split(',')

        links.map { |link| parse_link(link) }.compact.to_h
      end

      def self.parse_link(link)
        match = link.match(PATTERN)

        return unless match
        return if match['results'] != "true"

        [match['direction'], { 'cursor' => match['cursor'] }]
      end
      private_class_method :parse_link
    end
  end
end