Class: AutoExpreso::Client
- Inherits:
-
Object
- Object
- AutoExpreso::Client
- Includes:
- DataUtils
- Defined in:
- lib/autoexpreso.rb
Constant Summary collapse
- AE_URL =
'https://www.autoexpreso.com/Login.aspx'
Instance Attribute Summary collapse
-
#account ⇒ Object
readonly
Returns the value of attribute account.
-
#account_page ⇒ Object
readonly
Returns the value of attribute account_page.
-
#client ⇒ Object
readonly
Returns the value of attribute client.
-
#transactions ⇒ Object
readonly
Returns the value of attribute transactions.
Instance Method Summary collapse
-
#initialize(*args) ⇒ Client
constructor
A new instance of Client.
- #login(username, password) ⇒ Object
- #process_request(username, password) ⇒ Object
- #save_account ⇒ Object
- #table_data ⇒ Object
- #table_strip ⇒ Object
- #text_strip(field_name) ⇒ Object
Methods included from DataUtils
attributes, form_data, included, save_transactions
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
15 16 17 18 19 |
# File 'lib/autoexpreso.rb', line 15 def initialize(*args) @client = Mechanize.new @account = Hash.new @transactions = [] end |
Instance Attribute Details
#account ⇒ Object (readonly)
Returns the value of attribute account.
13 14 15 |
# File 'lib/autoexpreso.rb', line 13 def account @account end |
#account_page ⇒ Object (readonly)
Returns the value of attribute account_page.
13 14 15 |
# File 'lib/autoexpreso.rb', line 13 def account_page @account_page end |
#client ⇒ Object (readonly)
Returns the value of attribute client.
13 14 15 |
# File 'lib/autoexpreso.rb', line 13 def client @client end |
#transactions ⇒ Object (readonly)
Returns the value of attribute transactions.
13 14 15 |
# File 'lib/autoexpreso.rb', line 13 def transactions @transactions end |
Instance Method Details
#login(username, password) ⇒ Object
21 22 23 24 |
# File 'lib/autoexpreso.rb', line 21 def login(username, password) process_request(username, password) ap @account end |
#process_request(username, password) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/autoexpreso.rb', line 26 def process_request(username, password) @client.get(AE_URL) do |page| @account_page = page.form_with(id: form_data.login_form_id) do |form| form[form_data.login_form_username_name] = username form[form_data.login_form_password_name] = password end. end save_account table_strip end |
#save_account ⇒ Object
37 38 39 |
# File 'lib/autoexpreso.rb', line 37 def save_account attributes.map { |attribute| @account[attribute] = text_strip(form_data.send(attribute)) } end |
#table_data ⇒ Object
45 46 47 |
# File 'lib/autoexpreso.rb', line 45 def table_data @account_page.search("#{form_data.account_transaction_table_id} tbody tr") end |
#table_strip ⇒ Object
49 50 51 52 53 54 55 56 57 |
# File 'lib/autoexpreso.rb', line 49 def table_strip table_data.each do |tr| tds = tr.search('td') next unless tds.count == 4 save_transactions(tds, @transactions) end @account[:transactions] = @transactions end |
#text_strip(field_name) ⇒ Object
41 42 43 |
# File 'lib/autoexpreso.rb', line 41 def text_strip(field_name) @account_page.search(field_name).text.strip end |