Module: BitBucket::Connection
- Extended by:
- Connection
- Includes:
- Constants
- Included in:
- Connection, Request
- Defined in:
- lib/bitbucket_rest_api/connection.rb
Constant Summary collapse
- ALLOWED_OPTIONS =
[ :headers, :url, :params, :request, :ssl, :builder, :api ].freeze
Constants included from Constants
BitBucket::Constants::ACCEPT, BitBucket::Constants::ACCEPT_CHARSET, BitBucket::Constants::CACHE_CONTROL, BitBucket::Constants::CONTENT_LENGTH, BitBucket::Constants::CONTENT_TYPE, BitBucket::Constants::DATE, BitBucket::Constants::ETAG, BitBucket::Constants::LOCATION, BitBucket::Constants::META_FIRST, BitBucket::Constants::META_LAST, BitBucket::Constants::META_NEXT, BitBucket::Constants::META_PREV, BitBucket::Constants::META_REL, BitBucket::Constants::PARAM_PAGE, BitBucket::Constants::PARAM_START_PAGE, BitBucket::Constants::QUERY_STR_SEP, BitBucket::Constants::RATELIMIT_LIMIT, BitBucket::Constants::RATELIMIT_REMAINING, BitBucket::Constants::SERVER, BitBucket::Constants::USER_AGENT
Instance Method Summary collapse
- #caching? ⇒ Boolean
- #clear_cache ⇒ Object
-
#connection(api, options = {}) ⇒ Object
Returns a Fraday::Connection object.
- #default_options(options = {}) ⇒ Object
-
#stack(options = {}) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
Instance Method Details
#caching? ⇒ Boolean
32 33 34 |
# File 'lib/bitbucket_rest_api/connection.rb', line 32 def caching? !@connection.nil? end |
#clear_cache ⇒ Object
28 29 30 |
# File 'lib/bitbucket_rest_api/connection.rb', line 28 def clear_cache @connection = nil end |
#connection(api, options = {}) ⇒ Object
Returns a Fraday::Connection object
48 49 50 51 52 53 54 55 56 57 58 |
# File 'lib/bitbucket_rest_api/connection.rb', line 48 def connection(api, = {}) = () clear_cache unless .empty? builder = api.stack ? api.stack : stack(.merge!(api: api)) .merge!(builder: builder) .keep_if {|key, value| ALLOWED_OPTIONS.include?(key) } puts "OPTIONS:#{.inspect}" if ENV['DEBUG'] @connection ||= Faraday.new() end |
#default_options(options = {}) ⇒ Object
18 19 20 21 22 23 24 25 26 |
# File 'lib/bitbucket_rest_api/connection.rb', line 18 def (={}) { :headers => { USER_AGENT => [:user_agent] }, :ssl => { :verify => false }, :url => .fetch(:endpoint) { BitBucket.endpoint } }.merge() end |
#stack(options = {}) ⇒ Object
Exposes middleware builder to facilitate custom stacks and easy addition of new extensions such as cache adapter.
39 40 41 42 43 44 |
# File 'lib/bitbucket_rest_api/connection.rb', line 39 def stack(={}) @stack ||= begin builder_class = defined?(Faraday::RackBuilder) ? Faraday::RackBuilder : Faraday::Builder builder_class.new(&BitBucket.default_middleware()) end end |