lib/travis/client/session.rb in travis-1.5.6.travis.329.4 vs lib/travis/client/session.rb in travis-1.5.6.travis.330.4
- old
+ new
@@ -15,19 +15,20 @@
module Travis
module Client
class Session
SSL_OPTIONS = { :ca_file => File.expand_path("../../cacert.pem", __FILE__) }
include Methods
- attr_reader :connection, :headers, :access_token, :instruments, :faraday_adapter, :agent_info
+ attr_reader :connection, :headers, :access_token, :instruments, :faraday_adapter, :agent_info, :ssl
def initialize(options = Travis::Client::ORG_URI)
@headers = {}
@cache = {}
@instruments = []
@agent_info = []
@config = nil
@faraday_adapter = defined?(Typhoeus) ? :typhoeus : :net_http
+ @ssl = SSL_OPTIONS
options = { :uri => options } unless options.respond_to? :each_pair
options.each_pair { |key, value| public_send("#{key}=", value) }
raise ArgumentError, "neither :uri nor :connection specified" unless connection
@@ -42,13 +43,18 @@
def agent_info=(info)
@agent_info = [info].flatten.freeze
set_user_agent
end
+ def ssl=(options)
+ @ssl = options.dup.freeze
+ self.uri = uri if uri
+ end
+
def uri=(uri)
clear_cache!
- self.connection = Faraday.new(:url => uri, :ssl => SSL_OPTIONS) do |faraday|
+ self.connection = Faraday.new(:url => uri, :ssl => ssl) do |faraday|
faraday.request :url_encoded
faraday.response :json
faraday.response :follow_redirects
faraday.response :raise_error
faraday.adapter(*faraday_adapter)
@@ -152,11 +158,14 @@
def put_raw(*args)
raw(:put, *args)
end
- def raw(verb, *args)
- instrumented(verb.to_s.upcase, *args) { connection.public_send(verb, *args).body }
+ def raw(verb, url, *args)
+ url = url.sub(/^\//, '')
+ result = instrumented(verb.to_s.upcase, url, *args) { connection.public_send(verb, url, *args) }
+ raise Travis::Client::Error, 'SSL error: could not verify peer' if result.status == 0
+ result.body
rescue Faraday::Error::ClientError => e
handle_error(e)
end
def inspect