lib/gems/connection.rb in gems-0.1.0 vs lib/gems/connection.rb in gems-0.2.0
- old
+ new
@@ -1,22 +1,23 @@
require 'faraday_middleware'
module Gems
module Connection
- def connection(format=format)
+ def connection(content_length=nil, content_type=nil, format=foramt)
options = {
:headers => {
:user_agent => user_agent,
},
:ssl => {:verify => false},
- :url => 'https://rubygems.org',
+ :url => host,
}
+ options[:headers].merge!({:content_length => content_length}) if content_length
+ options[:headers].merge!({:content_type => content_type}) if content_type
options[:headers].merge!({:authorization => key}) if key
connection = Faraday.new(options) do |connection|
- connection.use Faraday::Request::UrlEncoded
- connection.use Faraday::Response::Mashify
+ connection.use Faraday::Request::UrlEncoded unless content_type
case format.to_s.downcase
when 'json'
connection.use Faraday::Response::ParseJson
when 'marshal'
connection.use Faraday::Response::ParseMarshal