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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fa82a34f07a1ecc5cdb0ee81688539c6c885c61d
4
- data.tar.gz: 71b30141dd78e4a77738b0720d8940d0d04eec78
3
+ metadata.gz: c76ce0ce2b597d51bfeb14b3418ec5cd15841a3b
4
+ data.tar.gz: 47bb457cff9d84cd0d53f737f93ab70761293b8a
5
5
  SHA512:
6
- metadata.gz: 7e0d7c578d0fbe19a6da91cc9b71f80faca4f6b4824ed796a9f1b21a1691c1d941856a807ae4a8e26349093af59826ba78da0842ef29a8c0e154dd075635cfff
7
- data.tar.gz: 9436ec0df002954d7bb41902111e8648cf5bf17e8d0eb3167ea54d1016bb88d33285629ebb612154cdd535f2ea8e5eb374249cfa8d59c83e88cd55a8b0b9decf
6
+ metadata.gz: 6655aa1704f5762ade472ee7db50539f1f111222f1a90196c82536bf7dea7d501f64191e292680de1ce9b7165ae97aa115159fca4c2361e0c3f9324ed6c1e892
7
+ data.tar.gz: 0c20edebafc3574836c8821da69bb46fb088088a6d89fc74e7efea186aa6977f8b833f914fade1708cbada683a3a2972e0a1abb147392269e1c91911c6a6c85c
data/.gitignore CHANGED
@@ -8,3 +8,5 @@
8
8
  /spec/reports/
9
9
  /tmp/
10
10
  /.env
11
+ /.env.development
12
+ /.byebug_history
data/.travis.yml CHANGED
@@ -2,4 +2,6 @@ sudo: false
2
2
  language: ruby
3
3
  rvm:
4
4
  - 2.2.4
5
+ - 2.2.6
6
+ - 2.3.3
5
7
  before_install: gem install bundler -v 1.12.5
data/README.md CHANGED
@@ -1,5 +1,7 @@
1
1
  # AmazonAuth
2
2
 
3
+ [![Build Status](https://travis-ci.org/kyamaguchi/amazon_auth.svg?branch=master)](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
- This may not work with newer versions of Firefox.
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 _env_.
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
- page = client.sign_in
59
+ client.sign_in
50
60
 
51
61
  # Continue to the page for Kindle
52
- page.first('a', text: 'コンテンツと端末の管理').click
62
+ client.session.all('a').find{|e| e['href'] =~ %r{/gp/digital/fiona/manage/} }.click
53
63
 
54
64
  # Close browser
55
- page.driver.quit
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
@@ -27,4 +27,5 @@ Gem::Specification.new do |spec|
27
27
  spec.add_development_dependency "bundler"
28
28
  spec.add_development_dependency "rake"
29
29
  spec.add_development_dependency "rspec"
30
+ spec.add_development_dependency "byebug"
30
31
  end
data/bin/console CHANGED
@@ -2,6 +2,7 @@
2
2
 
3
3
  require "bundler/setup"
4
4
  require "amazon_auth"
5
+ Dotenv.load('.env.development')
5
6
 
6
7
  # You can add fixtures and/or initialization code here to make experimenting
7
8
  # with your gem easier. You can also use a different console, if you like.
data/exe/amazon_auth CHANGED
@@ -5,8 +5,9 @@ require 'highline/import'
5
5
 
6
6
  result = []
7
7
 
8
- login = ask("Enter your #{AmazonInfo.domain} username: ") { |q| q.echo = true }
9
- passwd = ask("Enter your #{AmazonInfo.domain} password: ") { |q| q.echo = "*" }
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}"
@@ -1,5 +1,5 @@
1
1
  class AmazonInfo
2
2
  def self.domain
3
- 'amazon.co.jp'
3
+ ENV['AMAZON_DOMAIN'].presence || 'amazon.com'
4
4
  end
5
5
  end
@@ -1,9 +1,9 @@
1
1
  module AmazonAuth
2
2
  class Client
3
- INITIAL_ENTRY_URL = 'https://www.amazon.co.jp/'
3
+ attr_accessor :initial_url
4
4
 
5
5
  def initialize(options = {})
6
- @url = options.fetch(:url) { INITIAL_ENTRY_URL }
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
- @session = Capybara::Session.new(:selenium)
25
- @session.visit @url
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
- @session.click_on('signInSubmit')
29
+ session.click_on('signInSubmit')
33
30
 
34
- while image_recognition_displayed? do
31
+ while alert_displayed? do
35
32
  retry_sign_in
36
33
  end
37
34
 
38
- @session.first('.nav-line-2').click
39
- @session
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
- input = ask "Got the prompt. Read characters from the image: "
45
- fill_in_with_stroke('auth-captcha-guess', input)
46
- @session.click_on('signInSubmit')
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 = @session.first("##{dom_id}")
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
- @session.has_content?('お客様のアカウントを強力に保護するため') || @session.has_content?('問題が発生しました')
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
- @session.driver
70
+ session.driver
64
71
  end
65
72
 
66
73
  def sleep_s(sec = 2)
@@ -1,3 +1,3 @@
1
1
  module AmazonAuth
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.3"
3
3
  end
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.2
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-15 00:00:00.000000000 Z
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.4.8
183
+ rubygems_version: 2.6.8
170
184
  signing_key:
171
185
  specification_version: 4
172
186
  summary: Login amazon.