Class: TurksatkabloCli::OnlineOperations::Agent

Inherits:
Object
  • Object
show all
Includes:
Helpers
Defined in:
lib/turksatkablo_cli/online_operations/agent.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

#add_line, #agent, #check_is_installed?, #check_ruby_version, #internet_connection?, #require_all, #which

Constructor Details

#initializeAgent

Returns a new instance of Agent.



10
11
12
13
14
15
16
17
18
# 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

Instance Attribute Details

#fail_login_attemptObject

Returns the value of attribute fail_login_attempt.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def 
  @fail_login_attempt
end

#has_logged_inObject

Returns the value of attribute has_logged_in.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def has_logged_in
  @has_logged_in
end

#login_chooseObject

Returns the value of attribute login_choose.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def 
  @login_choose
end

#passwordObject

Returns the value of attribute password.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def password
  @password
end

#radio_btn_valueObject

Returns the value of attribute radio_btn_value.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def radio_btn_value
  @radio_btn_value
end

#sessionObject

Returns the value of attribute session.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def session
  @session
end

#usernameObject

Returns the value of attribute username.



7
8
9
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 7

def username
  @username
end

Instance Method Details

#authenticated?Boolean

Returns:

  • (Boolean)


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 24

def authenticated?
  begin
    if has_logged_in?
      true
    else
      auth = TurksatkabloCli::OnlineOperations::Auth.instance
      (auth)

      if has_logged_in?
        true
      else
        user_authenticated? if @fail_login_attempt == 0
      end
    end
  rescue Exception => e
    false
  end

end

#end_sessionObject



66
67
68
69
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 66

def end_session
  @session.driver.quit
  @session = nil
end

#get_loginObject



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 44

def 
  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. = chosen
      self.radio_btn_value = @login_type[chosen][:radio_btn_value]

      user_authenticated?
    end
  end
end

#has_logged_in?Boolean

Returns:

  • (Boolean)


20
21
22
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 20

def has_logged_in?
  self.has_logged_in
end

#retry_authenticateObject



75
76
77
78
79
80
81
82
83
84
85
# 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

#screenshotObject



71
72
73
# File 'lib/turksatkablo_cli/online_operations/agent.rb', line 71

def screenshot
  @session.save_screenshot
end

#user_authenticated?Boolean

Returns:

  • (Boolean)


87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
# 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

        
      end
    else
      retry_authenticate
    end

  rescue Exception => e
    retry_authenticate
  end
end