You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

slack_client.rb 1.1KB

1234567891011121314151617181920212223242526272829303132333435363738394041
  1. require 'selenium-webdriver'
  2. module SlackMattermostEmoji
  3. class SlackClient
  4. def initialize(username:, password:, domain:)
  5. @username = username
  6. @password = password
  7. @domain = domain
  8. @authenticated = false
  9. options = Selenium::WebDriver::Chrome::Options.new
  10. options.headless!
  11. @driver = Selenium::WebDriver.for :chrome, options: options
  12. if [@username, @password, @domain].any? { |el| el.nil? || el.empty? }
  13. raise 'Slack username, password, and domain are all required'
  14. end
  15. end
  16. def authenticate
  17. @driver.navigate.to "https://#{@domain}"
  18. @driver.find_element(name: 'email').send_keys(@username)
  19. @driver.find_element(name: 'password').send_keys(@password)
  20. @driver.find_element(id: 'signin_btn').click
  21. begin
  22. @driver.find_element(css: 'p.alert.alert_error')
  23. raise 'Invalid credentials'
  24. rescue Selenium::WebDriver::Error::NoSuchElementError
  25. nil
  26. end
  27. @authenticated = true
  28. end
  29. def authenticated?
  30. @authenticated
  31. end
  32. end
  33. end