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 +4 -4
- data/.gitignore +1 -0
- data/README.md +5 -4
- data/lib/amazon_auth/client.rb +29 -15
- data/lib/amazon_auth/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: bef1e0c0082271554c7f432b4f47c3393185a8c7
|
4
|
+
data.tar.gz: 35b752aa09e5afc2e6e80430340709898e29da5b
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4b7a75614c9de5ee2b874cddfdadfcf3f3af0da4749f79b7b0ecccd39fac63bf2b6756908f0554f6c7db1a16a07b6368a80dd1579cea67b3ef7f0db2be710857
|
7
|
+
data.tar.gz: ee61dd83b8f73127a0cb8053ef4b340e67027d8e6b6c5bfb000a170b542ba251e4a6ebd09ae7ee95e3770d07292d2f8a1d5515fa1b4380a7ff1a966727592c9c
|
data/.gitignore
CHANGED
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.
|
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
|
data/lib/amazon_auth/client.rb
CHANGED
@@ -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
|
-
|
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
|
-
|
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
|
-
|
34
|
-
|
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
|
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-
|
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
|
63
|
-
session.
|
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
|
data/lib/amazon_auth/version.rb
CHANGED
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.
|
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-
|
11
|
+
date: 2017-04-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|