class OpengraphTransporter::Browser
Constants
- DEFAULT_PRIMARY_LOCALE
- MAX_TRANSLATION_PAGE_LIMIT
Public Class Methods
export()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 9 def export begin Watir.driver = :webdriver @browser = Watir::Browser.new :firefox @page_index_counter = 0 @translation_count_index = 0 @translation = Base.translation @translation_arr = @translation [:dst_translation_arr].clone fb_login if @translation[:primary_locale].nil? primary_locale = DEFAULT_PRIMARY_LOCALE end developer_translations_home_uri = "https://www.facebook.com/translations/admin/browse.php?search=&sloc=#{primary_locale}&aloc=#{@translation[:app_locale]}&app=#{@translation[:destination_application_id]}" @browser.goto developer_translations_home_uri GracefulQuit.enable parse_translation_rows rescue Exception => e say("An error occurred when generating automated browser, do you have FireFox installed? \n\n error: #{e}.") exit end end
Private Class Methods
complete_translations_process()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 72 def complete_translations_process fb_logout open_graph_translations_stats end
fb_login()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 77 def fb_login say("\n.....logging into Facebook") @browser.goto "https://www.facebook.com" @browser.text_field(id: "email").set Base.user[:fb_username] @browser.text_field(id: "pass").set Base.user[:fb_password] @browser.label(id: "loginbutton").click end
fb_logout()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 85 def fb_logout say(".....logging out of Facebook \n") @browser.div(id: "userNavigationLabel").click @browser.label(class: "uiLinkButton navSubmenu").click @browser.close end
open_graph_translations_stats()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 92 def open_graph_translations_stats say("<%= color('\n***********************************************************************************************************', GREEN, BOLD) %>") say("Source Application: <%= color('#{@translation[:src_app_name]}', GREEN, BOLD) %>") say("Destination Application: <%= color('#{@translation[:dst_app_name]}', GREEN, BOLD) %>") say("Export completed: <%= color('#{@translation[:dst_translation_arr].length} Open Graph translations processed', GREEN, BOLD) %>") say("<%= color('***********************************************************************************************************\n', GREEN, BOLD) %>") end
parse_translation_rows()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 36 def parse_translation_rows @translation_arr.each_with_index do |translation, index| row_hash = "variant:" << translation[:native_hash] translation_row = @browser.tr(:id, row_hash) if translation_row.exists? && !translation[:translation].empty? say("updating translation native hash: #{translation[:native_hash]} : #{translation[:translation]}") translation_row.td(:class, /s_trans/).click translation_row.textarea(:class, /uiTextareaAutogrow/).set translation[:translation] translation_row.button(:id, /submit:/).click sleep(0.25) @translation_count_index += 1 end GracefulQuit.check end process_next_page end
process_next_page()
click to toggle source
# File lib/opengraph_transporter/browser.rb, line 53 def process_next_page next_button = @browser.div(:class => "pagerpro_container").link(:text => /Next/) if next_button.exists? && @page_index_counter < MAX_TRANSLATION_PAGE_LIMIT begin translations_page = @page_index_counter + 1 say("processing translation page.... #{translations_page + 1}") @page_index_counter += 1 next_button.click sleep(2.5) parse_translation_rows rescue Exception => e say("Translation error: #{e}, carry on.") parse_translation_rows end else complete_translations_process end end