lib/cmis/connection.rb in cmis-ruby-0.4.5 vs lib/cmis/connection.rb in cmis-ruby-0.4.6
- old
+ new
@@ -1,38 +1,31 @@
require 'cmis/connection/request_modifier'
require 'cmis/connection/response_parser'
require 'cmis/connection/url_resolver'
require 'cmis/version'
-require 'core_ext/hash/compact'
-require 'core_ext/hash/keys'
require 'faraday'
module CMIS
class Connection
def initialize(options)
options.symbolize_keys!
message = "option `service_url` must be set"
service_url = options[:service_url] or raise message
- adapter = (options[:adapter] || :net_http).to_sym
+ options[:adapter] ||= :net_http
- headers = {
- user_agent: "cmis-ruby/#{VERSION} [#{adapter}]"
- }.merge(options[:headers] || {})
- conn_opts = { headers: headers, ssl: options[:ssl] }.compact
-
- @http = Faraday.new(conn_opts) do |builder|
+ @http = Faraday.new(connection_options(options)) do |builder|
builder.use RequestModifier
builder.request :multipart
builder.request :url_encoded
if options[:username]
builder.basic_auth(options[:username], options[:password])
end
- builder.adapter adapter
+ builder.adapter options[:adapter].to_sym
builder.response :logger if options[:log_requests]
builder.use ResponseParser
end
@url_resolver = URLResolver.new(@http, service_url)
@@ -51,8 +44,20 @@
else
@http.get(url, params.merge(query), headers)
end
response.body
+ end
+
+ private
+
+ def connection_options(options)
+ headers = { user_agent: "cmis-ruby/#{VERSION} [#{options[:adapter]}]" }
+ headers.merge!(options[:headers]) if options[:headers]
+
+ conn_opts = { headers: headers }
+ conn_opts[:ssl] = options[:ssl] if options[:ssl]
+
+ conn_opts
end
end
end