Class: BankScrap::Bbva
Constant Summary collapse
- BASE_ENDPOINT =
'https://bancamovil.grupobbva.com'- LOGIN_ENDPOINT =
'/DFAUTH/slod/DFServletXML'- PRODUCTS_ENDPOINT =
'/ENPP/enpp_mult_web_mobility_02/products/v1'- ACCOUNT_ENDPOINT =
'/ENPP/enpp_mult_web_mobility_02/accounts/'- USER_AGENT =
BBVA expects an identifier before the actual User Agent, but 12345 works fine
'12345;Android;LGE;Nexus 5;1080x1776;Android;4.4.4;BMES;4.0.4'
Constants inherited from Bank
BankScrap::Bank::WEB_USER_AGENT
Instance Attribute Summary
Attributes inherited from Bank
Instance Method Summary collapse
-
#fetch_accounts ⇒ Object
Fetch all the accounts for the given user Returns an array of BankScrap::Account objects.
-
#fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) ⇒ Object
Fetch transactions for the given account.
-
#initialize(user, password, log: false, debug: false, extra_args: nil) ⇒ Bbva
constructor
A new instance of Bbva.
Methods inherited from Bank
Constructor Details
#initialize(user, password, log: false, debug: false, extra_args: nil) ⇒ Bbva
Returns a new instance of Bbva.
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 |
# File 'lib/bank_scrap/banks/bbva.rb', line 12 def initialize(user, password, log: false, debug: false, extra_args: nil) @user = format_user(user.dup) @password = password @log = log @debug = debug initialize_connection set_headers({ "User-Agent" => USER_AGENT, 'BBVA-User-Agent' => USER_AGENT, 'Accept-Language' => 'spa', 'Content-Language' => 'spa', 'Accept' => 'application/json', 'Accept-Charset' => 'UTF-8', 'Connection' => 'Keep-Alive', 'Host' => 'bancamovil.grupobbva.com', 'Cookie2' => '$Version=1' }) login super end |
Instance Method Details
#fetch_accounts ⇒ Object
Fetch all the accounts for the given user Returns an array of BankScrap::Account objects
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/bank_scrap/banks/bbva.rb', line 38 def fetch_accounts log 'fetch_accounts' # Even if the required method is an HTTP POST # the API requires a funny header that says is a GET # otherwise the request doesn't work. response = with_headers({'BBVA-Method' => 'GET'}) do post(BASE_ENDPOINT + PRODUCTS_ENDPOINT, {}) end json = JSON.parse(response) json["accounts"].collect { |data| build_account(data) } end |
#fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) ⇒ Object
Fetch transactions for the given account. By default it fetches transactions for the last month, The maximum allowed by the BBVA API is the last 3 years.
Account should be a BankScrap::Account object Returns an array of BankScrap::Transaction objects
58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 |
# File 'lib/bank_scrap/banks/bbva.rb', line 58 def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today) fromDate = start_date.strftime("%Y-%m-%d") toDate = end_date.strftime("%Y-%m-%d") # Misteriously we need a specific content-type here funny_headers = { 'Content-Type' => 'application/json; charset=UTF-8', 'BBVA-Method' => 'GET' } url = BASE_ENDPOINT + ACCOUNT_ENDPOINT + account.id+ "/movements/v1?fromDate=#{fromDate}&toDate=#{toDate}" offset = nil transactions = [] with_headers(funny_headers) do # Loop over pagination loop do new_url = offset ? (url + "&offset=#{offset}") : url json = JSON.parse(post(new_url, {})) unless json["movements"].blank? transactions += json["movements"].collect { |data| build_transaction(data, account) } offset = json["offset"] end break unless json["thereAreMoreMovements"] == true end end transactions end |