amazon_auth 0.1.5 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 9bb189eb92ba2db5dcf11bc40d40bda8bc490ea2
4
- data.tar.gz: 2498a86f72cabefebef0682de2debe8697cf841d
3
+ metadata.gz: bef1e0c0082271554c7f432b4f47c3393185a8c7
4
+ data.tar.gz: 35b752aa09e5afc2e6e80430340709898e29da5b
5
5
  SHA512:
6
- metadata.gz: df882ca03728ed34c328f76cb4607836e1dda1185093fd7af1df4e40080ef746fbb72a5377a4dee5f1a3cc5d941c7f1060c75e69562a26e911578910c1f97da1
7
- data.tar.gz: 2af1a90785ec4f78770feb83e90b141de50a1d155697c7dd213137ce03c5f7c3431bc66dee6c49b4d3e7293a17f9e6f87f2611ebe9d1127eb8c4ecb42bddec48
6
+ metadata.gz: 4b7a75614c9de5ee2b874cddfdadfcf3f3af0da4749f79b7b0ecccd39fac63bf2b6756908f0554f6c7db1a16a07b6368a80dd1579cea67b3ef7f0db2be710857
7
+ data.tar.gz: ee61dd83b8f73127a0cb8053ef4b340e67027d8e6b6c5bfb000a170b542ba251e4a6ebd09ae7ee95e3770d07292d2f8a1d5515fa1b4380a7ff1a966727592c9c
data/.gitignore CHANGED
@@ -11,3 +11,4 @@
11
11
  /.env.development
12
12
  /.byebug_history
13
13
  /.ruby-version
14
+ /.rspec_status
data/README.md CHANGED
@@ -5,6 +5,9 @@
5
5
 
6
6
  Sign In Amazon using Capybara and Selenium
7
7
 
8
+ ![amazon_auth_login](https://cloud.githubusercontent.com/assets/275284/25064724/7f5faae4-223b-11e7-9fc6-4a82d1d727ab.gif)
9
+ Recorded with [Recordit](http://recordit.co/)
10
+
8
11
  ## Installation
9
12
 
10
13
  Add this line to your application's Gemfile:
@@ -64,10 +67,8 @@ client = AmazonAuth::Client.new
64
67
  client.sign_in
65
68
 
66
69
  # Continue to the page for Kindle
67
- client.session.all('a').find{|e| e['href'] =~ %r{/gp/digital/fiona/manage/} }.click
68
-
69
- # Close browser
70
- client.driver.quit
70
+ link = client.links_for('#navFooter a').find{|link| link =~ %r{/gp/digital/fiona/manage/} }
71
+ client.session.visit link
71
72
  ```
72
73
 
73
74
  ### Use amazon site in different domain
@@ -21,24 +21,42 @@ module AmazonAuth
21
21
  @driver = options.fetch(:driver, :selenium)
22
22
  end
23
23
 
24
+ def links_for(selector, options = {})
25
+ wait_for_selector(selector, options)
26
+ doc.css(selector).map{|e| e['href'] }
27
+ end
28
+
29
+ def wait_for_selector(selector, options = {})
30
+ options.fetch(:wait_time, 3).times do
31
+ if session.first(selector)
32
+ break
33
+ else
34
+ sleep(1)
35
+ end
36
+ end
37
+ end
38
+
24
39
  def sign_in
25
40
  session.visit initial_url
26
- session.first('#a-autoid-0-announce').click
41
+ link = links_for('#nav-signin-tooltip a').find{|link| link =~ %r{\A/gp/navigation/redirector.html} }
42
+ session.visit(link) if link
43
+ submit_signin_form
44
+ end
27
45
 
28
- sleep_s
46
+ def submit_signin_form
47
+ return true unless session.has_selector?('#signInSubmit')
29
48
  session.fill_in 'ap_email', with: @login
30
49
  session.fill_in 'ap_password', with: @password
31
50
  session.click_on('signInSubmit')
32
51
 
33
- while alert_displayed? do
34
- retry_sign_in
52
+ raise('Failed on signin') if alert_displayed?
53
+ while image_recognition_displayed? do
54
+ retry_signin_form_with_image_recognition
35
55
  end
36
-
37
- session.first('.nav-line-2').click
38
- session
56
+ true
39
57
  end
40
58
 
41
- def retry_sign_in
59
+ def retry_signin_form_with_image_recognition
42
60
  session.fill_in 'ap_password', with: @password
43
61
  if image_recognition_displayed?
44
62
  input = ask "Got the prompt. Read characters from the image: "
@@ -48,7 +66,7 @@ module AmazonAuth
48
66
  end
49
67
 
50
68
  def alert_displayed?
51
- session.has_selector?('.a-alert-container')
69
+ session.has_selector?('.a-alert-error')
52
70
  end
53
71
 
54
72
  def image_recognition_displayed?
@@ -59,12 +77,8 @@ module AmazonAuth
59
77
  @session ||= Capybara::Session.new(@driver)
60
78
  end
61
79
 
62
- def driver
63
- session.driver
64
- end
65
-
66
- def sleep_s(sec = 2)
67
- sleep sec
80
+ def doc
81
+ Nokogiri.HTML(session.html)
68
82
  end
69
83
 
70
84
  # Hide instance variables of credentials on console
@@ -1,3 +1,3 @@
1
1
  module AmazonAuth
2
- VERSION = "0.1.5"
2
+ VERSION = "0.2.0"
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.1.5
4
+ version: 0.2.0
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-04-15 00:00:00.000000000 Z
11
+ date: 2017-04-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: capybara