turksatkablo_cli 0.1.3 → 0.1.4

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: 311eaf860709698d53cc493af1066842ae00f6bd
4
- data.tar.gz: 27ae9da5b9c30f17edb31ad0316c8d6c37838489
3
+ metadata.gz: 1230eb0c37e81a750dac3f03c0e635b6f778e8d8
4
+ data.tar.gz: b79102395e62f1f9a992376f7472400094944f08
5
5
  SHA512:
6
- metadata.gz: 41fbb59695a2bf141327fd1ba0b75fe3f60795968d7cae8b7a60be4e97172d65449930f8192beb4bfd4f5c1d0037f8a23575940dcd899d6b5d201e2928147137
7
- data.tar.gz: 179f8727dcadd54a16b5490d5521803750aa0b01dd2c6a7178cbcc4043ac80e05a01e21735a94e73836b349ed2cdb29a96aa47a6eba8eb8d2474942d3d05c00a
6
+ metadata.gz: a490e09b11ba616bb24d4ce2f8163e400a41eaaa2e02ecbfe052e317d0938c85cc83c9351270e32bc32e8282fa5b78ba95a2481c9cee119c0f007b0b4ebaa35c
7
+ data.tar.gz: ffe7d6086cb40e455c8e82641cc706aff80efe25817136c9427d92a876aaa21303e4db657fa0ec314cf9353472bb9a7d20a0a14dd8fdeda528419b1391bab84b
data/.gitignore CHANGED
@@ -33,5 +33,3 @@ Gemfile.lock
33
33
 
34
34
  # Dotenv
35
35
  .env
36
-
37
- .byebug_history
data/README.md CHANGED
@@ -1,5 +1,6 @@
1
1
  Turksat Kablo CLI :black_medium_square:
2
2
  =================
3
+ [![Gem Version](https://badge.fury.io/rb/turksatkablo_cli.svg)](https://badge.fury.io/rb/turksatkablo_cli)
3
4
 
4
5
  A command-line interface for the Turksat Kablo Online Islemler - https://online.turksatkablo.com.tr/
5
6
 
@@ -10,7 +11,8 @@ A command-line interface for the Turksat Kablo Online Islemler - https://online.
10
11
 
11
12
  ## Setup
12
13
 
13
- turksatkablo_cli supports Ruby (MRI) 2.0+
14
+ turksatkablo_cli is built with Ruby, so you'll need a working Ruby 2.1.0>= environment to use it. You can find Ruby installation instructions [here](https://www.ruby-lang.org/en/installation/).
15
+
14
16
 
15
17
  1. Install via rubygems
16
18
 
@@ -38,3 +40,15 @@ turksatkablo kotadetay # Son 3 ayın günlük takibi v.s
38
40
  turksatkablo musterino # Müşteri no - kısa kodu mn
39
41
  turksatkablo ozet # Hizmetler genel durum - kısa kodu o
40
42
  ```
43
+
44
+ ### Changelog
45
+
46
+ + 0.1.4 – Fix retry_authenticate and authenticated? methods, login details could not be saved when base url was not reachable
47
+ + 0.1.3 – Modernize multiple classes, add `ozet`, `hizmetler`, `musterino`, `kampanya`, `anlikborc` commands
48
+ + 0.1.2 – Modernize Agent and Auth classes, ability to save user's encrypted login details, add `kota` command.
49
+ + 0.1.1 – Build app skeleton, implement basic authentication
50
+ + 0.1.0 - Initial version.
51
+
52
+ ### Contributing
53
+
54
+ turksatkablo_cli is open source, and contributions are very welcome!
@@ -20,7 +20,11 @@ end
20
20
  at_exit{
21
21
  # cleanup temp files
22
22
  # close open connections
23
- Capybara.current_session.driver.quit
23
+ begin
24
+ Capybara.current_session.driver.quit
25
+ rescue Exception => e
26
+ abort "turksatkablo_cli requires phantomjs https://github.com/rokumatsumoto/turksatkablo_cli#setup"
27
+ end
24
28
  }
25
29
 
26
30
  TurksatkabloCli.main
@@ -5,7 +5,11 @@ require 'capybara/poltergeist'
5
5
  # See more options at https://github.com/teampoltergeist/poltergeist#customization
6
6
  options = { js_errors: false, phantomjs_options: ['--load-images=no', '--ignore-ssl-errors=yes'] }
7
7
  Capybara.register_driver :poltergeist do |app|
8
- Capybara::Poltergeist::Driver.new(app, options)
8
+ begin
9
+ Capybara::Poltergeist::Driver.new(app, options)
10
+ rescue Exception => e
11
+ abort "turksatkablo_cli requires phantomjs https://github.com/rokumatsumoto/turksatkablo_cli#setup"
12
+ end
9
13
  end
10
14
 
11
15
  # Configure Capybara to use Poltergeist as the driver
@@ -1,12 +1,11 @@
1
1
  require 'highline'
2
2
 
3
-
4
3
  module TurksatkabloCli
5
4
  module OnlineOperations
6
5
  class Agent
7
6
  include Helpers
8
7
  attr_accessor :login_choose, :username, :password, :radio_btn_value,
9
- :fail_login_attempt, :session
8
+ :fail_login_attempt, :session, :has_logged_in, :auth
10
9
 
11
10
  def initialize
12
11
  @session = Capybara::Session.new(:poltergeist)
@@ -15,27 +14,26 @@ module TurksatkabloCli
15
14
  email: {username_label: "E-mail", password_label: "Şifre", radio_btn_value: 4},
16
15
  ceptelefonu: {username_label: "Cep Telefonu (Başında 0 olmadan 10 haneli olmalı.)", password_label: "Şifre", radio_btn_value: 5} }
17
16
  @fail_login_attempt = 0
17
+ @has_logged_in = false
18
+ end
18
19
 
20
+ def has_logged_in?
21
+ agent.has_logged_in
19
22
  end
20
23
 
21
24
  def authenticated?
22
25
  begin
23
- if agent.session.current_url != Enums::BASE_URL_SUCCESS
26
+ if has_logged_in?
27
+ true
28
+ else
24
29
  auth = TurksatkabloCli::OnlineOperations::Auth.instance
25
30
  set_login_data(auth)
26
31
 
27
- if agent.session.current_url != Enums::BASE_URL
28
- if agent.user_authenticated?
29
- true
30
- else
31
- false
32
- end
33
- else
32
+ if has_logged_in?
34
33
  true
34
+ else
35
+ user_authenticated? if @fail_login_attempt == 0
35
36
  end
36
-
37
- else
38
- true
39
37
  end
40
38
  rescue Exception => e
41
39
  false
@@ -65,7 +63,6 @@ module TurksatkabloCli
65
63
  end
66
64
 
67
65
 
68
-
69
66
  def end_session
70
67
  @session.driver.quit
71
68
  @session = nil
@@ -76,53 +73,49 @@ module TurksatkabloCli
76
73
  end
77
74
 
78
75
  def retry_authenticate
79
- if (@fail_login_attempt == 0)
76
+ if @fail_login_attempt == 0
80
77
  puts "Türksat Kablo Online İşlemler sayfasına şuan ulaşılamıyor, tekrar deniyoruz..."
81
78
  @fail_login_attempt = 1
82
79
 
83
80
  user_authenticated?
84
81
  else
85
82
  puts "Türksat Kablo Online İşlemler sayfasına şuan ulaşılamıyor."
86
- @fail_login_attempt = 0
87
-
88
83
  false
89
84
  end
90
85
  end
91
86
 
92
87
  def user_authenticated?
93
88
  begin
94
- if @session.current_url != Enums::BASE_URL_SUCCESS
95
- visit_status = @session.visit(Enums::BASE_URL)
96
- if visit_status["status"] == 'success' && @session.current_url == Enums::BASE_URL
97
- @fail_login_attempt = 0
98
- puts "#{Enums::BASE_URL} adresine erişim başarılı. Giriş yapılıyor..."
99
89
 
100
- @session.find(:css, "div.radio-container div:nth-child(#{self.radio_btn_value}) > label").click
101
- kullanici_id = @session.find('input#KullaniciID')
102
- kullanici_id.send_keys(self.username)
90
+ visit_status = @session.visit(Enums::BASE_URL)
103
91
 
104
- kullanici_sifre = @session.find('input#KullaniciSifre')
105
- kullanici_sifre.send_keys(self.password)
92
+ if visit_status["status"] == 'success' && @session.current_url == Enums::BASE_URL
93
+ @fail_login_attempt = 0
94
+ puts "#{Enums::BASE_URL} adresine erişim başarılı. Giriş yapılıyor..."
106
95
 
107
- @session.find_link(id: 'Button1').click
96
+ @session.find(:css, "div.radio-container div:nth-child(#{self.radio_btn_value}) > label").click
97
+ kullanici_id = @session.find('input#KullaniciID')
98
+ kullanici_id.send_keys(self.username)
108
99
 
109
- if @session.current_url == Enums::BASE_URL_SUCCESS
110
- puts "\nGiriş işlemi başarılı"
111
- add_line
100
+ kullanici_sifre = @session.find('input#KullaniciSifre')
101
+ kullanici_sifre.send_keys(self.password)
112
102
 
103
+ @session.find_link(id: 'Button1').click
113
104
 
114
- true
115
- else
116
- puts "\nGiriş bilgileriniz hatalı, kontrol ederek tekrar deneyiniz."
117
- add_line
105
+ if @session.current_url == Enums::BASE_URL_SUCCESS
106
+ puts "\nGiriş işlemi başarılı"
107
+ add_line
108
+ self.has_logged_in = true
118
109
 
119
- get_login
120
- end
110
+ true
121
111
  else
122
- retry_authenticate
112
+ puts "\nGiriş bilgileriniz hatalı, kontrol ederek tekrar deneyiniz."
113
+ add_line
114
+
115
+ get_login
123
116
  end
124
117
  else
125
- true
118
+ retry_authenticate
126
119
  end
127
120
 
128
121
  rescue Exception => e
@@ -130,15 +123,20 @@ module TurksatkabloCli
130
123
  end
131
124
  end
132
125
 
133
- private
134
- def set_login_data(auth)
135
- if auth.login_data.kind_of?(Hash)
126
+ private
127
+ def set_login_data(auth)
128
+ if auth.login_data.kind_of?(Hash) && !has_login_data?
136
129
  agent.username = auth.login_data[:username]
137
130
  agent.password = auth.login_data[:password]
138
131
  agent.radio_btn_value = auth.login_data[:radio_btn_value]
132
+ end
133
+ end
139
134
 
135
+ def has_login_data?
136
+ if agent.username.nil? || agent.password.nil? || agent.radio_btn_value.nil?
137
+ false
140
138
  else
141
-
139
+ true
142
140
  end
143
141
  end
144
142
 
@@ -8,7 +8,8 @@ module TurksatkabloCli
8
8
  class Auth
9
9
  include Singleton
10
10
  include Helpers
11
- attr_reader :path, :login_type, :login_data
11
+ attr_reader :path, :login_type
12
+ attr_accessor :login_data
12
13
 
13
14
  FILE_NAME = '.turksatkablo'.freeze
14
15
  KEY = "m\x13\x95\xBE6\x81\xEEN\xE6\xDC\xA0\x83K\xE8X2\a\xD7\xB2\x94L\xF2\xEC\xF9\x80\x9F_\xDB\xDB\xD05\v".freeze
@@ -16,23 +17,28 @@ module TurksatkabloCli
16
17
 
17
18
  def initialize
18
19
  @path = File.join(File.expand_path('~'), FILE_NAME)
20
+
19
21
  @login_data = get
20
22
  end
21
23
 
24
+ def save_login_info
25
+ login_info = { :radio_btn_value => agent.radio_btn_value, :username => agent.username,
26
+ :password => agent.password }
27
+
28
+ save_file(login_info) if @path
29
+ puts "Bilgileriniz bilgisayarınızda şifrelenerek saklandı." if File.exists?(@path)
22
30
 
23
- def get
31
+ login_info
32
+ end
33
+
34
+ def get
24
35
  return read_file if File.exists?(@path)
25
36
  begin
26
37
  if agent.get_login
38
+ save_login_info
27
39
 
28
- login_info = { :radio_btn_value => agent.radio_btn_value, :username => agent.username,
29
- :password => agent.password }
30
-
31
- save_file(login_info) if @path
32
- puts "Bilgileriniz bilgisayarınızda şifrelenerek saklandı." if File.exists?(@path)
33
- login_info
34
- end
35
- rescue Exception => e
40
+ end
41
+ rescue Exception => e
36
42
  puts "Bir sorun oluştu."
37
43
  end
38
44
  end
@@ -1,5 +1,5 @@
1
1
  module TurksatkabloCli
2
2
  module OnlineOperations
3
- VERSION = "0.1.3"
3
+ VERSION = "0.1.4"
4
4
  end
5
5
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: turksatkablo_cli
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.3
4
+ version: 0.1.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samet Gunaydin
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2017-11-28 00:00:00.000000000 Z
11
+ date: 2017-12-02 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler