class FbErrorMachine::GraphErrorScraper

Public Class Methods

scrape_graph_api_errors(version="2.7") click to toggle source
# File lib/fb_error_machine/graph_error_scraper.rb, line 4
def self.scrape_graph_api_errors(version="2.7")
  browser = Watir::Browser.new :phantomjs
  browser.goto("https://developers.facebook.com/docs/graph-api/using-graph-api/v#{version}")

  error_table = browser.table(xpath: '//*[@id="u_0_0"]/div/span/div/div[8]/div/div[1]/table')
  error_rows = error_table.rows.to_a
  error_rows.shift

  auth_table = browser.table(xpath: '//*[@id="u_0_0"]/div/span/div/div[8]/div/div[2]/table')
  auth_rows = auth_table.rows.to_a
  auth_rows.shift

  rows = error_rows + auth_rows
  errors = []

  rows.each do |row|
    errors << {
      error_code: ErrorWriter.find_error_code(row),
      description: ErrorWriter.find_description(row),
      instructions: ErrorWriter.find_instructions(row),
    }
  end

  browser.close
  ErrorWriter.write_errors(type: 'graph', errors: errors)
end