squeegee 0.1.0 → 0.1.1

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.
@@ -2,18 +2,15 @@ module Squeegee
2
2
  # Account
3
3
  #
4
4
  # Generic account with validations on specific parameters
5
- class Account
6
- attr_accessor :name, :amount, :due_at, :paid, :uid
5
+ class Account < Base
6
+ attr_accessor :name, :amount, :due_at, :paid, :uid, :number
7
7
  def initialize(args={})
8
- %w(name uid amount due_at).each do |key|
9
- raise Squeegee::Error::InvalidParams,
10
- "missing attribute `#{key}`" unless args.has_key?(key.to_sym)
8
+ @keys = %w(name uid amount due_at)
9
+ params(args)
10
+
11
+ args.each do |attribute, value|
12
+ send(:"#{attribute}=", value)
11
13
  end
12
- @name = args[:name]
13
- @amount = args[:amount]
14
- @due_at = args[:due_at]
15
- @paid = args[:paid]
16
- @uid = args[:uid]
17
14
  end
18
15
  end
19
16
  end
@@ -18,6 +18,7 @@ module Squeegee
18
18
  @agent.log = Logger.new 'squeegee.log'
19
19
  @agent.user_agent = "Mozilla/5.0 (Squeegee)"
20
20
  @agent.default_encoding = "utf8"
21
+ @agent.agent.http.ssl_version = :SSLv3
21
22
  @agent.get(url)
22
23
  end
23
24
  end
@@ -5,14 +5,14 @@ module Squeegee
5
5
  #
6
6
  class BritishGas < Base
7
7
  HOST = "https://www.britishgas.co.uk"
8
- LOGIN_URL = "#{HOST}/Your_Account/Account_Details/"
9
- ACCOUNTS_URL = "#{HOST}/AccountSummary/getAccountDetailsForSummary/"
10
- ACCOUNT_URL = "#{HOST}/Your_Account/Account_Transaction/"
8
+ LOGIN_URL = "#{HOST}/Login/Login-Verify/"
9
+ ACCOUNTS_URL = "#{HOST}/apps/britishgas/components/GetAccountDetails/GET.servlet"
10
+ ACCOUNT_URL = "#{HOST}/YourAccount/PaymentHistory"
11
11
 
12
12
  attr_accessor :accounts
13
13
 
14
14
  FIELD = {
15
- email: "userName",
15
+ email: "emailAddress",
16
16
  password: "password"
17
17
  }
18
18
 
@@ -32,35 +32,34 @@ module Squeegee
32
32
 
33
33
  def authenticate!
34
34
  page = get(LOGIN_URL)
35
- form = page.form_with(action: '/Online_User/Account_Summary/')
35
+ form = page.form_with(name: 'userlogin')
36
36
 
37
37
  form[FIELD[:email]] = @email
38
38
  form[FIELD[:password]] = @password
39
-
40
39
  page = @agent.submit(form, form.buttons.first)
41
- #raise Error::Unauthorized, "Account details could be wrong" if page.at('.error')
40
+ raise Error::Unauthorized, "Account details could be wrong" if page.at('.error')
42
41
  end
43
42
 
44
43
  def get_accounts
45
44
  page = get(ACCOUNTS_URL)
46
- accounts = JSON.parse(page.body)
45
+ accounts = JSON.parse(page.body).first
47
46
  #account_ids = page.search("table#tableSelectAccount td > strong").collect {|row| row.content.to_i}
48
- accounts.each do |account|
49
- response = get_account(account['accountReferenceNumber'])
47
+ accounts['activeProducts'].each do |account|
48
+ response = get_account(account['accountNumber'])
50
49
  @accounts << Squeegee::Account.new(response)
51
50
  end
52
51
  end
53
52
 
54
53
  def get_account(id)
55
54
  response = {}
56
- url = "#{Squeegee::BritishGas::ACCOUNT_URL}?accountnumber=#{id}"
55
+ url = "#{Squeegee::BritishGas::ACCOUNT_URL}?accountNumber=#{id}"
57
56
  page = get(url)
58
- table = page.search("div#divHistoryTable table tbody")
57
+ table = page.search("table.table-history tbody")
59
58
  rows = table.search("tr").map do |row|
60
59
  tds = row.search("td")
61
60
  _row = {
62
61
  date: Date.parse(
63
- tds.first.inner_text.match(/\d{2}\s\w{3}\s\d{4}/)[0]
62
+ tds[0].inner_text.match(/\d{2}\s\w{3}\s\d{4}/)[0]
64
63
  ),
65
64
  type: tds[1].inner_text.match(/[A-Za-z]{2,}\s?[A-Za-z]?{2,}/)[0],
66
65
  debit: tds[2].inner_text.to_f,
@@ -78,7 +77,8 @@ module Squeegee
78
77
  end
79
78
  end
80
79
  response[:uid] = Digest::MD5.hexdigest("BritishGas#{id}")
81
- response[:name] = "BritishGas (#{id.to_s[-4..-1]})"
80
+ response[:name] = "British Gas (#{id.to_s[-4..-1]})"
81
+ response[:number] = id.to_i
82
82
  response
83
83
  end
84
84
 
@@ -67,6 +67,7 @@ module Squeegee
67
67
  amount: amount,
68
68
  due_at: due_at,
69
69
  paid: paid,
70
+ number: account_id,
70
71
  uid: uid
71
72
  )
72
73
 
@@ -18,6 +18,11 @@ module Squeegee
18
18
  @keys = %w(username password)
19
19
  @accounts = []
20
20
 
21
+ @agent = Mechanize.new
22
+
23
+ # NOTE: Orange websites redirects though insecure servers.
24
+ @agent.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
25
+
21
26
  params(args)
22
27
  @username = args.delete(:username)
23
28
  @password = args.delete(:password)
@@ -37,12 +42,13 @@ module Squeegee
37
42
 
38
43
  page = @agent.submit(form, form.buttons.first)
39
44
 
40
- if page.uri == LOGIN_POST_URL && !page.search('.error').nil?
45
+ if page.uri.to_s == LOGIN_POST_URL && !page.search('.error').nil?
41
46
  raise Squeegee::Error::Unauthenticated
42
47
  end
43
48
  end
44
49
 
45
50
  def get_statement
51
+
46
52
  page = get(BILLS_URL)
47
53
 
48
54
  last_bill = page.search("#eBillMainContent .eBillStandardTable").first
@@ -51,12 +57,14 @@ module Squeegee
51
57
 
52
58
  due_at = Date.parse(last_bill.search("td")[0].inner_text)
53
59
  amount = last_bill.search('td')[2].inner_text.gsub(/\.|,/,'').match(/\d{1,}/)[0].to_i
60
+ number = page.at("#accountSelectorLilp")['value'].to_i
54
61
  #@paid = balance || balance[0].to_i >= 0
55
- uid = Digest::MD5.hexdigest("OrangeUK#{@username}")
62
+ uid = Digest::MD5.hexdigest("OrangeUK#{number}")
56
63
 
57
64
  @accounts << Squeegee::Account.new(due_at: due_at,
58
- name: "Orange UK",
65
+ name: "Orange UK (#{number.to_s[-4..-1]})",
59
66
  uid: uid,
67
+ number: number,
60
68
  amount: amount)
61
69
  end
62
70
  end
@@ -1,3 +1,3 @@
1
1
  module Squeegee
2
- VERSION = "0.1.0"
2
+ VERSION = "0.1.1"
3
3
  end
@@ -17,27 +17,27 @@ describe Squeegee::Account do
17
17
  attr.delete(:name)
18
18
  expect{
19
19
  subject.new(attr)
20
- }.to raise_error(ArgumentError, "missing attribute `name`")
20
+ }.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `name` ")
21
21
  end
22
22
 
23
23
  it "validates presence of amount" do
24
24
  attr.delete(:amount)
25
25
  expect{
26
26
  subject.new(attr)
27
- }.to raise_error(ArgumentError, "missing attribute `amount`")
27
+ }.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `amount` ")
28
28
  end
29
29
 
30
30
  it "validates presence of uid" do
31
31
  attr.delete(:uid)
32
32
  expect{
33
33
  subject.new(attr)
34
- }.to raise_error(ArgumentError, "missing attribute `uid`")
34
+ }.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `uid` ")
35
35
  end
36
36
 
37
37
  it "validates presence of due_at" do
38
38
  attr.delete(:due_at)
39
39
  expect{
40
40
  subject.new(attr)
41
- }.to raise_error(ArgumentError, "missing attribute `due_at`")
41
+ }.to raise_error(Squeegee::Error::InvalidParams, "missing parameters `due_at` ")
42
42
  end
43
43
  end
@@ -31,6 +31,11 @@ describe Squeegee::Base do
31
31
  Logger.should_receive(:new).with('squeegee.log').and_return(logger)
32
32
  mechanize.should_receive(:log=).with(logger)
33
33
  mechanize.should_receive(:get).with("http://google.com")
34
+ agent = stub(:agent)
35
+ mechanize.should_receive(:agent).and_return(agent)
36
+ http = stub(:http)
37
+ agent.should_receive(:http).and_return(http)
38
+ http.should_receive(:ssl_version=).with(:SSLv3)
34
39
 
35
40
  subject.get("http://google.com")
36
41
  end
@@ -6,11 +6,9 @@ describe Squeegee::BritishGas do
6
6
  let(:form) {mock('form')}
7
7
  let(:button) {mock('button')}
8
8
  let(:json) {[
9
- {
10
- 'accountReferenceNumber' => 850046061940,
11
- 'Amount' => 70.00,
12
- 'Paymenttype' => ""
13
- }
9
+ 'activeProducts' => [
10
+ {'accountNumber' => 850046061940}
11
+ ]
14
12
  ].to_json}
15
13
 
16
14
  subject {Squeegee::BritishGas}
@@ -77,25 +75,26 @@ describe Squeegee::BritishGas do
77
75
  #Mechanize.any_instance.stub(get: mechanize.as_null_object)
78
76
  Mechanize.should_receive(:new).and_return(mechanize.as_null_object)
79
77
  mechanize.stub(form_with: form.as_null_object)
78
+ mechanize.stub(:at)
80
79
  end
81
80
  it "navigates to login URL" do
82
81
  mechanize.should_receive(:get).with(
83
- "https://www.britishgas.co.uk/Your_Account/Account_Details/"
82
+ "https://www.britishgas.co.uk/Login/Login-Verify/"
84
83
  ).and_return(mechanize)
85
84
 
86
85
  subject.new({})
87
86
  end
88
87
 
89
- it "finds by form action" do
88
+ it "finds by form name" do
90
89
  mechanize.should_receive(:form_with).with(
91
- action: '/Online_User/Account_Summary/'
90
+ :name => 'userlogin'
92
91
  ).and_return(form.as_null_object)
93
92
 
94
93
  subject.new
95
94
  end
96
95
 
97
96
  it "fills in form inputs" do
98
- form.should_receive(:[]=).with('userName', 'test@test.com')
97
+ form.should_receive(:[]=).with('emailAddress', 'test@test.com')
99
98
  form.should_receive(:[]=).with('password', 'superduper')
100
99
 
101
100
  subject.new(email: "test@test.com", password: "superduper")
@@ -137,7 +136,7 @@ describe Squeegee::BritishGas do
137
136
 
138
137
  it "finds paid bill" do
139
138
  mechanize.should_receive(:search).
140
- with("div#divHistoryTable table tbody").
139
+ with("table.table-history tbody").
141
140
  and_return(node)
142
141
  node.should_receive(:search).
143
142
  with('tr').
@@ -156,7 +155,7 @@ describe Squeegee::BritishGas do
156
155
 
157
156
  it "finds debt" do
158
157
  mechanize.should_receive(:search).
159
- with("div#divHistoryTable table tbody").
158
+ with("table.table-history tbody").
160
159
  and_return(node)
161
160
  node.should_receive(:search).
162
161
  with('tr').
@@ -106,10 +106,12 @@ describe Squeegee::OrangeUK do
106
106
  stub(:inner_text => "£25.50")
107
107
  ]
108
108
  )
109
+ mechanize.stub(:at).with('#accountSelectorLilp').and_return({'value' => '1234'})
109
110
  Squeegee::Account.should_receive(:new).
110
111
  with(amount: 2550,
111
- name: "Orange UK",
112
- uid: "0a24082a818a019adfbe7d0b77d5448d",
112
+ name: "Orange UK (1234)",
113
+ uid: "06a0a787d8267fcb1a2887dc7baf4de1",
114
+ :number => 1234,
113
115
  due_at: Date.parse('2012-05-15'))
114
116
  subject.new
115
117
  end
@@ -2,12 +2,12 @@
2
2
  require File.expand_path('../lib/squeegee/version', __FILE__)
3
3
 
4
4
  Gem::Specification.new do |gem|
5
- gem.authors = ["Kyle Welsby", "Chuck Hardy"]
6
- gem.email = ["app@britishruby.com"]
5
+ gem.authors = ["Kyle Welsby"]
6
+ gem.email = ["kyle@mekyle.com"]
7
7
  gem.description = %q{A collection of strategies to get bill dates and amounts
8
8
  from a growing range of accounts.}
9
9
  gem.summary = %q{Returns bill dates and amounts form utility accounts.}
10
- gem.homepage = "http://github.com/britruby/squeegee"
10
+ gem.homepage = "http://github.com/kylewelsby/squeegee"
11
11
 
12
12
  gem.add_runtime_dependency 'mechanize'
13
13
  gem.add_runtime_dependency 'logger'
metadata CHANGED
@@ -1,20 +1,19 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: squeegee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.0
4
+ version: 0.1.1
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
8
8
  - Kyle Welsby
9
- - Chuck Hardy
10
9
  autorequire:
11
10
  bindir: bin
12
11
  cert_chain: []
13
- date: 2012-04-21 00:00:00.000000000 Z
12
+ date: 2012-12-17 00:00:00.000000000 Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: mechanize
17
- requirement: &70160111404560 !ruby/object:Gem::Requirement
16
+ requirement: !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ! '>='
@@ -22,10 +21,15 @@ dependencies:
22
21
  version: '0'
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *70160111404560
24
+ version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
26
+ requirements:
27
+ - - ! '>='
28
+ - !ruby/object:Gem::Version
29
+ version: '0'
26
30
  - !ruby/object:Gem::Dependency
27
31
  name: logger
28
- requirement: &70160111403560 !ruby/object:Gem::Requirement
32
+ requirement: !ruby/object:Gem::Requirement
29
33
  none: false
30
34
  requirements:
31
35
  - - ! '>='
@@ -33,10 +37,15 @@ dependencies:
33
37
  version: '0'
34
38
  type: :runtime
35
39
  prerelease: false
36
- version_requirements: *70160111403560
40
+ version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
42
+ requirements:
43
+ - - ! '>='
44
+ - !ruby/object:Gem::Version
45
+ version: '0'
37
46
  - !ruby/object:Gem::Dependency
38
47
  name: gem-release
39
- requirement: &70160111402880 !ruby/object:Gem::Requirement
48
+ requirement: !ruby/object:Gem::Requirement
40
49
  none: false
41
50
  requirements:
42
51
  - - ! '>='
@@ -44,10 +53,15 @@ dependencies:
44
53
  version: '0'
45
54
  type: :development
46
55
  prerelease: false
47
- version_requirements: *70160111402880
56
+ version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ! '>='
60
+ - !ruby/object:Gem::Version
61
+ version: '0'
48
62
  - !ruby/object:Gem::Dependency
49
63
  name: rspec
50
- requirement: &70160111402040 !ruby/object:Gem::Requirement
64
+ requirement: !ruby/object:Gem::Requirement
51
65
  none: false
52
66
  requirements:
53
67
  - - ! '>='
@@ -55,10 +69,15 @@ dependencies:
55
69
  version: '0'
56
70
  type: :development
57
71
  prerelease: false
58
- version_requirements: *70160111402040
72
+ version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
74
+ requirements:
75
+ - - ! '>='
76
+ - !ruby/object:Gem::Version
77
+ version: '0'
59
78
  - !ruby/object:Gem::Dependency
60
79
  name: simplecov
61
- requirement: &70160111401320 !ruby/object:Gem::Requirement
80
+ requirement: !ruby/object:Gem::Requirement
62
81
  none: false
63
82
  requirements:
64
83
  - - ! '>='
@@ -66,10 +85,15 @@ dependencies:
66
85
  version: '0'
67
86
  type: :development
68
87
  prerelease: false
69
- version_requirements: *70160111401320
88
+ version_requirements: !ruby/object:Gem::Requirement
89
+ none: false
90
+ requirements:
91
+ - - ! '>='
92
+ - !ruby/object:Gem::Version
93
+ version: '0'
70
94
  - !ruby/object:Gem::Dependency
71
95
  name: webmock
72
- requirement: &70160111400600 !ruby/object:Gem::Requirement
96
+ requirement: !ruby/object:Gem::Requirement
73
97
  none: false
74
98
  requirements:
75
99
  - - ! '>='
@@ -77,11 +101,16 @@ dependencies:
77
101
  version: '0'
78
102
  type: :development
79
103
  prerelease: false
80
- version_requirements: *70160111400600
104
+ version_requirements: !ruby/object:Gem::Requirement
105
+ none: false
106
+ requirements:
107
+ - - ! '>='
108
+ - !ruby/object:Gem::Version
109
+ version: '0'
81
110
  description: ! "A collection of strategies to get bill dates and amounts\n from a
82
111
  growing range of accounts."
83
112
  email:
84
- - app@britishruby.com
113
+ - kyle@mekyle.com
85
114
  executables: []
86
115
  extensions: []
87
116
  extra_rdoc_files: []
@@ -109,7 +138,7 @@ files:
109
138
  - spec/squeegee/bskyb_spec.rb
110
139
  - spec/squeegee/orange_uk_spec.rb
111
140
  - squeegee.gemspec
112
- homepage: http://github.com/britruby/squeegee
141
+ homepage: http://github.com/kylewelsby/squeegee
113
142
  licenses: []
114
143
  post_install_message:
115
144
  rdoc_options: []
@@ -129,7 +158,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
129
158
  version: '0'
130
159
  requirements: []
131
160
  rubyforge_project:
132
- rubygems_version: 1.8.17
161
+ rubygems_version: 1.8.24
133
162
  signing_key:
134
163
  specification_version: 3
135
164
  summary: Returns bill dates and amounts form utility accounts.