Skip to content

Commit

Permalink
Merge pull request #54 from jsmestad/feature/configure-client
Browse files Browse the repository at this point in the history
Support passing in a block to initialize
  • Loading branch information
forest committed Aug 17, 2015
2 parents a4eda90 + a3eca57 commit c715563
Showing 1 changed file with 4 additions and 1 deletion.
5 changes: 4 additions & 1 deletion lib/tracker_api/client.rb
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,7 @@ class Client
#
# @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')
Expand All @@ -31,6 +31,8 @@ def initialize(options={})
@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
Expand All @@ -41,6 +43,7 @@ def initialize(options={})
builder.request :json

builder.use TrackerApi::Logger, @logger
@faraday_block.call(builder) if @faraday_block
builder.adapter adapter
end
end
Expand Down

0 comments on commit c715563

Please sign in to comment.