Class: OKCupid::Authentication
- Inherits:
-
Object
- Object
- OKCupid::Authentication
- Defined in:
- lib/lonely_coder/authentication.rb
Instance Method Summary collapse
- #change_to_using_simpler_parser(browser) ⇒ Object
-
#initialize(username, password, browser) ⇒ Authentication
constructor
A new instance of Authentication.
- #restore_default_parser(browser) ⇒ Object
- #success? ⇒ Boolean
Constructor Details
#initialize(username, password, browser) ⇒ Authentication
Returns a new instance of Authentication.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 |
# File 'lib/lonely_coder/authentication.rb', line 10 def initialize(username, password, browser) change_to_using_simpler_parser(browser) browser.post("https://www.okcupid.com/login", { username: username, password: password, okc_api: 1 }) body = JSON.parse(browser.page.body) # body['screenname'] will be `nil` for failed auth # and equal to the supplied username for success. # there may be other cases? @success = body['screenname'] != nil restore_default_parser(browser) end |
Instance Method Details
#change_to_using_simpler_parser(browser) ⇒ Object
33 34 35 |
# File 'lib/lonely_coder/authentication.rb', line 33 def change_to_using_simpler_parser(browser) browser.pluggable_parser.html = AuthenticationParser end |
#restore_default_parser(browser) ⇒ Object
37 38 39 |
# File 'lib/lonely_coder/authentication.rb', line 37 def restore_default_parser(browser) browser.pluggable_parser.html = Mechanize::Page end |
#success? ⇒ Boolean
29 30 31 |
# File 'lib/lonely_coder/authentication.rb', line 29 def success? @success end |