amazon_auth 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 04a18c43fe199086bfa94cb3c6eeb96d6c418f16
4
- data.tar.gz: d6a43c21ebfb9e81cc18c917ec3351958af4a04a
3
+ metadata.gz: 063d73a7b294c00b1e491c7c7fadffe02dd58807
4
+ data.tar.gz: acb5054776d89ba8c6ecaef6ad5496a92883bd61
5
5
  SHA512:
6
- metadata.gz: ce2c1e9a62fce22901ac94c3e48bdcf740cf261df96ba10456ead755152fca65037f3a91b9acb4f7d98513438d1e250fd2ce047bb78cc96dd719c71cf09ff523
7
- data.tar.gz: 742268eb916028b5927723ecd0ec4911a9feab20aadcaa1fec52960f6657da974600ad3badf960866e03c1f7bd16b29d9eeb3905ab4fed5e6f89ffa4b4b44f2c
6
+ metadata.gz: e060fd99e003322aee83799c9cf05171db6891e45d7ca06dfee5ad164660b94743c021337d35ef95fdd1adf5df6f5488126bbd44e977bf07d7b377c35dcb7fbd
7
+ data.tar.gz: 7073d53fe9aec2b7b18094e5762fe560b8f5ce9a7e89790d8a947c26077bbbe1f55fb55990a8ec808bbb61c8c3473ba1fa51b692406914a277fe1a3866ea6b02
data/README.md CHANGED
@@ -73,6 +73,20 @@ Set `AMAZON_DOMAIN` in _.env_.
73
73
 
74
74
  e.g. `AMAZON_DOMAIN=amazon.co.jp` for Japanese site
75
75
 
76
+ ### Logging
77
+
78
+ Normal logging
79
+
80
+ ```ruby
81
+ client = AmazonAuth::Client.new(verbose: true)
82
+ ```
83
+
84
+ More logging (This includes `session.current_url`)
85
+
86
+ ```ruby
87
+ client = AmazonAuth::Client.new(debug: true)
88
+ ```
89
+
76
90
  ### Use Firefox
77
91
 
78
92
  This gem may not work with newer versions of Firefox.
data/lib/amazon_auth.rb CHANGED
@@ -8,6 +8,7 @@ begin
8
8
  rescue LoadError
9
9
  end
10
10
  require_relative "amazon_auth/version"
11
+ require_relative "amazon_auth/extensions/common_extension"
11
12
  require_relative "amazon_auth/extensions/session_extension"
12
13
  require_relative "amazon_auth/amazon_info"
13
14
  require_relative "amazon_auth/capybara"
@@ -1,10 +1,12 @@
1
1
  module AmazonAuth
2
2
  class Client
3
+ include AmazonAuth::CommonExtension
3
4
  include AmazonAuth::SessionExtension
4
5
 
5
6
  attr_accessor :initial_url
6
7
 
7
8
  def initialize(options = {})
9
+ @options = options
8
10
  @initial_url = options.fetch(:url) { "https://www.#{AmazonInfo.domain}/" }
9
11
  @login = options.fetch(:login) do
10
12
  if (amazon_username_code = ENV['AMAZON_USERNAME_CODE']).present?
@@ -30,21 +32,26 @@ module AmazonAuth
30
32
 
31
33
  def sign_in
32
34
  session.visit initial_url
35
+ debug "Visiting #{initial_url}"
33
36
  link = links_for('#nav-signin-tooltip a').find{|link| link =~ %r{\A/gp/navigation/redirector.html} }
37
+ debug "link: [#{link}]"
34
38
  session.visit(link) if link
35
39
  submit_signin_form
36
40
  end
37
41
 
38
42
  def submit_signin_form
43
+ debug "Begin submit_signin_form"
39
44
  return true unless session.has_selector?('#signInSubmit')
40
45
  session.fill_in 'ap_email', with: @login
41
46
  session.fill_in 'ap_password', with: @password
42
47
  session.click_on('signInSubmit')
48
+ log "Clicked signInSubmit"
43
49
 
44
50
  raise('Failed on signin') if alert_displayed?
45
51
  while image_recognition_displayed? do
46
52
  retry_signin_form_with_image_recognition
47
53
  end
54
+ debug "End submit_signin_form"
48
55
  true
49
56
  end
50
57
 
@@ -52,8 +59,12 @@ module AmazonAuth
52
59
  return true unless session.has_selector?('#signInSubmit')
53
60
  session.fill_in 'ap_password', with: @password
54
61
  if image_recognition_displayed?
55
- input = ask "Got the prompt. Read characters from the image: "
56
- return true if input.blank? || !session.first('#auth-captcha-guess') # Skip when form is submitted manually
62
+ input = ask "Got the prompt. Read characters from the image [blank to cancel]: "
63
+ if input.blank?
64
+ debug "Going back to #{initial_url}"
65
+ session.visit initial_url
66
+ return true
67
+ end
57
68
  session.fill_in 'auth-captcha-guess', with: input
58
69
  end
59
70
  sleep 1
@@ -0,0 +1,15 @@
1
+ module AmazonAuth
2
+ module CommonExtension
3
+
4
+ def log(message)
5
+ return unless (@options[:debug] || @options[:verbose])
6
+ puts "[#{Time.current.strftime('%Y-%m-%d %H:%M:%S')}] #{message}" +
7
+ (@options[:debug] ? " -- #{session.current_url}" : '')
8
+ end
9
+
10
+ def debug(message)
11
+ return unless @options[:debug]
12
+ log(message)
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module AmazonAuth
2
- VERSION = "0.3.0"
2
+ VERSION = "0.3.1"
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: amazon_auth
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.0
4
+ version: 0.3.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Kazuho Yamaguchi
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2017-06-07 00:00:00.000000000 Z
11
+ date: 2017-06-16 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara
@@ -160,6 +160,7 @@ files:
160
160
  - lib/amazon_auth/capybara.rb
161
161
  - lib/amazon_auth/client.rb
162
162
  - lib/amazon_auth/converter.rb
163
+ - lib/amazon_auth/extensions/common_extension.rb
163
164
  - lib/amazon_auth/extensions/session_extension.rb
164
165
  - lib/amazon_auth/version.rb
165
166
  homepage: https://github.com/kyamaguchi/amazon_auth
@@ -182,7 +183,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
183
  version: '0'
183
184
  requirements: []
184
185
  rubyforge_project:
185
- rubygems_version: 2.6.8
186
+ rubygems_version: 2.6.11
186
187
  signing_key:
187
188
  specification_version: 4
188
189
  summary: Login amazon.