yopta_switcher 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/exe/yopta_switcher +5 -0
- data/lib/yopta_switcher.rb +5 -0
- data/lib/yopta_switcher/cli.rb +20 -0
- data/lib/yopta_switcher/cli/operation_builder.rb +58 -0
- data/lib/yopta_switcher/cli/options.rb +13 -0
- data/lib/yopta_switcher/cli/options_parser.rb +98 -0
- data/lib/yopta_switcher/client.rb +68 -0
- data/lib/yopta_switcher/operations/turn_off.rb +21 -0
- data/lib/yopta_switcher/operations/turn_on.rb +21 -0
- data/lib/yopta_switcher/selenium_driver_adapter.rb +42 -0
- data/lib/yopta_switcher/version.rb +3 -0
- metadata +169 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: 34208e2962a5669de56be377d0dd47275afa4a1b
|
4
|
+
data.tar.gz: 9e493593141fad7e6f6546a2c346e4be3b67f466
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 91cbba17cdc2c6d15a308ed494ed6387a25249dab38735edbcc4a912c22f9172f94454e8ac0a2f30f6baf2b877462a49cf2cccb32a018de9e736ef1066ea58be
|
7
|
+
data.tar.gz: 744182168fe98890835e46a31e41a3ae21d6c29ad9e63cb426098a7901c5ce78022bdbb7f653ecd13efec40baf57046bb59e7f6e0fae7c583b22bbd32ac8b644
|
data/exe/yopta_switcher
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
require 'yopta_switcher'
|
2
|
+
require 'yopta_switcher/cli/options'
|
3
|
+
require 'yopta_switcher/cli/options_parser'
|
4
|
+
require 'yopta_switcher/cli/operation_builder'
|
5
|
+
|
6
|
+
module YoptaSwitcher
|
7
|
+
module CLI
|
8
|
+
def self.run(argv = [])
|
9
|
+
options_parser = OptionsParser.new(argv: argv, options: Options.new)
|
10
|
+
options_parser.parse!
|
11
|
+
options = options_parser.options
|
12
|
+
|
13
|
+
operation_builder = OperationBuilder.new(options)
|
14
|
+
operation_builder.build
|
15
|
+
operation = operation_builder.operation
|
16
|
+
|
17
|
+
operation.call
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
@@ -0,0 +1,58 @@
|
|
1
|
+
require 'selenium-webdriver'
|
2
|
+
require 'yopta_switcher'
|
3
|
+
|
4
|
+
module YoptaSwitcher
|
5
|
+
module CLI
|
6
|
+
class OperationBuilder
|
7
|
+
attr_reader :client, :driver, :options, :operation
|
8
|
+
|
9
|
+
def initialize(options)
|
10
|
+
@options = options
|
11
|
+
@driver = build_driver(options)
|
12
|
+
@client = build_client(@driver, options)
|
13
|
+
end
|
14
|
+
|
15
|
+
def build
|
16
|
+
@operation ||=
|
17
|
+
options.
|
18
|
+
operation_class.
|
19
|
+
new(
|
20
|
+
client: client,
|
21
|
+
login: options.login,
|
22
|
+
password: options.password
|
23
|
+
)
|
24
|
+
end
|
25
|
+
|
26
|
+
private
|
27
|
+
|
28
|
+
def build_driver(options)
|
29
|
+
wait = wait_class.new(timeout: options.wait_timeout)
|
30
|
+
driver = webdriver_class.for(options.browser)
|
31
|
+
driver_adapter_class.new(driver: driver, wait_instance: wait)
|
32
|
+
end
|
33
|
+
|
34
|
+
def build_client(driver, options)
|
35
|
+
client_class.new(
|
36
|
+
driver: driver,
|
37
|
+
login_url: options.login_url
|
38
|
+
)
|
39
|
+
end
|
40
|
+
|
41
|
+
def client_class
|
42
|
+
YoptaSwitcher::Client
|
43
|
+
end
|
44
|
+
|
45
|
+
def wait_class
|
46
|
+
Selenium::WebDriver::Wait
|
47
|
+
end
|
48
|
+
|
49
|
+
def webdriver_class
|
50
|
+
Selenium::WebDriver
|
51
|
+
end
|
52
|
+
|
53
|
+
def driver_adapter_class
|
54
|
+
YoptaSwitcher::SeleniumDriverAdapter
|
55
|
+
end
|
56
|
+
end
|
57
|
+
end
|
58
|
+
end
|
@@ -0,0 +1,98 @@
|
|
1
|
+
require 'optparse'
|
2
|
+
require 'optparse/uri'
|
3
|
+
|
4
|
+
module YoptaSwitcher
|
5
|
+
module CLI
|
6
|
+
class OptionsParser
|
7
|
+
OPERATION_NAME_TO_CLASS_MAPPING = {
|
8
|
+
'turn_on' => YoptaSwitcher::Operations::TurnOn,
|
9
|
+
'turn_off' => YoptaSwitcher::Operations::TurnOff
|
10
|
+
}.freeze
|
11
|
+
|
12
|
+
BROWSER_MAPPING = {
|
13
|
+
'phantomjs' => :phantomjs,
|
14
|
+
'firefox' => :firefox
|
15
|
+
}.freeze
|
16
|
+
|
17
|
+
attr_reader :options, :argv, :parser
|
18
|
+
|
19
|
+
def initialize(argv:, options:)
|
20
|
+
@options = options
|
21
|
+
@argv = argv
|
22
|
+
@parser = OptionParser.new
|
23
|
+
define_options
|
24
|
+
end
|
25
|
+
|
26
|
+
def define_options
|
27
|
+
define_login_url_option
|
28
|
+
define_login_option
|
29
|
+
define_password_option
|
30
|
+
define_wait_option
|
31
|
+
define_operation_option
|
32
|
+
define_browser_option
|
33
|
+
end
|
34
|
+
|
35
|
+
def parse!
|
36
|
+
set_default_options
|
37
|
+
parser.parse!(argv)
|
38
|
+
options
|
39
|
+
end
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def set_default_options
|
44
|
+
options.wait_timeout = 10
|
45
|
+
options.browser = :phantomjs
|
46
|
+
options.operation_class = YoptaSwitcher::Operations::TurnOn
|
47
|
+
end
|
48
|
+
|
49
|
+
def define_login_url_option
|
50
|
+
parser.on('-u Login URL', URI) do |url|
|
51
|
+
options.login_url = url.to_s
|
52
|
+
end
|
53
|
+
end
|
54
|
+
|
55
|
+
def define_login_option
|
56
|
+
parser.on('-l Login') do |login|
|
57
|
+
options.login = login
|
58
|
+
end
|
59
|
+
end
|
60
|
+
|
61
|
+
def define_password_option
|
62
|
+
parser.on('-p Password') do |password|
|
63
|
+
options.password = password
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
def define_wait_option
|
68
|
+
parser.on(
|
69
|
+
'-w Wait timeout in seconds',
|
70
|
+
OptionParser::DecimalInteger,
|
71
|
+
'10'
|
72
|
+
) do |wait|
|
73
|
+
options.wait_timeout = wait
|
74
|
+
end
|
75
|
+
end
|
76
|
+
|
77
|
+
def define_operation_option
|
78
|
+
parser.on(
|
79
|
+
'-o Operation',
|
80
|
+
OPERATION_NAME_TO_CLASS_MAPPING.keys,
|
81
|
+
OPERATION_NAME_TO_CLASS_MAPPING.keys.join(', ')
|
82
|
+
) do |operation|
|
83
|
+
options.operation_class = OPERATION_NAME_TO_CLASS_MAPPING[operation]
|
84
|
+
end
|
85
|
+
end
|
86
|
+
|
87
|
+
def define_browser_option
|
88
|
+
parser.on(
|
89
|
+
'-b Browser',
|
90
|
+
BROWSER_MAPPING.keys,
|
91
|
+
BROWSER_MAPPING.values.join(', ')
|
92
|
+
) do |browser|
|
93
|
+
options.browser = BROWSER_MAPPING[browser]
|
94
|
+
end
|
95
|
+
end
|
96
|
+
end
|
97
|
+
end
|
98
|
+
end
|
@@ -0,0 +1,68 @@
|
|
1
|
+
module YoptaSwitcher
|
2
|
+
class Client
|
3
|
+
DEFAULT_CLICKS_NUMBER = 15
|
4
|
+
|
5
|
+
attr_reader :driver, :login_url
|
6
|
+
|
7
|
+
def initialize(driver:, login_url:)
|
8
|
+
@driver = driver
|
9
|
+
@login_url = login_url
|
10
|
+
end
|
11
|
+
|
12
|
+
def login(login:, password:)
|
13
|
+
driver.visit(login_url)
|
14
|
+
|
15
|
+
username_element = driver.find_element(name: 'login')
|
16
|
+
driver.clear(username_element)
|
17
|
+
driver.fill_in(username_element, login)
|
18
|
+
|
19
|
+
password_element = driver.find_element(name: 'password')
|
20
|
+
driver.clear(password_element)
|
21
|
+
driver.fill_in(password_element, password)
|
22
|
+
|
23
|
+
driver.submit(password_element)
|
24
|
+
end
|
25
|
+
|
26
|
+
def set_lowest_subscription_level(clicks_number = DEFAULT_CLICKS_NUMBER)
|
27
|
+
decrease_button =
|
28
|
+
driver.wait { driver.find_element(css: 'div.decrease a') }
|
29
|
+
increase_button = driver.find_element(css: 'div.increase a')
|
30
|
+
clicks_number.times do
|
31
|
+
driver.click(decrease_button)
|
32
|
+
end
|
33
|
+
driver.click(increase_button)
|
34
|
+
end
|
35
|
+
|
36
|
+
def set_highest_subscription_level(clicks_number = DEFAULT_CLICKS_NUMBER)
|
37
|
+
increase_button =
|
38
|
+
driver.wait { driver.find_element(css: 'div.increase a') }
|
39
|
+
decrease_button = driver.find_element(css: 'div.decrease a')
|
40
|
+
clicks_number.times do
|
41
|
+
driver.click(increase_button)
|
42
|
+
end
|
43
|
+
end
|
44
|
+
|
45
|
+
def apply_selected_subscription_level
|
46
|
+
apply_button =
|
47
|
+
driver.wait { driver.find_element(css: '.main-offer .tariff a.btn') }
|
48
|
+
|
49
|
+
driver.click(apply_button)
|
50
|
+
driver.wait do
|
51
|
+
driver.
|
52
|
+
find_element(
|
53
|
+
css: '.main-offer .tariff .tarriff-info .message-wrapper'
|
54
|
+
)
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
def logout
|
59
|
+
logout_button_text = 'Выход'
|
60
|
+
logout_button = driver.find_element(link_text: logout_button_text)
|
61
|
+
driver.click(logout_button)
|
62
|
+
end
|
63
|
+
|
64
|
+
def quit
|
65
|
+
driver.quit
|
66
|
+
end
|
67
|
+
end
|
68
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module YoptaSwitcher
|
2
|
+
module Operations
|
3
|
+
class TurnOff
|
4
|
+
attr_reader :client, :login, :password
|
5
|
+
|
6
|
+
def initialize(client:, login:, password:)
|
7
|
+
@client = client
|
8
|
+
@login = login
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
client.login(login: login, password: password)
|
14
|
+
client.set_lowest_subscription_level
|
15
|
+
client.apply_selected_subscription_level
|
16
|
+
client.logout
|
17
|
+
client.quit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module YoptaSwitcher
|
2
|
+
module Operations
|
3
|
+
class TurnOn
|
4
|
+
attr_reader :client, :login, :password
|
5
|
+
|
6
|
+
def initialize(client:, login:, password:)
|
7
|
+
@client = client
|
8
|
+
@login = login
|
9
|
+
@password = password
|
10
|
+
end
|
11
|
+
|
12
|
+
def call
|
13
|
+
client.login(login: login, password: password)
|
14
|
+
client.set_highest_subscription_level
|
15
|
+
client.apply_selected_subscription_level
|
16
|
+
client.logout
|
17
|
+
client.quit
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
@@ -0,0 +1,42 @@
|
|
1
|
+
module YoptaSwitcher
|
2
|
+
class SeleniumDriverAdapter
|
3
|
+
attr_reader :driver, :wait_instance
|
4
|
+
|
5
|
+
def initialize(driver:, wait_instance:)
|
6
|
+
@driver = driver
|
7
|
+
@wait_instance = wait_instance
|
8
|
+
end
|
9
|
+
|
10
|
+
def visit(url)
|
11
|
+
driver.navigate.to(url)
|
12
|
+
end
|
13
|
+
|
14
|
+
def wait(&block)
|
15
|
+
wait_instance.until(&block)
|
16
|
+
end
|
17
|
+
|
18
|
+
def fill_in(element, input_string)
|
19
|
+
element.send_keys(input_string)
|
20
|
+
end
|
21
|
+
|
22
|
+
def find_element(finder_args)
|
23
|
+
driver.find_element(finder_args)
|
24
|
+
end
|
25
|
+
|
26
|
+
def click(element)
|
27
|
+
element.click
|
28
|
+
end
|
29
|
+
|
30
|
+
def submit(element)
|
31
|
+
element.submit
|
32
|
+
end
|
33
|
+
|
34
|
+
def clear(element)
|
35
|
+
element.clear
|
36
|
+
end
|
37
|
+
|
38
|
+
def quit
|
39
|
+
driver.quit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
end
|
metadata
ADDED
@@ -0,0 +1,169 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: yopta_switcher
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.1.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Alexander Panasyuk
|
8
|
+
autorequire:
|
9
|
+
bindir: exe
|
10
|
+
cert_chain: []
|
11
|
+
date: 2017-06-28 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: selenium-webdriver
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - "~>"
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '3.4'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - "~>"
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '3.4'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: bundler
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - "~>"
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '1.15'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - "~>"
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '1.15'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: rake
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - "~>"
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '10.0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - "~>"
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '10.0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: minitest
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '5.0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '5.0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: pry-byebug
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '3.4'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '3.4'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: guard
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - "~>"
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '2.14'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - "~>"
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '2.14'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: guard-minitest
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - "~>"
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '2.4'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - "~>"
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '2.4'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: minitest-stub_any_instance
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - '='
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: 1.0.1
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - '='
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: 1.0.1
|
125
|
+
description: Switches Internet access subscription terms. Works for one anonymous
|
126
|
+
ISP.
|
127
|
+
email:
|
128
|
+
- panasmeister@gmail.com
|
129
|
+
executables:
|
130
|
+
- yopta_switcher
|
131
|
+
extensions: []
|
132
|
+
extra_rdoc_files: []
|
133
|
+
files:
|
134
|
+
- "./lib/yopta_switcher.rb"
|
135
|
+
- "./lib/yopta_switcher/cli.rb"
|
136
|
+
- "./lib/yopta_switcher/cli/operation_builder.rb"
|
137
|
+
- "./lib/yopta_switcher/cli/options.rb"
|
138
|
+
- "./lib/yopta_switcher/cli/options_parser.rb"
|
139
|
+
- "./lib/yopta_switcher/client.rb"
|
140
|
+
- "./lib/yopta_switcher/operations/turn_off.rb"
|
141
|
+
- "./lib/yopta_switcher/operations/turn_on.rb"
|
142
|
+
- "./lib/yopta_switcher/selenium_driver_adapter.rb"
|
143
|
+
- "./lib/yopta_switcher/version.rb"
|
144
|
+
- exe/yopta_switcher
|
145
|
+
homepage: https://github.com/panasyuk/yopta_switcher
|
146
|
+
licenses:
|
147
|
+
- MIT
|
148
|
+
metadata: {}
|
149
|
+
post_install_message:
|
150
|
+
rdoc_options: []
|
151
|
+
require_paths:
|
152
|
+
- lib
|
153
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
154
|
+
requirements:
|
155
|
+
- - ">="
|
156
|
+
- !ruby/object:Gem::Version
|
157
|
+
version: '0'
|
158
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
159
|
+
requirements:
|
160
|
+
- - ">="
|
161
|
+
- !ruby/object:Gem::Version
|
162
|
+
version: '0'
|
163
|
+
requirements: []
|
164
|
+
rubyforge_project:
|
165
|
+
rubygems_version: 2.6.11
|
166
|
+
signing_key:
|
167
|
+
specification_version: 4
|
168
|
+
summary: Enables automation of switching subscription terms
|
169
|
+
test_files: []
|