Sha256: 7240bf48928b8317c4cd5e8b10b645157101129cc76390f6cccb5b083e462d22

Contents?: true

Size: 1.05 KB

Versions: 3

Compression:

Stored size: 1.05 KB

Contents

# frozen_string_literal: true

module Jiminy
  module Reporting
    module CIProviders
      module CircleCI
        class APIRequest
          API_BASE = "https://circleci.com/api/v2/"

          CIRCLE_TOKEN_HEADER = "Circle-Token"

          def initialize(path)
            @url = URI.join(API_BASE, path)
          end

          def perform!
            Jiminy.logger.debug { "API request: #@url" }
            response
          end

          private

            attr_reader :url

            def response
              @_response ||= http.request(request)
            end

            def request
              @_request ||= Net::HTTP::Get.new(url).tap do |req|
                req[CIRCLE_TOKEN_HEADER] = Jiminy.config.circle_ci_api_token
              end
            end

            def http
              @_http ||= Net::HTTP.new(url.host, url.port).tap do |http_instance|
                http_instance.use_ssl = true
                http_instance.verify_mode = OpenSSL::SSL::VERIFY_NONE
              end
            end
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
jiminy-0.4.0 lib/jiminy/reporting/ci_providers/circle_ci/api_request.rb
jiminy-0.3.0 lib/jiminy/reporting/ci_providers/circle_ci/api_request.rb
jiminy-0.2.0 lib/jiminy/reporting/ci_providers/circle_ci/api_request.rb