Sha256: 8b4dcb3263868f24996c9c034298a4c37cb918886eb0e40151a0d3df699ee6a5

Contents?: true

Size: 723 Bytes

Versions: 26

Compression:

Stored size: 723 Bytes

Contents

# frozen_string_literal: true

module Pennyworth
  module Integrations
    module GitHub
      # Represents a generic GitHub API response.
      class Response
        def initialize raw
          @raw = raw
        end

        def next_page = page("next")

        def last_page = page("last")

        def records = success? ? JSON(raw.body, symbolize_names: true) : []

        def success? = raw.status.success?

        private

        attr_reader :raw

        def page reference
          links.find { |link| link.include? reference }
               .then { |link| String(link)[/page=(?<page>\d+)/, :page].to_i }
        end

        def links = String(raw.headers["Link"]).split(", ")
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
pennyworth-13.8.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.7.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.6.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.5.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.4.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.3.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.2.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.1.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.0.1 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-13.0.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.3.1 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.3.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.2.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.1.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.0.2 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.0.1 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-12.0.0 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-11.2.2 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-11.2.1 lib/pennyworth/integrations/git_hub/response.rb
pennyworth-11.2.0 lib/pennyworth/integrations/git_hub/response.rb