Class: AutoExpreso::Client
- Inherits:
-
Object
- Object
- AutoExpreso::Client
show all
- Includes:
- DataUtils
- Defined in:
- lib/autoexpreso.rb
Constant Summary
collapse
- AE_LOGIN =
'https://www.autoexpreso.com/Login.aspx'
- AE_ACCOUNT =
'https://www.autoexpreso.com/dynamic/'
Instance Attribute Summary collapse
Instance Method Summary
collapse
Methods included from DataUtils
attributes, form_data, included, save_transactions
Constructor Details
#initialize(*args) ⇒ Client
Returns a new instance of Client.
17
18
19
20
21
|
# File 'lib/autoexpreso.rb', line 17
def initialize(*args)
@client = Mechanize.new
@account = Hash.new
@transactions = []
end
|
Instance Attribute Details
#account ⇒ Object
Returns the value of attribute account.
15
16
17
|
# File 'lib/autoexpreso.rb', line 15
def account
@account
end
|
#account_page ⇒ Object
Returns the value of attribute account_page.
15
16
17
|
# File 'lib/autoexpreso.rb', line 15
def account_page
@account_page
end
|
#client ⇒ Object
Returns the value of attribute client.
15
16
17
|
# File 'lib/autoexpreso.rb', line 15
def client
@client
end
|
#transactions ⇒ Object
Returns the value of attribute transactions.
15
16
17
|
# File 'lib/autoexpreso.rb', line 15
def transactions
@transactions
end
|
Instance Method Details
#account_details(json: false) ⇒ Object
71
72
73
74
75
76
77
|
# File 'lib/autoexpreso.rb', line 71
def account_details(json: false)
if json
puts JSON.pretty_generate(account)
else
ap account
end
end
|
#authenticate(username, password) ⇒ Object
28
29
30
31
32
33
34
35
|
# File 'lib/autoexpreso.rb', line 28
def authenticate(username, password)
@client.get(AE_LOGIN) do |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.click_button
end
end
|
#login(username, password) ⇒ Object
23
24
25
26
|
# File 'lib/autoexpreso.rb', line 23
def login(username, password)
authenticate(username, password)
process_request
end
|
#process_request ⇒ Object
37
38
39
40
41
|
# File 'lib/autoexpreso.rb', line 37
def process_request
process_transactions
save_account
table_strip
end
|
#process_transactions ⇒ Object
43
44
45
|
# File 'lib/autoexpreso.rb', line 43
def process_transactions
@account_page = @client.get(AE_ACCOUNT)
end
|
#save_account ⇒ Object
47
48
49
50
51
|
# File 'lib/autoexpreso.rb', line 47
def save_account
attributes.map do |attribute|
@account[attribute] = text_strip(form_data.send(attribute))
end
end
|
#table_data ⇒ Object
57
58
59
|
# File 'lib/autoexpreso.rb', line 57
def table_data
@account_page.search("#{form_data.account_transaction_table_id} tbody tr")
end
|
#table_strip ⇒ Object
61
62
63
64
65
66
67
68
69
|
# File 'lib/autoexpreso.rb', line 61
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
53
54
55
|
# File 'lib/autoexpreso.rb', line 53
def text_strip(field_name)
@account_page.search(field_name).text.strip
end
|