lib/heroku/api.rb in heroku-api-0.3.21 vs lib/heroku/api.rb in heroku-api-0.3.22
- old
+ new
@@ -50,10 +50,12 @@
:host => 'api.heroku.com',
:nonblock => false,
:scheme => 'https'
}
+ attr_accessor :second_factor
+
def initialize(options={})
options = OPTIONS.merge(options)
@api_key = options.delete(:api_key) || ENV['HEROKU_API_KEY']
if !@api_key && options.has_key?(:username) && options.has_key?(:password)
@@ -71,9 +73,14 @@
@connection = Excon.new("#{options[:scheme]}://#{options[:host]}", options)
end
def request(params, &block)
begin
+ if @second_factor
+ params[:headers] ||= {}
+ params[:headers]['Heroku-Two-Factor-Code'] = @second_factor
+ @second_factor = nil # don't use the token again
+ end
response = @connection.request(params, &block)
rescue Excon::Errors::HTTPStatusError => error
klass = case error.response.status
when 401 then Heroku::API::Errors::Unauthorized
when 402 then Heroku::API::Errors::VerificationRequired