Class: Argosnap::Fetch
- Inherits:
-
Object
- Object
- Argosnap::Fetch
- Defined in:
- lib/argosnap/balance.rb
Overview
Given username and a password, fetch balance from www.tarsnap.com
Instance Method Summary collapse
-
#balance ⇒ Object
Fetch balance from tarsnap using.
-
#check_configuration ⇒ Object
Elementary configuration file check.
-
#check_login_errors(data) ⇒ Object
check for login errors.
Instance Method Details
#balance ⇒ Object
Fetch balance from tarsnap using
33 34 35 36 37 38 39 40 41 42 43 44 45 |
# File 'lib/argosnap/balance.rb', line 33 def balance check_configuration agent = Mechanize.new page = agent.get('https://www.tarsnap.com/account.html') form = page.form_with(action: 'https://www.tarsnap.com/manage.cgi') form.address = config.data[:email] form.password = config.data[:password] panel = agent.submit(form) check_login_errors(panel) picodollars = panel.parser.to_s.scan(/\$\d+\.\d+/)[0].scan(/\d+\.\d+/)[0].to_f.round(4) config.logger.info("Current amount of picoUSD: #{picodollars}") picodollars end |
#check_configuration ⇒ Object
Elementary configuration file check
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/argosnap/balance.rb', line 10 def check_configuration Install.new.ensure_compatibility Install.new.ensure_installation if config.data[:email].empty? config.log_and_abort("Please add your tarsnap email to #{config}") end if config.data[:password].empty? config.log_and_abort("Please add your tarsnap password to #{config}") end end |
#check_login_errors(data) ⇒ Object
check for login errors
22 23 24 25 26 27 28 29 30 |
# File 'lib/argosnap/balance.rb', line 22 def check_login_errors(data) = 'No user exists with the provided email address; please try again.' = 'Password is incorrect; please try again.' if data.body.include?() config.log_and_abort('Password is incorrect; please try again.') elsif data.body.include?() config.log_and_abort('Bad password. Please check your configuration file tarsnap password!') end end |