mbanker 0.1.0
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/.gitignore +4 -0
- data/Gemfile +4 -0
- data/Guardfile +16 -0
- data/MIT-LICENSE +20 -0
- data/README.markdown +77 -0
- data/Rakefile +2 -0
- data/lib/mbanker.rb +14 -0
- data/lib/mbanker/account.rb +71 -0
- data/lib/mbanker/accounts_list.rb +29 -0
- data/lib/mbanker/authenticator.rb +34 -0
- data/lib/mbanker/crawler.rb +78 -0
- data/lib/mbanker/persistent_crawler.rb +51 -0
- data/lib/mbanker/session.rb +16 -0
- data/lib/mbanker/version.rb +3 -0
- data/mbanker.gemspec +28 -0
- data/spec/lib/mbanker/authenticator.rb +52 -0
- data/spec/lib/mbanker/session_spec.rb +37 -0
- data/spec/lib/mbanker_spec.rb +36 -0
- data/spec/spec_helper.rb +1 -0
- metadata +130 -0
data/.gitignore
ADDED
data/Gemfile
ADDED
data/Guardfile
ADDED
@@ -0,0 +1,16 @@
|
|
1
|
+
guard 'ego' do
|
2
|
+
watch('Guardfile')
|
3
|
+
end
|
4
|
+
|
5
|
+
guard 'bundler' do
|
6
|
+
watch('Gemfile')
|
7
|
+
watch(/^.+\.gemspec/)
|
8
|
+
end
|
9
|
+
|
10
|
+
guard 'rspec', :version => 2 do
|
11
|
+
watch(%r{^spec/.+_spec\.rb})
|
12
|
+
watch(%r{^lib/(.+)\.rb}) { |m| "spec/lib/#{m[1]}_spec.rb" }
|
13
|
+
watch('spec/spec_helper.rb') { "spec" }
|
14
|
+
watch('Gemfile') { "spec" }
|
15
|
+
watch(/^.+\.gemspec/) { "spec" }
|
16
|
+
end
|
data/MIT-LICENSE
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright © 2011 Michal Taszycki
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
4
|
+
of this software and associated documentation files (the "Software"), to deal
|
5
|
+
in the Software without restriction, including without limitation the rights
|
6
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
7
|
+
copies of the Software, and to permit persons to whom the Software is
|
8
|
+
furnished to do so, subject to the following conditions:
|
9
|
+
|
10
|
+
The above copyright notice and this permission notice shall be included in
|
11
|
+
all copies or substantial portions of the Software.
|
12
|
+
|
13
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
14
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
15
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
16
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
17
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
18
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
19
|
+
THE SOFTWARE.
|
20
|
+
|
data/README.markdown
ADDED
@@ -0,0 +1,77 @@
|
|
1
|
+
mBanker
|
2
|
+
=======
|
3
|
+
|
4
|
+
Missing API for online mBank services.
|
5
|
+
|
6
|
+
Client for nonexistent mBank API.
|
7
|
+
|
8
|
+
Installation
|
9
|
+
------------
|
10
|
+
|
11
|
+
gem install mbanker
|
12
|
+
|
13
|
+
Usage
|
14
|
+
-----
|
15
|
+
|
16
|
+
``` ruby
|
17
|
+
|
18
|
+
require 'mbanker'
|
19
|
+
|
20
|
+
# opening session
|
21
|
+
session = Mbanker.create_session USERNAME, PASSWORD
|
22
|
+
|
23
|
+
# printing accounts info
|
24
|
+
session.accounts.each do |account|
|
25
|
+
puts "#{account.label} - #{account.name}"
|
26
|
+
puts " number: #{account.number}"
|
27
|
+
puts " balance: #{account.balance}"
|
28
|
+
puts " available money: #{account.balance}"
|
29
|
+
|
30
|
+
# fetch and print account details
|
31
|
+
account.fetch_details
|
32
|
+
puts " details:"
|
33
|
+
puts " iban number: #{account.iban_number}"
|
34
|
+
puts " bic number: #{account.bic_number}"
|
35
|
+
puts " owner: #{account.owner}"
|
36
|
+
puts " account type: #{account.account_type}"
|
37
|
+
puts " client role: #{account.client_role}"
|
38
|
+
puts " plenipotentiary: #{account.plenipotentiary}"
|
39
|
+
end
|
40
|
+
|
41
|
+
# changing name of the account
|
42
|
+
session.accounts.first.change_name "MONEY JAR"
|
43
|
+
|
44
|
+
```
|
45
|
+
|
46
|
+
Development and testing
|
47
|
+
-------------
|
48
|
+
|
49
|
+
git clone git://github.com/mehowte/mbanker.git
|
50
|
+
cd mbanker
|
51
|
+
bundle
|
52
|
+
bundle exec rspec spec
|
53
|
+
|
54
|
+
License
|
55
|
+
-------
|
56
|
+
|
57
|
+
Copyright © 2011 Michal Taszycki
|
58
|
+
|
59
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
60
|
+
of this software and associated documentation files (the "Software"), to deal
|
61
|
+
in the Software without restriction, including without limitation the rights
|
62
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
63
|
+
copies of the Software, and to permit persons to whom the Software is
|
64
|
+
furnished to do so, subject to the following conditions:
|
65
|
+
|
66
|
+
The above copyright notice and this permission notice shall be included in
|
67
|
+
all copies or substantial portions of the Software.
|
68
|
+
|
69
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
70
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
71
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
72
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
73
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
74
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
75
|
+
THE SOFTWARE.
|
76
|
+
|
77
|
+
|
data/Rakefile
ADDED
data/lib/mbanker.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
module Mbanker
|
2
|
+
autoload :Account, 'mbanker/account'
|
3
|
+
autoload :AccountsList, 'mbanker/accounts_list'
|
4
|
+
autoload :Authenticator, 'mbanker/authenticator'
|
5
|
+
autoload :Crawler, 'mbanker/crawler'
|
6
|
+
autoload :PersistentCrawler, 'mbanker/persistent_crawler'
|
7
|
+
autoload :Session, 'mbanker/session'
|
8
|
+
|
9
|
+
def self.create_session username, password
|
10
|
+
crawler = Crawler.new
|
11
|
+
authenticator = Authenticator.new crawler, username, password
|
12
|
+
Session.new crawler, authenticator
|
13
|
+
end
|
14
|
+
end
|
@@ -0,0 +1,71 @@
|
|
1
|
+
module Mbanker
|
2
|
+
class Account
|
3
|
+
attr_reader :index, :name, :label, :number, :iban_number, :bic_number, :account_type
|
4
|
+
attr_reader :owner, :plenipotentiary, :client_role, :balance, :available_money
|
5
|
+
|
6
|
+
def initialize index, crawler, attributes
|
7
|
+
@index, @crawler = index, crawler
|
8
|
+
if attributes.key? :full_name_and_number
|
9
|
+
extract_label_name_and_number attributes[:full_name_and_number]
|
10
|
+
end
|
11
|
+
[:balance, :available_money].each do |attribute_name|
|
12
|
+
if attributes.key? attribute_name
|
13
|
+
instance_variable_set(:"@#{attribute_name}", attributes[attribute_name])
|
14
|
+
end
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def change_name new_name
|
19
|
+
visit_account_details
|
20
|
+
@crawler.click change_name_button
|
21
|
+
|
22
|
+
@crawler.get_form.tbVarPartAccName = new_name
|
23
|
+
@crawler.click confirm_button
|
24
|
+
end
|
25
|
+
|
26
|
+
def fetch_details
|
27
|
+
visit_account_details
|
28
|
+
extract_label_and_name @crawler.extract_text('fieldset:nth-child(2) .content')
|
29
|
+
@number = @crawler.extract_text('fieldset:nth-child(3) .content')
|
30
|
+
@iban_number = @crawler.extract_text('fieldset:nth-child(4) .content')
|
31
|
+
@bic_number = @crawler.extract_text('fieldset:nth-child(5) .content')
|
32
|
+
@account_type = @crawler.extract_text('fieldset:nth-child(6) .content')
|
33
|
+
@owner = @crawler.extract_text('fieldset:nth-child(7) li')
|
34
|
+
@plenipotentiary = @crawler.extract_text('fieldset:nth-child(8) li')
|
35
|
+
@client_role = @crawler.extract_text('fieldset:nth-child(9) .content')
|
36
|
+
@balance = @crawler.extract_text('fieldset:nth-child(10) .amount')
|
37
|
+
@available_money = @crawler.extract_text('fieldset:nth-child(11) .amount')
|
38
|
+
end
|
39
|
+
|
40
|
+
|
41
|
+
private
|
42
|
+
|
43
|
+
def extract_label_name_and_number full_name_and_number
|
44
|
+
label_and_name, @number = full_name_and_number.gsub(/\A(.+) ((\d\s?){26})\Z/,'\1,\2').split(',').map(&:strip)
|
45
|
+
extract_label_and_name label_and_name
|
46
|
+
end
|
47
|
+
|
48
|
+
def extract_label_and_name label_and_name
|
49
|
+
@label, @name = label_and_name.split(' - ').map(&:strip)
|
50
|
+
@name ||= ''
|
51
|
+
end
|
52
|
+
|
53
|
+
def visit_account_details
|
54
|
+
@crawler.visit :accounts_list
|
55
|
+
@crawler.click account_link
|
56
|
+
end
|
57
|
+
|
58
|
+
def change_name_button
|
59
|
+
@crawler.search('.button:nth-child(2)').first
|
60
|
+
end
|
61
|
+
|
62
|
+
def confirm_button
|
63
|
+
@crawler.search('#Confirm').first
|
64
|
+
end
|
65
|
+
|
66
|
+
def account_link
|
67
|
+
@crawler.search('p.Account a')[@index]
|
68
|
+
end
|
69
|
+
end
|
70
|
+
end
|
71
|
+
|
@@ -0,0 +1,29 @@
|
|
1
|
+
module Mbanker
|
2
|
+
class AccountsList
|
3
|
+
attr_reader :accounts
|
4
|
+
|
5
|
+
def initialize crawler
|
6
|
+
@crawler = crawler
|
7
|
+
fetch_accounts
|
8
|
+
end
|
9
|
+
|
10
|
+
private
|
11
|
+
def fetch_accounts
|
12
|
+
@accounts = []
|
13
|
+
@crawler.visit :accounts_list
|
14
|
+
full_names_and_numbers = @crawler.extract_texts('.Account a')
|
15
|
+
balances = @crawler.extract_texts('.Amount a')
|
16
|
+
availables = @crawler.extract_texts('.Amount span')
|
17
|
+
accounts_count = full_names_and_numbers.count
|
18
|
+
accounts_count.times do |index|
|
19
|
+
attributes = {
|
20
|
+
full_name_and_number: full_names_and_numbers[index],
|
21
|
+
balance: balances[index],
|
22
|
+
available_money: availables[index]
|
23
|
+
}
|
24
|
+
@accounts << Mbanker::Account.new(index, @crawler, attributes)
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
29
|
+
end
|
@@ -0,0 +1,34 @@
|
|
1
|
+
module Mbanker
|
2
|
+
class Authenticator
|
3
|
+
attr_accessor :crawler
|
4
|
+
|
5
|
+
def initialize crawler, login, password
|
6
|
+
@crawler, @login, @password = crawler, login, password
|
7
|
+
end
|
8
|
+
|
9
|
+
def authenticated?
|
10
|
+
crawler.visit :accounts_list
|
11
|
+
session_error_absent?
|
12
|
+
end
|
13
|
+
|
14
|
+
def authenticate!
|
15
|
+
crawler.visit :login
|
16
|
+
login_form = crawler.get_form
|
17
|
+
login_form.customer = @login
|
18
|
+
login_form.password = @password
|
19
|
+
login_form.submit
|
20
|
+
unless session_error_absent?
|
21
|
+
raise "Could not authenticate"
|
22
|
+
end
|
23
|
+
end
|
24
|
+
|
25
|
+
def unauthenticate!
|
26
|
+
crawler.visit :logout
|
27
|
+
end
|
28
|
+
|
29
|
+
def session_error_absent?
|
30
|
+
not crawler.can_find?('.error.noSession')
|
31
|
+
end
|
32
|
+
|
33
|
+
end
|
34
|
+
end
|
@@ -0,0 +1,78 @@
|
|
1
|
+
require 'mechanize'
|
2
|
+
module Mbanker
|
3
|
+
class Crawler
|
4
|
+
|
5
|
+
BASE_URI = 'https://www.mbank.com.pl/'
|
6
|
+
PATHS = {
|
7
|
+
:login => 'logon.aspx',
|
8
|
+
:logout => 'logout.aspx',
|
9
|
+
:accounts_list => 'accounts_list.aspx',
|
10
|
+
:account_details => 'account_details.aspx',
|
11
|
+
:account_name_change => 'contract_change_name.aspx',
|
12
|
+
:operation_history => 'account_oper_list.aspx'
|
13
|
+
}
|
14
|
+
|
15
|
+
def initialize
|
16
|
+
@agent = Mechanize.new
|
17
|
+
end
|
18
|
+
|
19
|
+
def visit path_name
|
20
|
+
@agent.get(BASE_URI + PATHS[path_name])
|
21
|
+
end
|
22
|
+
|
23
|
+
def click link_or_button
|
24
|
+
action = extract_action link_or_button
|
25
|
+
parameters = extract_post_parameters link_or_button
|
26
|
+
submit_navigation_form action, parameters
|
27
|
+
end
|
28
|
+
|
29
|
+
def extract_action link
|
30
|
+
onclick_value = link.attribute('onclick').value
|
31
|
+
onclick_value.gsub(/\A.*\('/, '').gsub(/'.*\Z/,'')
|
32
|
+
end
|
33
|
+
|
34
|
+
def extract_post_parameters link
|
35
|
+
onclick_value = link.attribute('onclick').value
|
36
|
+
onclick_value.gsub(/'/,'').split(',')[3]
|
37
|
+
end
|
38
|
+
|
39
|
+
def submit_navigation_form action, parameters
|
40
|
+
navigation_form = @agent.page.form
|
41
|
+
navigation_form.action = action
|
42
|
+
navigation_form.__PARAMETERS = parameters
|
43
|
+
navigation_form.method = 'POST'
|
44
|
+
navigation_form.submit
|
45
|
+
end
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
|
50
|
+
def search selector
|
51
|
+
@agent.page.search(selector)
|
52
|
+
end
|
53
|
+
|
54
|
+
def find_first selector
|
55
|
+
@agent.page.at selector
|
56
|
+
end
|
57
|
+
|
58
|
+
def extract_text selector
|
59
|
+
element = find_first(selector)
|
60
|
+
element ? element.text.strip : ''
|
61
|
+
end
|
62
|
+
|
63
|
+
def extract_texts selector
|
64
|
+
search(selector).map(&:text).map(&:strip)
|
65
|
+
end
|
66
|
+
|
67
|
+
def can_find? selector
|
68
|
+
not search(selector).empty?
|
69
|
+
end
|
70
|
+
|
71
|
+
|
72
|
+
def get_form
|
73
|
+
@agent.page.form
|
74
|
+
end
|
75
|
+
|
76
|
+
|
77
|
+
end
|
78
|
+
end
|
@@ -0,0 +1,51 @@
|
|
1
|
+
module Mbanker
|
2
|
+
class PersistentCrawler
|
3
|
+
|
4
|
+
def initialize crawler, authenticater
|
5
|
+
@crawler, @authenticator = crawler, authenticater
|
6
|
+
if @authenticator.authenticated?
|
7
|
+
@authenticator.authenticate!
|
8
|
+
end
|
9
|
+
end
|
10
|
+
|
11
|
+
def visit path_name
|
12
|
+
@crawler.visit path_name
|
13
|
+
unless @authenticator.session_error_absent?
|
14
|
+
@authenticator.authenticate!
|
15
|
+
@crawler.visit path_name
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
def click link_or_button
|
20
|
+
@crawler.click link_or_button
|
21
|
+
unless @authenticator.session_error_absent?
|
22
|
+
@authenticator.authenticate!
|
23
|
+
@crawler.visit link_or_button
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
def search selector
|
28
|
+
@crawler.search selector
|
29
|
+
end
|
30
|
+
|
31
|
+
def can_find? selector
|
32
|
+
@crawler.can_find? selector
|
33
|
+
end
|
34
|
+
|
35
|
+
def find_first selector
|
36
|
+
@crawler.find_first selector
|
37
|
+
end
|
38
|
+
|
39
|
+
def extract_text selector
|
40
|
+
@crawler.extract_text selector
|
41
|
+
end
|
42
|
+
|
43
|
+
def extract_texts selector
|
44
|
+
@crawler.extract_texts selector
|
45
|
+
end
|
46
|
+
|
47
|
+
def get_form
|
48
|
+
@crawler.get_form
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
@@ -0,0 +1,16 @@
|
|
1
|
+
module Mbanker
|
2
|
+
class Session
|
3
|
+
attr_accessor :crawler, :persistent_crawler
|
4
|
+
|
5
|
+
def initialize crawler, authorizer
|
6
|
+
@crawler, @authorizer = crawler, authorizer
|
7
|
+
@persistent_crawler = Mbanker::PersistentCrawler.new @crawler, @authorizer
|
8
|
+
end
|
9
|
+
|
10
|
+
def accounts
|
11
|
+
@accounts_list ||= Mbanker::AccountsList.new @persistent_crawler
|
12
|
+
@accounts_list.accounts
|
13
|
+
end
|
14
|
+
|
15
|
+
end
|
16
|
+
end
|
data/mbanker.gemspec
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "mbanker/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "mbanker"
|
7
|
+
s.version = Mbanker::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Michał Taszycki"]
|
10
|
+
s.email = ["mtaszycki@gmail.com"]
|
11
|
+
s.homepage = "https://github.com/mehowte/mbanker"
|
12
|
+
s.summary = %q{Missing API for online mBank services}
|
13
|
+
s.description = %q{Provides access to online mBank services.}
|
14
|
+
|
15
|
+
s.rubyforge_project = "mbanker"
|
16
|
+
|
17
|
+
s.add_dependency "mechanize"
|
18
|
+
|
19
|
+
s.add_development_dependency "rspec"
|
20
|
+
s.add_development_dependency "guard"
|
21
|
+
s.add_development_dependency "guard-rspec"
|
22
|
+
s.add_development_dependency "growl"
|
23
|
+
|
24
|
+
s.files = `git ls-files`.split("\n")
|
25
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
26
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
27
|
+
s.require_paths = ["lib"]
|
28
|
+
end
|
@@ -0,0 +1,52 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mbanker
|
4
|
+
describe Authenticator do
|
5
|
+
let(:password) { double("password") }
|
6
|
+
let(:login) { double("login") }
|
7
|
+
let(:crawler) { double("crawler") }
|
8
|
+
let(:search_result) { double("search_result") }
|
9
|
+
let(:login_form) { double("login_form") }
|
10
|
+
|
11
|
+
subject { Authenticator.new crawler, login, password }
|
12
|
+
|
13
|
+
describe "#session_error_absent?" do
|
14
|
+
it "searches for appropriate element on current page" do
|
15
|
+
crawler.should_receive(:can_find?).with('.error.noSession') do
|
16
|
+
search_result.as_null_object
|
17
|
+
end
|
18
|
+
subject.session_error_absent?
|
19
|
+
end
|
20
|
+
|
21
|
+
it "recognizes when error element is found" do
|
22
|
+
crawler.stub(:can_find?) { true }
|
23
|
+
subject.session_error_absent?.should == false
|
24
|
+
crawler.stub(:can_find?) { false }
|
25
|
+
subject.session_error_absent?.should == true
|
26
|
+
end
|
27
|
+
end
|
28
|
+
|
29
|
+
describe "#authenticate!" do
|
30
|
+
it "visits login page" do
|
31
|
+
crawler.as_null_object.should_receive(:visit).with(:login)
|
32
|
+
subject.authenticate!
|
33
|
+
end
|
34
|
+
it "submits credentials" do
|
35
|
+
crawler.as_null_object.should_receive(:get_form) { login_form }
|
36
|
+
login_form.should_receive(:customer).with(:login)
|
37
|
+
login_form.should_receive(:password).with(:password)
|
38
|
+
login_form.should_receive(:submit)
|
39
|
+
subject.authenticate!
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
|
44
|
+
describe "#unauthenticate!" do
|
45
|
+
it "visits logout page" do
|
46
|
+
crawler.should_receive(:visit).with(:logout)
|
47
|
+
subject.unauthenticate!
|
48
|
+
end
|
49
|
+
end
|
50
|
+
end
|
51
|
+
end
|
52
|
+
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
module Mbanker
|
4
|
+
describe Session do
|
5
|
+
let(:accounts_list) { double("accounts_list").as_null_object }
|
6
|
+
let(:accounts) { double("accounts").as_null_object }
|
7
|
+
let(:crawler) { double("crawler").as_null_object }
|
8
|
+
let(:authorizer) { double("authorizer").as_null_object }
|
9
|
+
let(:persistent_crawler) { double("persistent_crawler").as_null_object }
|
10
|
+
|
11
|
+
subject { Session.new crawler, authorizer }
|
12
|
+
|
13
|
+
before do
|
14
|
+
Mbanker::PersistentCrawler.stub(:new) { persistent_crawler }
|
15
|
+
Mbanker::AccountsList.stub(:new) { accounts_list }
|
16
|
+
end
|
17
|
+
|
18
|
+
describe "#accounts" do
|
19
|
+
it "returns new accounts list" do
|
20
|
+
Mbanker::AccountsList.should_receive(:new) { accounts_list }
|
21
|
+
accounts_list.stub(:accounts) { accounts }
|
22
|
+
subject.accounts.should == accounts
|
23
|
+
end
|
24
|
+
|
25
|
+
it "initializes accounts list with persistent crawler" do
|
26
|
+
Mbanker::AccountsList.should_receive(:new).with(persistent_crawler)
|
27
|
+
subject.accounts
|
28
|
+
end
|
29
|
+
|
30
|
+
it "memoizes accounts list" do
|
31
|
+
Mbanker::AccountsList.should_receive(:new).once
|
32
|
+
subject.accounts
|
33
|
+
subject.accounts
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
@@ -0,0 +1,36 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe Mbanker do
|
4
|
+
|
5
|
+
describe "#create_session" do
|
6
|
+
|
7
|
+
let(:username) { "a username" }
|
8
|
+
let(:password) { "a password" }
|
9
|
+
|
10
|
+
let(:crawler) { double("crawler") }
|
11
|
+
let(:authenticator) { double("authenticator") }
|
12
|
+
let(:session) { double("session") }
|
13
|
+
|
14
|
+
before do
|
15
|
+
Mbanker::Crawler.stub(:new) { crawler }
|
16
|
+
Mbanker::Authenticator.stub(:new) { authenticator }
|
17
|
+
Mbanker::Session.stub(:new) { session }
|
18
|
+
end
|
19
|
+
|
20
|
+
it "creates new crawler" do
|
21
|
+
Mbanker::Crawler.should_receive(:new)
|
22
|
+
Mbanker::create_session username, password
|
23
|
+
end
|
24
|
+
|
25
|
+
it "creates new authenticator with crawler and credentials" do
|
26
|
+
Mbanker::Authenticator.should_receive(:new).with(crawler, username, password)
|
27
|
+
Mbanker::create_session username, password
|
28
|
+
end
|
29
|
+
|
30
|
+
it "returns new session constructed with crawler and credentials" do
|
31
|
+
Mbanker::Session.should_receive(:new).with(crawler, authenticator) { session }
|
32
|
+
|
33
|
+
Mbanker::create_session(username, password).should == session
|
34
|
+
end
|
35
|
+
end
|
36
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
require_relative '../lib/mbanker'
|
metadata
ADDED
@@ -0,0 +1,130 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: mbanker
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- "Micha\xC5\x82 Taszycki"
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-07-01 00:00:00 Z
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: mechanize
|
17
|
+
prerelease: false
|
18
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
19
|
+
none: false
|
20
|
+
requirements:
|
21
|
+
- - ">="
|
22
|
+
- !ruby/object:Gem::Version
|
23
|
+
version: "0"
|
24
|
+
type: :runtime
|
25
|
+
version_requirements: *id001
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
prerelease: false
|
29
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
30
|
+
none: false
|
31
|
+
requirements:
|
32
|
+
- - ">="
|
33
|
+
- !ruby/object:Gem::Version
|
34
|
+
version: "0"
|
35
|
+
type: :development
|
36
|
+
version_requirements: *id002
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
name: guard
|
39
|
+
prerelease: false
|
40
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
42
|
+
requirements:
|
43
|
+
- - ">="
|
44
|
+
- !ruby/object:Gem::Version
|
45
|
+
version: "0"
|
46
|
+
type: :development
|
47
|
+
version_requirements: *id003
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: guard-rspec
|
50
|
+
prerelease: false
|
51
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
52
|
+
none: false
|
53
|
+
requirements:
|
54
|
+
- - ">="
|
55
|
+
- !ruby/object:Gem::Version
|
56
|
+
version: "0"
|
57
|
+
type: :development
|
58
|
+
version_requirements: *id004
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: growl
|
61
|
+
prerelease: false
|
62
|
+
requirement: &id005 !ruby/object:Gem::Requirement
|
63
|
+
none: false
|
64
|
+
requirements:
|
65
|
+
- - ">="
|
66
|
+
- !ruby/object:Gem::Version
|
67
|
+
version: "0"
|
68
|
+
type: :development
|
69
|
+
version_requirements: *id005
|
70
|
+
description: Provides access to online mBank services.
|
71
|
+
email:
|
72
|
+
- mtaszycki@gmail.com
|
73
|
+
executables: []
|
74
|
+
|
75
|
+
extensions: []
|
76
|
+
|
77
|
+
extra_rdoc_files: []
|
78
|
+
|
79
|
+
files:
|
80
|
+
- .gitignore
|
81
|
+
- Gemfile
|
82
|
+
- Guardfile
|
83
|
+
- MIT-LICENSE
|
84
|
+
- README.markdown
|
85
|
+
- Rakefile
|
86
|
+
- lib/mbanker.rb
|
87
|
+
- lib/mbanker/account.rb
|
88
|
+
- lib/mbanker/accounts_list.rb
|
89
|
+
- lib/mbanker/authenticator.rb
|
90
|
+
- lib/mbanker/crawler.rb
|
91
|
+
- lib/mbanker/persistent_crawler.rb
|
92
|
+
- lib/mbanker/session.rb
|
93
|
+
- lib/mbanker/version.rb
|
94
|
+
- mbanker.gemspec
|
95
|
+
- spec/lib/mbanker/authenticator.rb
|
96
|
+
- spec/lib/mbanker/session_spec.rb
|
97
|
+
- spec/lib/mbanker_spec.rb
|
98
|
+
- spec/spec_helper.rb
|
99
|
+
homepage: https://github.com/mehowte/mbanker
|
100
|
+
licenses: []
|
101
|
+
|
102
|
+
post_install_message:
|
103
|
+
rdoc_options: []
|
104
|
+
|
105
|
+
require_paths:
|
106
|
+
- lib
|
107
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
108
|
+
none: false
|
109
|
+
requirements:
|
110
|
+
- - ">="
|
111
|
+
- !ruby/object:Gem::Version
|
112
|
+
version: "0"
|
113
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
114
|
+
none: false
|
115
|
+
requirements:
|
116
|
+
- - ">="
|
117
|
+
- !ruby/object:Gem::Version
|
118
|
+
version: "0"
|
119
|
+
requirements: []
|
120
|
+
|
121
|
+
rubyforge_project: mbanker
|
122
|
+
rubygems_version: 1.8.5
|
123
|
+
signing_key:
|
124
|
+
specification_version: 3
|
125
|
+
summary: Missing API for online mBank services
|
126
|
+
test_files:
|
127
|
+
- spec/lib/mbanker/authenticator.rb
|
128
|
+
- spec/lib/mbanker/session_spec.rb
|
129
|
+
- spec/lib/mbanker_spec.rb
|
130
|
+
- spec/spec_helper.rb
|