ba 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -19,23 +19,11 @@ And then execute:
19
19
 
20
20
  $ bundle
21
21
 
22
- Or install it yourself as:
23
-
24
- $ gem install ba
25
-
26
22
  ## Usage
27
23
 
28
24
  ### Checkout the different commands by running
29
25
  $ ba
30
26
 
31
- ### Install
32
- Run the following command if you don't have any config/config.yml file in your local path
33
-
34
- $ ba install
35
-
36
- ### Modify the ~/config/config.yml with your bank info
37
- $ vi ~/config/config.yml
38
-
39
27
  ### Run the command for your bank
40
28
  $ ba [BANK] balance
41
29
 
@@ -49,7 +37,6 @@ Or install it yourself as:
49
37
 
50
38
  ### Adding new Scripts
51
39
  - Follow the bank.sample.rb example
52
- - Add the bank to the config/config.sample.yml
53
40
  - Push it!
54
41
 
55
42
  ## CONTRIBUTORS
@@ -1,24 +1,40 @@
1
1
  module Ba::Banks
2
2
  class Bancolombia < Thor
3
3
 
4
- desc "balance", "Returns the Bancolombia account balance"
5
- def balance
6
- ##Login username page
7
- agent.get("https://bancolombia.olb.todo1.com/olb/Init")
8
- userLoginPage = agent.get("https://bancolombia.olb.todo1.com/olb/Login")
9
- userLoginPage.form_with(:name => "authenticationForm") do |f|
10
- f.userId = ask("Username: ")
11
- end.click_button
12
-
13
- ##Redirect to password page
14
- passwordPage = agent.get("https://bancolombia.olb.todo1.com/olb/GetUserProfile")
15
- passwordPageHtml = passwordPage.body
4
+ desc "balance optional: [username] [password]", "Returns the Bancolombia account balance"
5
+ def balance(username = nil , password = nil)
6
+ go_to_root
7
+ process_username_authentication(username)
8
+ process_password_authentication(password)
9
+ page = go_to_authentication_path
10
+ process_questions(page) if need_to_answer_banks_questions?(page)
11
+ balancePage = agent.get("/olb/BeginInitializeActionFromCM?from=pageTabs")
12
+ balance = balancePage.search(".contentTotalNegrita").last.children.text
13
+ puts "Your actual balance is: $#{balance}"
14
+ end
15
+
16
+ private
17
+
18
+ def go_to_authentication_path
19
+ agent.get("https://bancolombia.olb.todo1.com/olb/Authentication")
20
+ end
21
+
22
+ def need_to_answer_banks_questions?(page)
23
+ !get_question_form(page).nil?
24
+ end
25
+
26
+ def get_question_form(page)
27
+ @question_form ||= page.form_with(name: "checkChallQuestForm")
28
+ end
29
+
30
+ def process_password_authentication(password)
31
+ passwordPageHtml = get_password_path.body
16
32
  ##Insert \r for correct regex on password scripts
17
33
  passwordPageHtml.gsub!(/document.getElementById/, "\r\n\t document.getElementById")
18
34
  enc_password = ""
19
- password = ask("Password: ") { |q| q.echo = "*" }
35
+ password = password || ask("Password: ")
20
36
  password.to_s.split('').each do |n|
21
- passwordPageHtml.match(/\'td_#{n}\'\)\.addEventListener\(\'click\'\,\sfunction\(\)\{\S*\(\"(.*)\"\)\;\}/);
37
+ passwordPageHtml.match(/\'td_#{n}\'\)\.addEventListener\(\'click\'\,\sfunction\(\)\{\S*\(\"(.*)\"\)\;\}/)
22
38
  enc_password << $1
23
39
  end
24
40
 
@@ -27,31 +43,53 @@ module Ba::Banks
27
43
  secretHiddenField = $1
28
44
 
29
45
  ##Post encripted password and secret hidden field
30
- passwordPage.form_with(:name => "authenticationForm") do |f|
46
+ form = get_password_path.form_with(name: "authenticationForm") do |f|
31
47
  f.userId = "0"
32
48
  f.password = enc_password
33
49
  f.add_field!(secretHiddenField, value = enc_password)
34
- end.click_button
50
+ end
35
51
 
36
- ##Get Balance
37
- page = agent.get("https://bancolombia.olb.todo1.com/olb/Authentication")
38
- process_questions(page) if page.forms_with(name: "checkChallQuestForm").any?
39
- balancePage = agent.get("/olb/BeginInitializeActionFromCM?from=pageTabs")
40
- balance = balancePage.search(".contentTotalNegrita").last.children.text
41
- puts "Your actual balance is: $#{balance}"
52
+ form.click_button
42
53
  end
43
54
 
44
- private
55
+ def process_username_authentication(username)
56
+ form = get_login_path.form_with(name: "authenticationForm") do |f|
57
+ f.userId = username || ask("Username: ")
58
+ end
45
59
 
60
+ form.click_button
61
+ end
62
+
63
+ def go_to_root
64
+ agent.get "https://bancolombia.olb.todo1.com/olb/Init"
65
+ end
66
+
67
+ def get_login_path
68
+ agent.get "https://bancolombia.olb.todo1.com/olb/Login"
69
+ end
70
+
71
+ def get_password_path
72
+ @password_path ||= agent.get("https://bancolombia.olb.todo1.com/olb/GetUserProfile")
73
+ end
74
+
46
75
  def process_questions(page)
47
76
  puts "The answer for the following questions will not be saved"
48
- answer_one = ask(page.search("#luserAnswer1").text.strip + " ") { |q| q.echo = "*" }
49
- answer_two = ask(page.search("#luserAnswer2").text.strip + " ") { |q| q.echo = "*" }
50
- form = page.form_with(name: "checkChallQuestForm") do |f|
51
- f.userAnswer1 = answer_one
52
- f.userAnswer2 = answer_two
77
+ first_question = first_question(page)
78
+ second_question = second_question(page)
79
+
80
+ form = get_question_form(page) do |f|
81
+ f.userAnswer1 = first_question
82
+ f.userAnswer2 = secound_question
53
83
  end
54
- form.submit(form.buttons_with(name: "accept_btn").first)
84
+ agent.submit(form)
85
+ end
86
+
87
+ def first_question(page)
88
+ ask(page.search("#luserAnswer1").text.strip)
89
+ end
90
+
91
+ def second_question(page)
92
+ ask(page.search("#luserAnswer2").text.strip)
55
93
  end
56
94
 
57
95
  def agent
@@ -5,11 +5,5 @@
5
5
  # def balance
6
6
  # puts "Not yet Implemented"
7
7
  # end
8
- #
9
- # private
10
- #
11
- # def config
12
- # @config ||= YAML::load(File.open('config/config.yml'))["BANK"]
13
- # end
14
8
  # end
15
9
  # end
@@ -1,5 +1,4 @@
1
1
  require 'thor'
2
- require 'yaml'
3
2
  require 'mechanize'
4
3
  require 'highline/import'
5
4
  require 'ba/banks'
@@ -1,3 +1,3 @@
1
1
  module Ba
2
- VERSION = "0.0.7"
2
+ VERSION = "0.0.8"
3
3
  end
@@ -17,7 +17,7 @@ describe Ba::CLI do
17
17
 
18
18
  describe "#version" do
19
19
  it "returns the current application version" do
20
- STDOUT.should_receive(:puts).with ("0.0.6")
20
+ STDOUT.should_receive(:puts).with ("0.0.8")
21
21
  subject.version
22
22
  end
23
23
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ba
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.7
4
+ version: 0.0.8
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors: