Class: Mbanker::Authenticator

Inherits:
Object
  • Object
show all
Defined in:
lib/mbanker/authenticator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(crawler, login, password) ⇒ Authenticator

Returns a new instance of Authenticator.



5
6
7
# File 'lib/mbanker/authenticator.rb', line 5

def initialize crawler, , password
  @crawler, @login, @password = crawler, , password
end

Instance Attribute Details

#crawlerObject

Returns the value of attribute crawler.



3
4
5
# File 'lib/mbanker/authenticator.rb', line 3

def crawler
  @crawler
end

Instance Method Details

#authenticate!Object



14
15
16
17
18
19
20
21
22
23
# File 'lib/mbanker/authenticator.rb', line 14

def authenticate!
  crawler.visit :login
   = crawler.get_form
  .customer = @login
  .password = @password
  .submit
  unless session_error_absent?
    raise "Could not authenticate"
  end
end

#authenticated?Boolean

Returns:

  • (Boolean)


9
10
11
12
# File 'lib/mbanker/authenticator.rb', line 9

def authenticated?
  crawler.visit :accounts_list
  session_error_absent?
end

#session_error_absent?Boolean

Returns:

  • (Boolean)


29
30
31
# File 'lib/mbanker/authenticator.rb', line 29

def session_error_absent?
  not crawler.can_find?('.error.noSession')
end

#unauthenticate!Object



25
26
27
# File 'lib/mbanker/authenticator.rb', line 25

def unauthenticate!
  crawler.visit :logout
end