Sha256: 04d6c48f45915988eb8b6c1e15a5917e04e1c56006111dabbe38a3c8ed3e4b13

Contents?: true

Size: 983 Bytes

Versions: 3

Compression:

Stored size: 983 Bytes

Contents

require 'faraday_middleware'

module Gems
  module Connection
    def connection(format=format)
      options = {
        :headers => {
          :user_agent => user_agent,
        },
        :ssl => {:verify => false},
        :url => 'https://rubygems.org',
      }

      options[:headers].merge!({:authorization => key}) if key

      connection = Faraday.new(options) do |connection|
        connection.use Faraday::Request::UrlEncoded
        connection.use Faraday::Response::Mashify
        case format.to_s.downcase
        when 'json'
          connection.use Faraday::Response::ParseJson
        when 'marshal'
          connection.use Faraday::Response::ParseMarshal
        when 'xml'
          connection.use Faraday::Response::ParseXml
        end
        connection.use Faraday::Response::RaiseError
        connection.adapter Faraday.default_adapter
      end
      connection.basic_auth username, password if username && password
      connection
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
gems-0.0.7 lib/gems/connection.rb
gems-0.0.6 lib/gems/connection.rb
gems-0.0.5 lib/gems/connection.rb