Class: CommerceBank
Instance Attribute Summary collapse
-
#available ⇒ Object
readonly
Returns the value of attribute available.
-
#current ⇒ Object
readonly
Returns the value of attribute current.
-
#register ⇒ Object
readonly
Returns the value of attribute register.
Instance Method Summary collapse
- #daily_summary ⇒ Object
- #gmail_daily_summary ⇒ Object
- #gmail_monthly_summary ⇒ Object
- #html_daily_summary ⇒ Object
-
#initialize ⇒ CommerceBank
constructor
A new instance of CommerceBank.
- #monthly_summary(day_in_month = (Date.today - Date.today.day)) ⇒ Object
- #print_all ⇒ Object
- #print_daily_summary ⇒ Object
- #text_daily_summary ⇒ Object
Constructor Details
#initialize ⇒ CommerceBank
Returns a new instance of CommerceBank.
105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 |
# File 'lib/commercebank.rb', line 105 def initialize @config = AppConfig.new('~/.commerce.yaml') client = WebClient.new client.get('/') client.get('/CBI/login.aspx', 'MAINFORM') client.fields['txtUserID'] = @config[:username] response = client.post('/CBI/login.aspx', 'MAINFORM') # If a question was asked, answer it then get the password page. question = response.body.scan(/Your security question: (.*?)<\/td>/i).first.andand.first if question client.fields['txtChallengeAnswer'] = @config[question] client.fields['saveComputer'] = 'rdoBindDeviceNo' response = client.post('/CBI/login.aspx', 'MAINFORM') end raise "could not reach the password page" unless client.fields['__EVENTTARGET'] == 'btnLogin' client.fields['txtPassword'] = @config[:password] response = client.post('/CBI/login.aspx') response = client.get('/CBI/Accounts/CBI/Activity.aspx', 'MAINFORM') (@current, @available) = parse_balance(response.body) @pending = parse_pending(response.body) client.fields['Anthem_UpdatePage'] = 'true' client.fields['txtFilterFromDate:textBox'] = Time.parse('1/1/2000').strftime('%m/%d/%Y') client.fields['txtFilterToDate:textBox'] = Time.now.strftime('%m/%d/%Y') response = client.post('/CBI/Accounts/CBI/Activity.aspx?Anthem_CallBack=true') raw_data = JSON.parse(response.body) @register = parse_register(raw_data['controls']['pnlPosted']) end |
Instance Attribute Details
#available ⇒ Object (readonly)
Returns the value of attribute available.
103 104 105 |
# File 'lib/commercebank.rb', line 103 def available @available end |
#current ⇒ Object (readonly)
Returns the value of attribute current.
103 104 105 |
# File 'lib/commercebank.rb', line 103 def current @current end |
#register ⇒ Object (readonly)
Returns the value of attribute register.
103 104 105 |
# File 'lib/commercebank.rb', line 103 def register @register end |
Instance Method Details
#daily_summary ⇒ Object
143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 |
# File 'lib/commercebank.rb', line 143 def daily_summary today, yesterday, this_week, last_week = [], [], [], [] register.each do |entry| if entry[:date] == Date.today then today << entry elsif entry[:date] == (Date.today - 1) then yesterday << entry elsif entry[:date] >= Date.today.last_sunday then this_week << entry elsif entry[:date] >= (Date.today.last_sunday - 1).last_sunday then last_week << entry end end { 'Pending' => @pending, 'Today' => today, 'Yesterday' => yesterday, 'This Week' => this_week, 'Last Week' => last_week, :order => [ 'Pending', 'Today', 'Yesterday', 'This Week', 'Last Week' ] } end |
#gmail_daily_summary ⇒ Object
185 186 187 188 189 190 191 192 |
# File 'lib/commercebank.rb', line 185 def gmail_daily_summary subject = "Daily Summary" username = @config['GMail Username'] password = @config['GMail Password'] GMail.new(username, password).send(username, subject, html_daily_summary, 'text/html') end |
#gmail_monthly_summary ⇒ Object
194 195 196 197 198 199 200 201 202 203 |
# File 'lib/commercebank.rb', line 194 def gmail_monthly_summary last_month = Date.today - Date.today.day subject = "#{last_month.strftime('%B')} Summary" summary = summarize_html(monthly_summary(last_month)) username = @config['GMail Username'] password = @config['GMail Password'] GMail.new(username, password).send(username, subject, summary, 'text/html') end |
#html_daily_summary ⇒ Object
181 182 183 |
# File 'lib/commercebank.rb', line 181 def html_daily_summary summarize_html daily_summary end |
#monthly_summary(day_in_month = (Date.today - Date.today.day)) ⇒ Object
162 163 164 165 166 167 |
# File 'lib/commercebank.rb', line 162 def monthly_summary(day_in_month = (Date.today - Date.today.day)) first_of_month = day_in_month - day_in_month.day + 1 last_of_month = first_of_month + day_in_month.days_in_month - 1 entries = register.find_all {|entry| entry[:date] >= first_of_month && entry[:date] <= last_of_month} { day_in_month.strftime('%B') => entries } end |
#print_all ⇒ Object
169 170 171 |
# File 'lib/commercebank.rb', line 169 def print_all summarize 'All' => register end |
#print_daily_summary ⇒ Object
173 174 175 |
# File 'lib/commercebank.rb', line 173 def print_daily_summary print(summarize(daily_summary)) end |
#text_daily_summary ⇒ Object
177 178 179 |
# File 'lib/commercebank.rb', line 177 def text_daily_summary summarize daily_summary end |