Sha256: bdba0a57ab4c8e33cf68ddd52e827a07c68734cafc6a932a7d6e8aa0376b5411

Contents?: true

Size: 1.04 KB

Versions: 8

Compression:

Stored size: 1.04 KB

Contents

require 'selenium-webdriver'

require_relative './authenticator'
require_relative './message_handler'
require_relative './cookie_handler'

class FacebookConnection
  attr_reader :headless

  def initialize(headless:)
    @headless = headless

    cookie_handler.load
  end

  def login
    authenticator = Authenticator.new(driver)
    authenticator.login
  end

  def close
    cookie_handler.save
  end

  def message_handler
    @message_handler ||= MessageHandler.new(driver)
  end

  def driver
    return @driver if defined? @driver

    options = Selenium::WebDriver::Chrome::Options.new
    options.add_argument('--disable-notifications')
    options.add_argument('--no-sandbox')
    options.add_argument('--disable-dev-shm-usage')
    options.add_argument('--headless') if headless
    options.add_option('detach', true) unless headless

    @driver = Selenium::WebDriver.for :chrome, options: options

    @driver.manage.window.resize_to(1920, 1080)

    @driver
  end

  def cookie_handler
    @cookie_handler ||= CookieHandler.new(driver)
  end
end

Version data entries

8 entries across 8 versions & 1 rubygems

Version Path
fuck_facebook-0.5.4 src/facebook_connection.rb
fuck_facebook-0.5.3 src/facebook_connection.rb
fuck_facebook-0.5.2 src/facebook_connection.rb
fuck_facebook-0.5.1 src/facebook_connection.rb
fuck_facebook-0.5.0 src/facebook_connection.rb
fuck_facebook-0.4.1 src/facebook_connection.rb
fuck_facebook-0.4.0 src/facebook_connection.rb
fuck_facebook-0.3.0 src/facebook_connection.rb