Sha256: 115e6e5cd2dea885c2cb73ff20fec3ab2ed18ff5f4e7113e44cdc9606de59edd

Contents?: true

Size: 984 Bytes

Versions: 25

Compression:

Stored size: 984 Bytes

Contents

# frozen_string_literal: true

module Prefab
  class HttpConnection
    AUTH_USER = 'authuser'
    PROTO_HEADERS = {
      'Content-Type' => 'application/x-protobuf',
      'Accept' => 'application/x-protobuf',
      'X-PrefabCloud-Client-Version' => "prefab-cloud-ruby-#{Prefab::VERSION}"
    }.freeze

    def initialize(api_root, api_key)
      @api_root = api_root
      @api_key = api_key
    end

    def get(path)
      connection(PROTO_HEADERS).get(path)
    end

    def post(path, body)
      connection(PROTO_HEADERS).post(path, body.to_proto)
    end

    def connection(headers = {})
      if Faraday::VERSION[0].to_i >= 2
        Faraday.new(@api_root) do |conn|
          conn.request :authorization, :basic, AUTH_USER, @api_key

          conn.headers.merge!(headers)
        end
      else
        Faraday.new(@api_root) do |conn|
          conn.request :basic_auth, AUTH_USER, @api_key

          conn.headers.merge!(headers)
        end
      end
    end
  end
end

Version data entries

25 entries across 25 versions & 1 rubygems

Version Path
prefab-cloud-ruby-1.8.8.pre.1 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.7 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.6 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.5 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.4 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.3 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.2 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.1 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.8.0 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.7.2 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.7.1 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.7.0 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.6.2 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.6.1 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.6.0 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.5.1 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.6.0.pre2 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.6.0.pre1 lib/prefab/http_connection.rb
prefab-cloud-ruby-0 lib/prefab/http_connection.rb
prefab-cloud-ruby-1.5.0 lib/prefab/http_connection.rb