amazon_auth 0.1.2 → 0.1.3
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 +4 -4
- data/.gitignore +2 -0
- data/.travis.yml +2 -0
- data/README.md +25 -7
- data/amazon_auth.gemspec +1 -0
- data/bin/console +1 -0
- data/exe/amazon_auth +4 -2
- data/lib/amazon_auth/amazon_info.rb +1 -1
- data/lib/amazon_auth/client.rb +24 -17
- data/lib/amazon_auth/version.rb +1 -1
- data/lib/amazon_auth.rb +4 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c76ce0ce2b597d51bfeb14b3418ec5cd15841a3b
|
4
|
+
data.tar.gz: 47bb457cff9d84cd0d53f737f93ab70761293b8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6655aa1704f5762ade472ee7db50539f1f111222f1a90196c82536bf7dea7d501f64191e292680de1ce9b7165ae97aa115159fca4c2361e0c3f9324ed6c1e892
|
7
|
+
data.tar.gz: 0c20edebafc3574836c8821da69bb46fb088088a6d89fc74e7efea186aa6977f8b833f914fade1708cbada683a3a2972e0a1abb147392269e1c91911c6a6c85c
|
data/.gitignore
CHANGED
data/.travis.yml
CHANGED
data/README.md
CHANGED
@@ -1,5 +1,7 @@
|
|
1
1
|
# AmazonAuth
|
2
2
|
|
3
|
+
[](https://travis-ci.org/kyamaguchi/amazon_auth)
|
4
|
+
|
3
5
|
Sign In Amazon using Capybara and Selenium
|
4
6
|
|
5
7
|
## Installation
|
@@ -20,9 +22,17 @@ Or install it yourself as:
|
|
20
22
|
|
21
23
|
## Requirements
|
22
24
|
|
25
|
+
This gem may not work with newer versions of Firefox.
|
26
|
+
|
23
27
|
Firefox (<= 47.0.2)
|
24
28
|
|
25
|
-
|
29
|
+
[Download Firefox](https://ftp.mozilla.org/pub/firefox/releases/)
|
30
|
+
Don't forget to disable automatic updates of Firefox.
|
31
|
+
|
32
|
+
You may also need geckodriver.
|
33
|
+
This may need to be older depending on the version of selenium-webdriver.
|
34
|
+
e.g. geckodriver v0.14.0 works with selenium-webdriver 3.2
|
35
|
+
[Download geckodriver](https://github.com/mozilla/geckodriver/releases)
|
26
36
|
|
27
37
|
## Usage
|
28
38
|
|
@@ -30,8 +40,8 @@ This may not work with newer versions of Firefox.
|
|
30
40
|
|
31
41
|
[Quick] You can set login and password in console.
|
32
42
|
|
33
|
-
[Recommended] Or you can convert them to protect them against shoulder surfing.
|
34
|
-
Run `amazon_auth` and paste the output to
|
43
|
+
[Recommended] Or you can convert them to protect them against shoulder surfing.
|
44
|
+
Run `amazon_auth` and paste the output to _.env_.
|
35
45
|
(`AMAZON_USERNAME_CODE` , `AMAZON_PASSWORD_CODE` and `AMAZON_CODE_SALT`)
|
36
46
|
|
37
47
|
### Run
|
@@ -46,26 +56,34 @@ client = AmazonAuth::Client.new(login: 'your_amazon_email', password: 'your_amaz
|
|
46
56
|
client = AmazonAuth::Client.new
|
47
57
|
|
48
58
|
# Sign in
|
49
|
-
|
59
|
+
client.sign_in
|
50
60
|
|
51
61
|
# Continue to the page for Kindle
|
52
|
-
|
62
|
+
client.session.all('a').find{|e| e['href'] =~ %r{/gp/digital/fiona/manage/} }.click
|
53
63
|
|
54
64
|
# Close browser
|
55
|
-
|
65
|
+
client.driver.quit
|
56
66
|
```
|
57
67
|
|
68
|
+
### Use amamzon site in different domain
|
69
|
+
|
70
|
+
Set `AMAZON_DOMAIN` in _.env_.
|
71
|
+
|
72
|
+
e.g. `AMAZON_DOMAIN=amazon.co.jp` for Japanese site
|
73
|
+
|
58
74
|
## Development
|
59
75
|
|
60
76
|
Some features come from https://github.com/kyamaguchi/kindle
|
61
77
|
|
78
|
+
Use _.env.development_ instead of _.env_ in development.
|
79
|
+
|
62
80
|
```
|
63
81
|
git clone https://github.com/kyamaguchi/amazon_auth.git
|
64
82
|
cd amazon_auth
|
65
83
|
bundle
|
66
84
|
|
67
85
|
./exe/amazon_auth
|
68
|
-
vi .env
|
86
|
+
vi .env.development
|
69
87
|
|
70
88
|
rspec
|
71
89
|
|
data/amazon_auth.gemspec
CHANGED
data/bin/console
CHANGED
data/exe/amazon_auth
CHANGED
@@ -5,8 +5,9 @@ require 'highline/import'
|
|
5
5
|
|
6
6
|
result = []
|
7
7
|
|
8
|
-
|
9
|
-
|
8
|
+
domain = ask("Enter your amazon domain: ") { |q| q.echo = true ; q.default = AmazonInfo.domain }
|
9
|
+
login = ask("Enter your #{domain} username: ") { |q| q.echo = true }
|
10
|
+
passwd = ask("Enter your #{domain} password: ") { |q| q.echo = "*" }
|
10
11
|
salt = ask("Enter your salt: ") { |q| q.default = AmazonAuth::Converter.default_salt ; q.echo = true }
|
11
12
|
|
12
13
|
raise "Empty login or password" if login.to_s.size == 0 || passwd.to_s.size == 0
|
@@ -15,6 +16,7 @@ converter = AmazonAuth::Converter.new(salt)
|
|
15
16
|
|
16
17
|
puts "Put the following lines in .env"
|
17
18
|
puts
|
19
|
+
puts "AMAZON_DOMAIN=#{domain}"
|
18
20
|
puts "AMAZON_USERNAME_CODE=#{converter.encode(login)}"
|
19
21
|
puts "AMAZON_PASSWORD_CODE=#{converter.encode(passwd)}"
|
20
22
|
puts "AMAZON_CODE_SALT=#{salt}"
|
data/lib/amazon_auth/client.rb
CHANGED
@@ -1,9 +1,9 @@
|
|
1
1
|
module AmazonAuth
|
2
2
|
class Client
|
3
|
-
|
3
|
+
attr_accessor :initial_url
|
4
4
|
|
5
5
|
def initialize(options = {})
|
6
|
-
@
|
6
|
+
@initial_url = options.fetch(:url) { "https://www.#{AmazonInfo.domain}/" }
|
7
7
|
@login = options.fetch(:login) do
|
8
8
|
if (amazon_username_code = ENV['AMAZON_USERNAME_CODE']).present?
|
9
9
|
Converter.decode(amazon_username_code)
|
@@ -21,46 +21,53 @@ module AmazonAuth
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def sign_in
|
24
|
-
|
25
|
-
|
26
|
-
@session.within('#nav-tools') do
|
27
|
-
@session.click_on 'サインイン'
|
28
|
-
end
|
24
|
+
session.visit initial_url
|
25
|
+
session.first('#a-autoid-0-announce').click
|
29
26
|
|
30
27
|
fill_in_with_stroke('ap_email', @login)
|
31
28
|
fill_in_with_stroke('ap_password', @password)
|
32
|
-
|
29
|
+
session.click_on('signInSubmit')
|
33
30
|
|
34
|
-
while
|
31
|
+
while alert_displayed? do
|
35
32
|
retry_sign_in
|
36
33
|
end
|
37
34
|
|
38
|
-
|
39
|
-
|
35
|
+
session.first('.nav-line-2').click
|
36
|
+
session
|
40
37
|
end
|
41
38
|
|
42
39
|
def retry_sign_in
|
43
40
|
fill_in_with_stroke('ap_password', @password)
|
44
|
-
|
45
|
-
|
46
|
-
|
41
|
+
if image_recognition_displayed?
|
42
|
+
input = ask "Got the prompt. Read characters from the image: "
|
43
|
+
fill_in_with_stroke('auth-captcha-guess', input)
|
44
|
+
end
|
45
|
+
session.click_on('signInSubmit')
|
47
46
|
end
|
48
47
|
|
49
48
|
def fill_in_with_stroke(dom_id, value)
|
50
49
|
sleep_s
|
51
|
-
element =
|
50
|
+
element = session.first("##{dom_id}")
|
52
51
|
value.split(//u).each do |char|
|
53
52
|
element.send_keys(char)
|
54
53
|
sleep rand
|
55
54
|
end
|
56
55
|
end
|
57
56
|
|
57
|
+
def alert_displayed?
|
58
|
+
session.has_selector?('.a-alert-container')
|
59
|
+
end
|
60
|
+
|
58
61
|
def image_recognition_displayed?
|
59
|
-
|
62
|
+
session.has_selector?('#auth-captcha-image-container')
|
63
|
+
end
|
64
|
+
|
65
|
+
def session
|
66
|
+
@session ||= Capybara::Session.new(:selenium)
|
60
67
|
end
|
61
68
|
|
62
69
|
def driver
|
63
|
-
|
70
|
+
session.driver
|
64
71
|
end
|
65
72
|
|
66
73
|
def sleep_s(sec = 2)
|
data/lib/amazon_auth/version.rb
CHANGED
data/lib/amazon_auth.rb
CHANGED
@@ -3,6 +3,10 @@ Dotenv.load
|
|
3
3
|
require "active_support/all"
|
4
4
|
require "capybara"
|
5
5
|
require "highline/import"
|
6
|
+
begin
|
7
|
+
require 'byebug'
|
8
|
+
rescue LoadError
|
9
|
+
end
|
6
10
|
require_relative "amazon_auth/version"
|
7
11
|
require_relative "amazon_auth/amazon_info"
|
8
12
|
require_relative "amazon_auth/converter"
|
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.
|
4
|
+
version: 0.1.3
|
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-03-
|
11
|
+
date: 2017-03-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: capybara
|
@@ -122,6 +122,20 @@ dependencies:
|
|
122
122
|
- - ">="
|
123
123
|
- !ruby/object:Gem::Version
|
124
124
|
version: '0'
|
125
|
+
- !ruby/object:Gem::Dependency
|
126
|
+
name: byebug
|
127
|
+
requirement: !ruby/object:Gem::Requirement
|
128
|
+
requirements:
|
129
|
+
- - ">="
|
130
|
+
- !ruby/object:Gem::Version
|
131
|
+
version: '0'
|
132
|
+
type: :development
|
133
|
+
prerelease: false
|
134
|
+
version_requirements: !ruby/object:Gem::Requirement
|
135
|
+
requirements:
|
136
|
+
- - ">="
|
137
|
+
- !ruby/object:Gem::Version
|
138
|
+
version: '0'
|
125
139
|
description: Login amazon.
|
126
140
|
email:
|
127
141
|
- kzh.yap@gmail.com
|
@@ -166,7 +180,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
166
180
|
version: '0'
|
167
181
|
requirements: []
|
168
182
|
rubyforge_project:
|
169
|
-
rubygems_version: 2.
|
183
|
+
rubygems_version: 2.6.8
|
170
184
|
signing_key:
|
171
185
|
specification_version: 4
|
172
186
|
summary: Login amazon.
|