module BitBucket::Connection
Constants
- ALLOWED_OPTIONS
Public Instance Methods
caching?()
click to toggle source
# File lib/bitbucket_rest_api/connection.rb, line 71 def caching? !@connection.nil? end
clear_cache()
click to toggle source
# File lib/bitbucket_rest_api/connection.rb, line 67 def clear_cache @connection = nil end
connection(options = {})
click to toggle source
Returns a Fraday::Connection object
# File lib/bitbucket_rest_api/connection.rb, line 90 def connection(options = {}) conn_options = default_options(options) clear_cache unless options.empty? puts "OPTIONS:#{conn_options.inspect}" if ENV['DEBUG'] @connection ||= Faraday.new(conn_options.merge(:builder => stack(options))) do |faraday| faraday.response :logger if ENV['DEBUG'] end end
default_middleware(options={})
click to toggle source
Default middleware stack that uses default adapter as specified at configuration stage.
# File lib/bitbucket_rest_api/connection.rb, line 40 def default_middleware(options={}) Proc.new do |builder| #builder.use BitBucket::Request::Jsonize builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded if client_id? && client_secret? builder.use FaradayMiddleware::OAuth, {consumer_key: client_id, consumer_secret: client_secret, token: oauth_token, token_secret: oauth_secret} end builder.use BitBucket::Request::BasicAuth, authentication if basic_authed? builder.use FaradayMiddleware::EncodeJson builder.use Faraday::Response::Logger if ENV['DEBUG'] unless options[:raw] builder.use BitBucket::Response::Mashify builder.use BitBucket::Response::Jsonize end builder.use BitBucket::Response::RaiseError builder.adapter adapter end end
default_options(options={})
click to toggle source
# File lib/bitbucket_rest_api/connection.rb, line 26 def default_options(options={}) { :headers => { USER_AGENT => user_agent }, :ssl => { :verify => false }, :url => options.fetch(:endpoint) { BitBucket.endpoint } }.merge(BitBucket.connection_options) .merge(options) end
stack(options={}, &block)
click to toggle source
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
# File lib/bitbucket_rest_api/connection.rb, line 78 def stack(options={}, &block) @stack ||= begin if block_given? Faraday::RackBuilder.new(&block) else Faraday::RackBuilder.new(&default_middleware(options)) end end end