class USPassportTracker::Track
Core Implementations
Constants
- ACTION_BUTTON
- CHROME_OPTIONS
- OPTIONS
- PASSPORT_INPUT
- TRACKER_URL
Attributes
country_code[RW]
country_name[RW]
passport_number[RW]
response_text[RW]
root_url[RW]
screenshot_enabled[RW]
screenshot_filename[RW]
Public Class Methods
new(passport_number, country_code = 'GH', screenshot_enabled = false)
click to toggle source
# File lib/us_passport_tracker.rb, line 24 def initialize(passport_number, country_code = 'GH', screenshot_enabled = false) @passport_number = passport_number @country_code = country_code.downcase @screenshot_enabled = screenshot_enabled @driver = Selenium::WebDriver.for(:chrome, options: CHROME_OPTIONS) @root_url = "http://www.ustraveldocs.com/#{@country_code}/index.html?firstTime=No" end
Public Instance Methods
ready_for_pickup?()
click to toggle source
# File lib/us_passport_tracker.rb, line 48 def ready_for_pickup? return false if @response_text.nil? @response_text.include? 'ready' end
status()
click to toggle source
# File lib/us_passport_tracker.rb, line 36 def status @driver.navigate.to @root_url @driver.get "#{TRACKER_URL}?country=#{uri_country_name}&language=en" @driver.find_element(id: PASSPORT_INPUT).send_keys(@passport_number) @driver.find_element(id: ACTION_BUTTON).click sleep 2 # Wait for Result to show take_screenshot if @screenshot_enabled @response_text = @driver.find_element(class: 'result').text stop_driver @response_text end
Private Instance Methods
stop_driver()
click to toggle source
# File lib/us_passport_tracker.rb, line 62 def stop_driver @driver.quit end
take_screenshot()
click to toggle source
# File lib/us_passport_tracker.rb, line 66 def take_screenshot @screenshot_filename = 'PassportTrackerScreenshot.png' @driver.save_screenshot @screenshot_filename end
uri_country_name()
click to toggle source
# File lib/us_passport_tracker.rb, line 55 def uri_country_name uri = URI(@driver.find_element(id: 'login').attribute('href')) params = CGI.parse(uri.query) @country_name = CGI.unescape(params['country'].first) params['country'].first end