bankscrap 1.0.4 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: e0cc99604f8b8921d6ecbf987686300f460113d5
4
- data.tar.gz: d2fa8d351088f6386753b955606724f0e345c67a
3
+ metadata.gz: 7e9fea8d54632ad5388ccd2cd6075fbe0dd69bcc
4
+ data.tar.gz: 681e5691f14fbaa556502d5da1f16d4dff3b27be
5
5
  SHA512:
6
- metadata.gz: 564a3bb5e22a61f54254fe82f853a2b4bfcf3f356c6930940241e25d028d20bae5467ab0db06faaadfce30c7c0fa79e699d9c31c54d1f6126e09d64edd3b6927
7
- data.tar.gz: 8c51bff3b08ab398e3b30d052dceff1d181dc1ae9b081f70f188c2044832e997d522f174e127a2ae7081dbf478344fde943f135bb0e52ebb5d0587ab399183e1
6
+ metadata.gz: 23d25b06fbb967b07673077bb58cf8c214e1ab403fedfd511362c39d198923232c7d00473ae30b5b0731a45e3112e887ab23c696c4744405def72c3c4456e265
7
+ data.tar.gz: d828191804b5f7e55ff58cd78da48ecaac34bb8687b01cb1459b2d42b5b55750ec3cc42a400e84772548255ef9a98e5cc8e1fb4b2af19e9eab1e4990072b41ae
data/README.md CHANGED
@@ -59,42 +59,47 @@ Note that you only need to install the gem for your selected bank – the main g
59
59
 
60
60
  ###### BBVA
61
61
 
62
- $ bankscrap balance YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD
62
+ $ bankscrap balance YourBank --credentials=user:YOUR_BANK_USER password:YOUR_BANK_PASSWORD
63
63
 
64
64
  ###### ING Direct
65
65
  ING needs one more argument: your birthday.
66
66
 
67
- $ bankscrap balance ING --user YOUR_DNI --password YOUR_PASSWORD --extra=birthday:01/01/1980
67
+ $ bankscrap balance ING --credentials=user:YOUR_DNI password:YOUR_BANK_PASSWORD birthday:01/01/1980
68
68
 
69
69
  Replace 01/01/1980 with your actual birthday.
70
70
 
71
71
  #### Transactions for last 30 days
72
72
  ###### BBVA
73
73
 
74
- $ bankscrap transactions BBVA --user YOUR_BBVA_USER --password YOUR_BBVA_PASSWORD
74
+ $ bankscrap transactions BBVA --credentials=user:YOUR_BANK_USER password:YOUR_BANK_PASSWORD
75
75
 
76
76
  ###### ING Direct
77
77
 
78
- $ bankscrap transactions ING --user YOUR_DNI --password YOUR_PASSWORD --extra=birthday:01/01/1980
78
+ $ bankscrap transactions ING --credentials=nif:YOUR_DNI password:YOUR_BANK_PASSWORD birthday:01/01/1980
79
79
 
80
80
  #### Transactions with date range
81
81
 
82
- $ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --from 01-01-2015 --to 01-02-2015
82
+ $ bankscrap transactions YourBank --credentials=user:YOUR_BANK_USER password:YOUR_BANK_PASSWORD --from 01-01-2015 --to 01-02-2015
83
83
 
84
84
  ---
85
85
 
86
86
  By default it will use your first bank account, if you want to fetch transactions for a different account you can use this syntax:
87
87
 
88
- $ bankscrap transactions YourBank --iban "your_iban" --user YOUR_DNI --password YOUR_PASSWORD
88
+ $ bankscrap transactions YourBank --iban "your_iban" --credentials=user:YOUR_BANK_USER password:YOUR_BANK_PASSWORD
89
89
 
90
90
  If you don't want to pass your user and password everytime you can define them in your .bash_profile by adding:
91
91
 
92
- export BANK_SCRAP_USER=YOUR_BANK_USER
93
- export BANK_SCRAP_PASSWORD=YOUR_BANK_PASSWORD
92
+ export BANKSCRAP_[BANK_NAME]_USER=YOUR_BANK_USER
93
+ export BANKSCRAP_[BANK_NAME]_PASSWORD=YOUR_BANK_USER
94
+ export BANKSCRAP_[BANK_NAME]_ANY_OTHER_CREDENTIAL=ANY_OTHER_CREDENTIAL
95
+
96
+ eg:
97
+ export BANKSCRAP_BBVA_NET_CASH_USER=YOUR_BANK_USER
98
+
94
99
 
95
100
  #### Export transactions to CSV
96
101
 
97
- $ bankscrap transactions YourBank --user YOUR_BANK_USER --password YOUR_BANK_PASSWORD --format CSV [--output ./my_transactions.csv]
102
+ $ bankscrap transactions YourBank --credentials=user:YOUR_BANK_USER password:YOUR_BANK_PASSWORD --format CSV [--output ./my_transactions.csv]
98
103
 
99
104
  Currently only CSV is supported. The output parameter is optional, by default `transactions.csv` is used.
100
105
 
@@ -106,11 +111,11 @@ You can also use this gem from your own app as library. To do so first you must
106
111
  ```ruby
107
112
  # BBVA
108
113
  require 'bankscrap-bbva'
109
- bbva = Bankscrap::BBVA::Bank.new(YOUR_BBVA_USER, YOUR_BBVA_PASSWORD)
114
+ bbva = Bankscrap::BBVA::Bank.new(user: YOUR_BBVA_USER, password: YOUR_BBVA_PASSWORD)
110
115
 
111
116
  # ING
112
117
  require 'bankscrap-ing'
113
- ing = Bankscrap::ING::Bank.new(YOUR_DNI, YOUR_ING_PASSWORD, extra_args: {"birthday" => "dd/mm/yyyy"})
118
+ ing = Bankscrap::ING::Bank.new(nif: YOUR_NIF, password: YOUR_ING_PASSWORD, birthday: "dd/mm/yyyy")
114
119
  ```
115
120
 
116
121
 
@@ -1,6 +1,6 @@
1
1
  # Bankscrap::<%= module_name %>
2
2
 
3
- Bankscrap adapter for <%= bank_name %>
3
+ [Bankscrap](https://github.com/bankscrap/bankscrap) adapter for <%= bank_name %>.
4
4
 
5
5
  **TODO**: write a proper description for your adapter.
6
6
 
@@ -26,12 +26,12 @@ Or install it yourself as:
26
26
  ### From terminal
27
27
  #### Bank account balance
28
28
 
29
- $ bankscrap balance <%= module_name %> --user YOUR_USER --password YOUR_PASSWORD --extra=company_code:YOUR_COMPANY_CODE
29
+ $ bankscrap balance <%= module_name %> --credentials=user:YOUR_USER --password:YOUR_PASSWORD --any_other_credential:ANY_OTHER_CREDENTIAL
30
30
 
31
31
 
32
32
  #### Transactions
33
33
 
34
- $ bankscrap transactions <%= module_name %> --user YOUR_USER --password YOUR_PASSWORD --extra=company_code:YOUR_COMPANY_CODE
34
+ $ bankscrap transactions <%= module_name %> --credentials=user:YOUR_USER --password:YOUR_PASSWORD --any_other_credential:ANY_OTHER_CREDENTIAL
35
35
 
36
36
  ---
37
37
 
@@ -39,11 +39,9 @@ For more details on usage instructions please read [Bankscrap readme](https://gi
39
39
 
40
40
  ### From Ruby code
41
41
 
42
- **TODO**: check if your bank adapter needs more extra_args for the initializer.
43
-
44
42
  ```ruby
45
43
  require '<%= gem_name %>'
46
- <%= bank_name.underscore %> = Bankscrap::<%= module_name %>::Bank.new(YOUR_USER, YOUR_PASSWORD, extra_args: {arg: EXTRA_ARG_1})
44
+ <%= bank_name.underscore %> = Bankscrap::<%= module_name %>::Bank.new(user: YOUR_USER, password: YOUR_PASSWORD, any_other_credential: ANY_OTHER_CREDENTIAL)
47
45
  ```
48
46
 
49
47
 
@@ -11,23 +11,20 @@ module Bankscrap
11
11
  # ACCOUNTS_ENDPOINT = '/accounts'.freeze
12
12
  # TRANSACTIONS_ENDPOINT = '/transactions'.freeze
13
13
 
14
- def initialize(user, password, log: false, debug: false, extra_args: nil)
15
- @user = user
16
- @password = password
17
- @log = log
18
- @debug = debug
19
- # @extra_arg1 = extra_args.with_indifferent_access['extra_arg1']
14
+ # TODO: change this for the proper credentials required in your adapter.
15
+ # It can be anything (user, birthday, ID, whatever you need).
16
+ REQUIRED_CREDENTIALS = [:user, :password, :any_other_credential]
20
17
 
21
- initialize_connection
18
+ def initialize(credentials = {})
19
+ super do
20
+ # Here you can do further processing of the received credentials
21
+ # or add custom headers to the HTTP client
22
22
 
23
- # Optional Custom headers
24
- # user_agent = SecureRandom.hex(32).upcase + ';Android;LGE;Nexus 5;1080x1776;Android;5.1.1;BMES;4.4;xxhd'
25
- # add_headers(
26
- # 'User-Agent' => user_agent
27
- # )
28
-
29
- login
30
- super
23
+ # user_agent = SecureRandom.hex(32).upcase + ';Android;LGE;Nexus 5;1080x1776;Android;5.1.1;BMES;4.4;xxhd'
24
+ # add_headers(
25
+ # 'User-Agent' => user_agent
26
+ # )
27
+ end
31
28
  end
32
29
 
33
30
  # Fetch all the accounts for the given user
@@ -1,10 +1,15 @@
1
1
  module Bankscrap
2
2
  class Account
3
3
  include Utils::Inspectable
4
-
5
- attr_accessor :bank, :id, :name, :balance, :currency, :available_balance, :description, :transactions, :iban, :bic
4
+
5
+ attr_accessor :bank, :id, :name, :balance,
6
+ :available_balance, :description,
7
+ :transactions, :iban, :bic
6
8
 
7
9
  def initialize(params = {})
10
+ raise NotMoneyObjectError.new(:balance) unless params[:balance].is_a?(Money)
11
+ raise NotMoneyObjectError.new(:available_balance) unless params[:available_balance].is_a?(Money)
12
+
8
13
  params.each { |key, value| send "#{key}=", value }
9
14
  end
10
15
 
@@ -16,10 +21,14 @@ module Bankscrap
16
21
  bank.fetch_transactions_for(self, start_date: start_date, end_date: end_date)
17
22
  end
18
23
 
24
+ def currency
25
+ balance.try(:currency)
26
+ end
27
+
19
28
  private
20
29
 
21
30
  def inspect_attributes
22
- %i(id name balance currency available_balance description iban bic)
31
+ %i(id name balance available_balance description iban bic)
23
32
  end
24
33
  end
25
34
  end
@@ -7,18 +7,46 @@ module Bankscrap
7
7
  'like Gecko) Chrome/18.0.1025.166 Mobile Safari/535.19'.freeze
8
8
  attr_accessor :headers, :accounts, :investments
9
9
 
10
- def initialize(_user, _password, log: false, debug: false, extra_args: nil)
10
+ REQUIRED_CREDENTIALS = [:user, :password]
11
+
12
+ class MissingCredential < ArgumentError; end
13
+
14
+ def initialize(credentials = {})
15
+ # Assign required credentials as env vars.
16
+ # If empty, use ENV vars as fallback:
17
+ # BANKSCRAP_MY_BANK_USER, BANKSCRAP_MY_BANK_PASWORD, etc.
18
+ self.class::REQUIRED_CREDENTIALS.each do |field|
19
+ value = credentials.with_indifferent_access[field] || ENV["#{env_vars_prefix}_#{field.upcase}"]
20
+
21
+ if value.blank?
22
+ raise MissingCredential, "Missing credential: '#{field}'"
23
+ else
24
+ instance_variable_set("@#{field}", value)
25
+ end
26
+ end
27
+
28
+ initialize_http_client
29
+
30
+ # Bank adapters should use the yield block to do any required processing of credentials
31
+ yield if block_given?
32
+
33
+ login
11
34
  @accounts = fetch_accounts
35
+
36
+ # Not all the adapters have support for investments
37
+ if self.respond_to?(:fetch_investments)
38
+ @investments = fetch_investments
39
+ end
12
40
  end
13
41
 
14
42
  # Interface method placeholders
15
43
 
16
- def fetch_accounts
17
- raise "#{self.class} should implement a fetch_account method"
44
+ def login
45
+ raise "#{self.class} should implement a login method"
18
46
  end
19
47
 
20
- def fetch_investments
21
- raise "#{self.class} should implement a fetch_investment method"
48
+ def fetch_accounts
49
+ raise "#{self.class} should implement a fetch_account method"
22
50
  end
23
51
 
24
52
  def fetch_transactions_for(*)
@@ -64,19 +92,27 @@ module Bankscrap
64
92
  @http.get(url).body
65
93
  end
66
94
 
67
- def initialize_connection
95
+ def initialize_http_client
68
96
  @http = Mechanize.new do |mechanize|
69
97
  mechanize.user_agent = WEB_USER_AGENT
70
98
  mechanize.agent.http.verify_mode = OpenSSL::SSL::VERIFY_NONE
71
- mechanize.log = Logger.new(STDOUT) if @debug
72
- # mechanize.set_proxy 'localhost', 8888
99
+ mechanize.log = Logger.new(STDOUT) if Bankscrap.debug
100
+
101
+ if Bankscrap.proxy
102
+ mechanize.set_proxy Bankscrap.proxy[:host], Bankscrap.proxy[:port]
103
+ end
73
104
  end
74
105
 
75
106
  @headers = {}
76
107
  end
77
108
 
78
109
  def log(msg)
79
- puts msg if @log
110
+ puts msg if Bankscrap.log
111
+ end
112
+
113
+ # Prefix for env vars used to store credentials
114
+ def env_vars_prefix
115
+ self.class.parent.name.underscore.upcase.gsub('/', '_')
80
116
  end
81
117
  end
82
118
  end
data/lib/bankscrap/cli.rb CHANGED
@@ -8,22 +8,15 @@ end
8
8
  module Bankscrap
9
9
  class CLI < Thor
10
10
  def self.shared_options
11
- option :user, default: ENV['BANKSCRAP_USER']
12
- option :password, default: ENV['BANKSCRAP_PASSWORD']
13
- option :log, default: false
14
- option :debug, default: false
15
- option :iban, default: nil
16
-
11
+ option :credentials, default: {}, type: :hash
12
+ option :log, default: false
13
+ option :debug, default: false
14
+ option :iban, default: nil
17
15
  option :format
18
16
  option :output
19
-
20
- # Some bank needs more input, like birthday, this would go here
21
- # Usage:
22
- # bankscrap balance BANK_NAME --extra=birthday:01/12/1980
23
- option :extra, type: :hash, default: {}
24
17
  end
25
18
 
26
- desc 'balance BANK', "get accounts' balance"
19
+ desc 'balance BankName', "get accounts' balance"
27
20
  shared_options
28
21
  def balance(bank)
29
22
  assign_shared_options
@@ -31,11 +24,14 @@ module Bankscrap
31
24
 
32
25
  @client.accounts.each do |account|
33
26
  say "Account: #{account.description} (#{account.iban})", :cyan
34
- say "Balance: #{account.balance}", :green
27
+ say "Balance: #{account.balance.format}", :green
28
+ if account.balance != account.available_balance
29
+ say "Available: #{account.available_balance.format}", :yellow
30
+ end
35
31
  end
36
32
  end
37
33
 
38
- desc 'transactions BANK', "get account's transactions"
34
+ desc 'transactions BankName', "get account's transactions"
39
35
  shared_options
40
36
  options from: :string, to: :string
41
37
  def transactions(bank)
@@ -74,17 +70,17 @@ module Bankscrap
74
70
  private
75
71
 
76
72
  def assign_shared_options
77
- @user = options[:user]
78
- @password = options[:password]
79
- @iban = options[:iban]
80
- @log = options[:log]
81
- @debug = options[:debug]
82
- @extra_args = options[:extra]
73
+ @credentials = options[:credentials]
74
+ @iban = options[:iban]
75
+ @log = options[:log]
76
+ @debug = options[:debug]
83
77
  end
84
78
 
85
79
  def initialize_client_for(bank_name)
86
80
  bank_class = find_bank_class_for(bank_name)
87
- @client = bank_class.new(@user, @password, log: @log, debug: @debug, extra_args: @extra_args)
81
+ Bankscrap.log = @log
82
+ Bankscrap.debug = @debug
83
+ @client = bank_class.new(@credentials)
88
84
  end
89
85
 
90
86
  def find_bank_class_for(bank_name)
@@ -2,11 +2,12 @@ module Bankscrap
2
2
  class Transaction
3
3
  include Utils::Inspectable
4
4
 
5
- attr_accessor :id, :amount, :currency,
6
- :effective_date, :description,
5
+ attr_accessor :id, :amount, :description, :effective_date,
7
6
  :balance, :account
8
7
 
9
8
  def initialize(params = {})
9
+ raise NotMoneyObjectError.new(:amount) unless params[:amount].is_a?(Money)
10
+
10
11
  params.each { |key, value| send "#{key}=", value }
11
12
  end
12
13
 
@@ -18,14 +19,14 @@ module Bankscrap
18
19
  [effective_date.strftime('%d/%m/%Y'), description, amount]
19
20
  end
20
21
 
22
+ def currency
23
+ amount.currency
24
+ end
25
+
21
26
  private
22
27
 
23
28
  def inspect_attributes
24
- [
25
- :id, :amount, :currency,
26
- :effective_date, :description,
27
- :balance
28
- ]
29
+ [ :id, :amount, :effective_date, :description, :balance ]
29
30
  end
30
31
  end
31
32
  end
@@ -1,3 +1,3 @@
1
1
  module Bankscrap
2
- VERSION = '1.0.4'.freeze
2
+ VERSION = '2.0.0'.freeze
3
3
  end
data/lib/bankscrap.rb CHANGED
@@ -10,3 +10,22 @@ require_relative 'bankscrap/account'
10
10
  require_relative 'bankscrap/investment'
11
11
  require_relative 'bankscrap/transaction'
12
12
  require_relative 'bankscrap/exporters/csv'
13
+
14
+ module Bankscrap
15
+ class << self
16
+ attr_accessor :log
17
+ attr_accessor :debug
18
+ attr_accessor :proxy
19
+ end
20
+
21
+ class NotMoneyObjectError < TypeError
22
+ def initialize(attribute)
23
+ super("#{attribute} should be a Money object")
24
+ end
25
+ end
26
+
27
+
28
+ self.log = false
29
+ self.debug = false
30
+ # self.proxy = {host: 'localhost', port: 8888}
31
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bankscrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.4
4
+ version: 2.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Javier Cuevas
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2016-05-02 00:00:00.000000000 Z
12
+ date: 2016-06-01 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -73,6 +73,20 @@ dependencies:
73
73
  - - "~>"
74
74
  - !ruby/object:Gem::Version
75
75
  version: 0.39.0
76
+ - !ruby/object:Gem::Dependency
77
+ name: rspec
78
+ requirement: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: 3.4.0
83
+ type: :development
84
+ prerelease: false
85
+ version_requirements: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - "~>"
88
+ - !ruby/object:Gem::Version
89
+ version: 3.4.0
76
90
  - !ruby/object:Gem::Dependency
77
91
  name: thor
78
92
  requirement: !ruby/object:Gem::Requirement
@@ -150,7 +164,6 @@ files:
150
164
  - generators/templates/lib/%gem_name%.rb.tt
151
165
  - generators/templates/lib/bankscrap/%bank_name_dasherized%/bank.rb.tt
152
166
  - generators/templates/lib/bankscrap/%bank_name_dasherized%/version.rb.tt
153
- - lib/.DS_Store
154
167
  - lib/bankscrap.rb
155
168
  - lib/bankscrap/account.rb
156
169
  - lib/bankscrap/bank.rb
@@ -182,7 +195,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
182
195
  version: '0'
183
196
  requirements: []
184
197
  rubyforge_project:
185
- rubygems_version: 2.6.4
198
+ rubygems_version: 2.5.1
186
199
  signing_key:
187
200
  specification_version: 4
188
201
  summary: Get your bank account details.
data/lib/.DS_Store DELETED
Binary file