Module: NetworkConnector
- Defined in:
- lib/network_connector.rb,
lib/network_connector/version.rb
Defined Under Namespace
Classes: Error
Constant Summary collapse
- VERSION =
"0.1.1"- @@tries =
3- @@connected =
false
Class Method Summary collapse
Class Method Details
.connect ⇒ Object
56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 |
# File 'lib/network_connector.rb', line 56 def connect begin url = ENV["HOST"] browser = Watir::Browser.new :safari browser.goto(url) browser.send_keys :enter credentials = [ {path: {id: ENV["INPUT_USERNAME_ID"]}, value: ENV["USERNAME"]}, {path: {id: ENV["INPUT_PASSWORD_ID"]}, value: ENV["PASSWORD"]} ] = ENV["SUBMIT_BTN"] credentials.each do |element| text_field = browser.text_field(element[:path]) text_field.set element[:value] end browser.wait(20) browser.input({id: }).click if ENV["HAS_CONFIRMATION_BUTTON"].eql?("true") browser.input({id: ENV["CONFIRMATION_BUTTON"]}).click browser.wait(30) end browser.close rescue => exception puts "Ooops ! \n" \ "Please make sure that you are connected to the private wifi\n".red end end |
.connected? ⇒ Boolean
27 28 29 |
# File 'lib/network_connector.rb', line 27 def connected? @@connected end |
.has_internet? ⇒ Boolean
52 53 54 |
# File 'lib/network_connector.rb', line 52 def has_internet? Net::Ping::TCP.new("google.com", 'http').ping? end |
.start ⇒ Object
31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/network_connector.rb', line 31 def start @@connected = has_internet? unless @@connected @@tries -= 1 connect if @@tries.eql?(0) puts "Ooops ! \n" \ "We're sorry ! We've tried 3 times it failed \n" \ "- Verify that you set all correct for network informations \n" \ "- Perhaps the connection process is not support. \nIf so email us so we try to integrate it \n".red else start end else puts "Great ! You're connected !".green puts "Developed ❤️ by @katakeynii!" @@connected = false end end |
.tries ⇒ Object
23 24 25 |
# File 'lib/network_connector.rb', line 23 def tries @@tries end |