class TurksatkabloCli::OnlineOperations::Agent
Attributes
fail_login_attempt[RW]
has_logged_in[RW]
login_choose[RW]
password[RW]
radio_btn_value[RW]
session[RW]
username[RW]
Public Class Methods
new()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 10 def initialize @session = Capybara::Session.new(:poltergeist) @login_type = { musterino: {username_label: "Müşteri No", password_label: "Şifre", radio_btn_value: 1}, tckimlikno: {username_label: "T.C. Kimlik No", password_label: "Şifre", radio_btn_value: 2}, email: {username_label: "E-mail", password_label: "Şifre", radio_btn_value: 4}, ceptelefonu: {username_label: "Cep Telefonu (Başında 0 olmadan 10 haneli olmalı.)", password_label: "Şifre", radio_btn_value: 5} } @fail_login_attempt = 0 @has_logged_in = false end
Public Instance Methods
authenticated?()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 24 def authenticated? begin if has_logged_in? true else auth = TurksatkabloCli::OnlineOperations::Auth.instance set_login_data(auth) if has_logged_in? true else user_authenticated? if @fail_login_attempt == 0 end end rescue Exception => e false end end
end_session()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 66 def end_session @session.driver.quit @session = nil end
get_login()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 44 def get_login cli = HighLine.new cli.say("Kablo TV Giriş") cli.say("* Bilgileriniz daha sonraki girişleriniz için bilgisayarınızda şifrelenerek saklanacaktır.") cli.choose do |menu| menu.prompt = 'Abonesi olduğunuz Türksat hizmetleri ile ilgili giriş türü seçiniz: ' menu.choices(*@login_type.keys) do |chosen| self.username = cli.ask(@login_type[chosen][:username_label]) self.password = cli.ask(@login_type[chosen][:password_label]) { |q| q.echo = "*" } self.login_choose = chosen self.radio_btn_value = @login_type[chosen][:radio_btn_value] user_authenticated? end end end
has_logged_in?()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 20 def has_logged_in? self.has_logged_in end
retry_authenticate()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 75 def retry_authenticate if @fail_login_attempt == 0 puts "Türksat Kablo Online İşlemler sayfasına şuan ulaşılamıyor, tekrar deniyoruz..." @fail_login_attempt = 1 user_authenticated? else puts "Türksat Kablo Online İşlemler sayfasına şuan ulaşılamıyor." false end end
screenshot()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 71 def screenshot @session.save_screenshot end
user_authenticated?()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 87 def user_authenticated? begin visit_status = @session.visit(Enums::BASE_URL) if visit_status["status"] == 'success' && @session.current_url == Enums::BASE_URL @fail_login_attempt = 0 puts "#{Enums::BASE_URL} adresine erişim başarılı. Giriş yapılıyor..." @session.find(:css, "div.radio-container div:nth-child(#{self.radio_btn_value}) > label").click kullanici_id = @session.find('input#KullaniciID') kullanici_id.send_keys(self.username) kullanici_sifre = @session.find('input#KullaniciSifre') kullanici_sifre.send_keys(self.password) @session.find_link(id: 'Button1').click if @session.current_url == Enums::BASE_URL_SUCCESS puts "\nGiriş işlemi başarılı" add_line self.has_logged_in = true true else puts "\nGiriş bilgileriniz hatalı, kontrol ederek tekrar deneyiniz." add_line get_login end else retry_authenticate end rescue Exception => e retry_authenticate end end
Private Instance Methods
has_login_data?()
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 135 def has_login_data? if self.username.nil? || self.password.nil? || self.radio_btn_value.nil? false else true end end
set_login_data(auth)
click to toggle source
# File lib/turksatkablo_cli/online_operations/agent.rb, line 127 def set_login_data(auth) if auth.login_data.kind_of?(Hash) && !has_login_data? self.username = auth.login_data[:username] self.password = auth.login_data[:password] self.radio_btn_value = auth.login_data[:radio_btn_value] end end