lib/gems/connection.rb in gems-0.0.4 vs lib/gems/connection.rb in gems-0.0.5

- old
+ new

@@ -3,28 +3,32 @@ module Gems module Connection def connection(format=format) options = { :headers => { - 'User-Agent' => user_agent, + :user_agent => user_agent, }, :ssl => {:verify => false}, :url => 'https://rubygems.org', } - Faraday.new(options) do |connection| + options[:headers].merge!({:authorization => key}) if key + + connection = Faraday.new(options) do |connection| connection.use Faraday::Request::UrlEncoded - connection.use Faraday::Response::RaiseError connection.use Faraday::Response::Mashify - case format.to_sym - when :json + case format.to_s.downcase + when 'json' connection.use Faraday::Response::ParseJson - when :marshal + when 'marshal' connection.use Faraday::Response::ParseMarshal - when :xml + 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