Module: Login
- Included in:
- ClassMethods
- Defined in:
- lib/botinsta/login.rb
Overview
Contains login and logout methods for the bot.
Instance Method Summary collapse
-
#login ⇒ Object
Login method to log the user in.
-
#logout ⇒ Object
Prints action sum and then logs the user out.
Instance Method Details
#login ⇒ Object
Login method to log the user in. Prints success message on successful login,
error message otherwise.
10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/botinsta/login.rb', line 10 def login @agent = Mechanize.new # Navigate to classic login page login_page = @agent.get 'https://www.instagram.com/accounts/login/?force_classic_login' # Get the login form login_form = login_page.forms.first # Fill in the login form login_form['username'] = @username login_form['password'] = @password # Submit the form and if couldn't login raise an exception. (action: :login) response = login_form.submit if response.code != 200 && response.body.include?('not-logged-in') login_status = false else (result: :success, username: @username) login_status = true end raise StandardError unless login_status rescue StandardError (result: :error, username: @username) # TODO: logger to log these kind of stuff exit end |
#logout ⇒ Object
Prints action sum and then logs the user out.
43 44 45 46 47 |
# File 'lib/botinsta/login.rb', line 43 def logout print_action_sum (action: :logout) @agent.get 'https://instagram.com/accounts/logout/' end |