Sha256: 214f3d94beca4414c4f11d7efa79a23dca291141697d12664e622771fa82fafc

Contents?: true

Size: 1.28 KB

Versions: 2

Compression:

Stored size: 1.28 KB

Contents

require 'faraday_middleware'
require 'faraday/response/raise_octokit_error'

module Octokit
  # @private
  module Connection
    private

    def connection(authenticate=true, raw=false, version=3, force_urlencoded=false)
      case version
      when 3
        url = Octokit.api_endpoint
      end

      options = {
        :proxy => proxy,
        :ssl => { :verify => false },
        :url => url,
      }

      options.merge!(:params => {:access_token => oauth_token}) if oauthed? && !authenticated?
      options.merge!(:params => unauthed_rate_limit_params) if !oauthed? && !authenticated? && unauthed_rate_limited?

      # TODO: Don't build on every request
      connection = Faraday.new(options) do |builder|
        if version >= 3 && !force_urlencoded
          builder.request :json
        else
          builder.request :url_encoded
        end

        builder.use Faraday::Response::RaiseOctokitError

        unless raw
          builder.use FaradayMiddleware::Mashify
          builder.use FaradayMiddleware::ParseJson
        end

        faraday_config_block.call(builder) if faraday_config_block

        builder.adapter *adapter
      end

      connection.basic_auth authentication[:login], authentication[:password] if authenticate and authenticated?
      connection
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
octokit-1.17.1 lib/octokit/connection.rb
octokit-1.17.0 lib/octokit/connection.rb