lib/tracker_api/client.rb in tracker_api-0.2.10 vs lib/tracker_api/client.rb in tracker_api-0.2.11

- old
+ new

@@ -18,30 +18,33 @@ # @option options [String] :adapter Custom http adapter to configure Faraday with # @option options [String] :connection_options Connection options to pass to Faraday # # @example Creating a Client # Client.new token: 'my-super-special-token' - def initialize(options={}) + def initialize(options={}, &block) url = options.fetch(:url, 'https://www.pivotaltracker.com') @url = Addressable::URI.parse(url).to_s @api_version = options.fetch(:api_version, '/services/v5') @logger = options.fetch(:logger, ::Logger.new(nil)) adapter = options.fetch(:adapter, :excon) connection_options = options.fetch(:connection_options, { ssl: { verify: true } }) @auto_paginate = options.fetch(:auto_paginate, true) @token = options[:token] raise 'Missing required options: :token' unless @token + @faraday_block = block if block_given? + @connection = Faraday.new({ url: @url }.merge(connection_options)) do |builder| # response builder.use Faraday::Response::RaiseError builder.response :json # request builder.request :multipart builder.request :json builder.use TrackerApi::Logger, @logger + @faraday_block.call(builder) if @faraday_block builder.adapter adapter end end # Make a HTTP GET request