Module: BitBucket::Connection
- Included in:
- API
- Defined in:
- lib/bitbucket_rest_api/connection.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
%i[ headers url params request ssl ].freeze
Class Method Summary collapse
- .caching? ⇒ Boolean
- .clear_cache ⇒ Object
-
.connection(options = {}) ⇒ Object
Returns a Fraday::Connection object.
-
.default_middleware(options = {}) ⇒ Object
Default middleware stack that uses default adapter as specified at configuration stage.
- .default_options(options = {}) ⇒ Object
-
.stack(options = {}, &block) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
Class Method Details
.caching? ⇒ Boolean
68 69 70 |
# File 'lib/bitbucket_rest_api/connection.rb', line 68 def caching? !@connection.nil? end |
.clear_cache ⇒ Object
64 65 66 |
# File 'lib/bitbucket_rest_api/connection.rb', line 64 def clear_cache @connection = nil end |
.connection(options = {}) ⇒ Object
Returns a Fraday::Connection object
87 88 89 90 91 92 93 94 95 |
# File 'lib/bitbucket_rest_api/connection.rb', line 87 def connection( = {}) = () clear_cache unless .empty? puts "OPTIONS:#{.inspect}" if ENV['DEBUG'] @connection ||= Faraday.new(.merge(builder: stack())) do |faraday| faraday.response :logger if ENV['DEBUG'] end end |
.default_middleware(options = {}) ⇒ Object
Default middleware stack that uses default adapter as specified at configuration stage.
40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bitbucket_rest_api/connection.rb', line 40 def default_middleware( = {}) proc do |builder| # builder.use BitBucket::Request::Jsonize builder.use Faraday::Request::Multipart builder.use Faraday::Request::UrlEncoded builder.use FaradayMiddleware::OAuth, consumer_key: client_id, consumer_secret: client_secret, token: oauth_token, token_secret: oauth_secret if client_id? && client_secret? builder.use BitBucket::Request::BasicAuth, authentication if basic_authed? builder.use FaradayMiddleware::EncodeJson builder.use Faraday::Response::Logger if ENV['DEBUG'] builder.use BitBucket::Response::Helpers unless [: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 = {}) ⇒ Object
27 28 29 30 31 32 33 34 35 |
# File 'lib/bitbucket_rest_api/connection.rb', line 27 def ( = {}) { headers: { USER_AGENT => user_agent }, ssl: { verify: false }, url: .fetch(:endpoint) { BitBucket.endpoint } }.merge() end |
.stack(options = {}, &block) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
75 76 77 78 79 80 81 82 83 |
# File 'lib/bitbucket_rest_api/connection.rb', line 75 def stack( = {}, &block) @stack ||= begin if block_given? Faraday::RackBuilder.new(&block) else Faraday::RackBuilder.new(&default_middleware()) end end end |