lib/amazon_auth/client.rb in amazon_auth-0.2.0 vs lib/amazon_auth/client.rb in amazon_auth-0.2.1

- old
+ new

@@ -1,7 +1,9 @@ module AmazonAuth class Client + include AmazonAuth::SessionExtension + attr_accessor :initial_url def initialize(options = {}) @initial_url = options.fetch(:url) { "https://www.#{AmazonInfo.domain}/" } @login = options.fetch(:login) do @@ -17,27 +19,15 @@ else raise('AMAZON_PASSWORD_CODE is required.') end end @driver = options.fetch(:driver, :selenium) + rescue => e + puts "Please setup credentials of amazon_auth gem with folloing its instruction." + raise e end - def links_for(selector, options = {}) - wait_for_selector(selector, options) - doc.css(selector).map{|e| e['href'] } - end - - def wait_for_selector(selector, options = {}) - options.fetch(:wait_time, 3).times do - if session.first(selector) - break - else - sleep(1) - end - end - end - def sign_in session.visit initial_url link = links_for('#nav-signin-tooltip a').find{|link| link =~ %r{\A/gp/navigation/redirector.html} } session.visit(link) if link submit_signin_form @@ -55,16 +45,19 @@ end true end def retry_signin_form_with_image_recognition + return true unless session.has_selector?('#signInSubmit') session.fill_in 'ap_password', with: @password if image_recognition_displayed? input = ask "Got the prompt. Read characters from the image: " session.fill_in 'auth-captcha-guess', with: input end + sleep 1 session.click_on('signInSubmit') + sleep 2 end def alert_displayed? session.has_selector?('.a-alert-error') end @@ -73,13 +66,9 @@ session.has_selector?('#auth-captcha-image-container') end def session @session ||= Capybara::Session.new(@driver) - end - - def doc - Nokogiri.HTML(session.html) end # Hide instance variables of credentials on console def inspect to_s