Class: Dinero::Bank::Base

Inherits:
Object
  • Object
show all
Defined in:
lib/dinero/banks.rb

Direct Known Subclasses

CapitalOne, CapitalOne360, Sdccu, SouthStateBank

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Base

Returns a new instance of Base.



9
10
11
12
13
14
15
16
17
18
19
# File 'lib/dinero/banks.rb', line 9

def initialize options
  opts = default_options.merge options

  @username = opts[:username]
  @password = opts[:password]
  @login_url = opts[:login_url]
  @security_questions = opts[:security_questions] || []
  @timeout = opts[:timeout] || DEFAULT_TIMEOUT
  @authenticated = false
  validate!
end

Instance Attribute Details

#login_urlObject (readonly)

Returns the value of attribute login_url.



7
8
9
# File 'lib/dinero/banks.rb', line 7

def 
  @login_url
end

#passwordObject (readonly)

Returns the value of attribute password.



6
7
8
# File 'lib/dinero/banks.rb', line 6

def password
  @password
end

#security_questionsObject (readonly)

Returns the value of attribute security_questions.



6
7
8
# File 'lib/dinero/banks.rb', line 6

def security_questions
  @security_questions
end

#timeoutObject (readonly)

Returns the value of attribute timeout.



7
8
9
# File 'lib/dinero/banks.rb', line 7

def timeout
  @timeout
end

#usernameObject (readonly)

Returns the value of attribute username.



6
7
8
# File 'lib/dinero/banks.rb', line 6

def username
  @username
end

Instance Method Details

#accounts_summary_documentObject



54
55
56
57
58
59
# File 'lib/dinero/banks.rb', line 54

def accounts_summary_document
  return @accounts_summary_document if @accounts_summary_document

  goto_accounts_summary_page
  @accounts_summary_document = Nokogiri::HTML connection.page_source
end

#after_successful_loginObject



61
62
63
# File 'lib/dinero/banks.rb', line 61

def 
  # NOP
end

#authenticated?Boolean

Returns:

  • (Boolean)


46
47
48
# File 'lib/dinero/banks.rb', line 46

def authenticated?
  !!@authenticated
end

#class_nameObject



65
66
67
# File 'lib/dinero/banks.rb', line 65

def class_name
  self.class.to_s.downcase.gsub("dinero::bank::", '')
end

#connectionObject



42
43
44
# File 'lib/dinero/banks.rb', line 42

def connection
  @connection ||= establish_connection
end

#default_optionsObject



27
28
29
# File 'lib/dinero/banks.rb', line 27

def default_options
  {}
end

#establish_connectionObject



31
32
33
34
35
36
37
38
39
40
# File 'lib/dinero/banks.rb', line 31

def establish_connection
  capabilities = Selenium::WebDriver::Remote::Capabilities.phantomjs(
    'phantomjs.page.settings.userAgent' => 'Mozilla/5.0 (X11; Linux x86_64; rv:31.0) Gecko/20100101 Firefox/33.0',
    'service_args' => ['--ignore-ssl-errors=true', '--ssl-protocol=any']
  )

  driver = Selenium::WebDriver.for :phantomjs, :desired_capabilities => capabilities
  driver.manage.window.size = Selenium::WebDriver::Dimension.new(1640, 768)
  driver
end

#goto_login_pageObject



88
89
90
91
# File 'lib/dinero/banks.rb', line 88

def 
  connection.navigate.to 
  snap "#{class_name}_login_page.png"
end

#login!Object



93
94
95
96
97
98
99
100
101
102
# File 'lib/dinero/banks.rb', line 93

def login!
  return if authenticated?
  screenshot_on_error do
    
    post_credentials!
    wait.until { on_accounts_summary_page? }
    
    @authenticated = true
  end
end

#screenshot_on_error(name = nil) ⇒ Object



74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/dinero/banks.rb', line 74

def screenshot_on_error name = nil
  begin
    yield
  rescue
    unless name
      class_name, method_name = caller.first.match(/(\w+)\.rb\:\d+\:in\s\`([^\']+)/).captures
      name = "#{class_name}_#{method_name.gsub(/\W/, '')}"
    end
    snap "#{name}_error" unless @captured_error
    @captured_error = true
    raise
  end
end

#snap(filename) ⇒ Object



69
70
71
72
# File 'lib/dinero/banks.rb', line 69

def snap filename
  filename = filename + '.png' unless filename =~ /\.png$/
  connection.save_screenshot "log/#{filename}"
end

#validate!Object



21
22
23
24
25
# File 'lib/dinero/banks.rb', line 21

def validate!
  raise "Must supply :username" if @username.to_s.empty?
  raise "Must supply :password" if @password.to_s.empty?
  raise "Must have a :login_url" if @login_url.to_s.empty?
end

#waitObject



50
51
52
# File 'lib/dinero/banks.rb', line 50

def wait
  @wait ||= Selenium::WebDriver::Wait.new(:timeout => timeout)
end