Skip to content

Commit

Permalink
remove and ignore gem from repo (#2)
Browse files Browse the repository at this point in the history
* remove and ignore gem from repo

* Add open-uri gem

Is needed to read de api.ipify.org result

* Add loans and cards

* Bump version
  • Loading branch information
albfan authored and raulmarcosl committed Jul 16, 2018
1 parent 7270145 commit 4d84d41
Show file tree
Hide file tree
Showing 4 changed files with 61 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
*.gem
Binary file removed bankscrap-santander-1.1.0.gem
Binary file not shown.
60 changes: 59 additions & 1 deletion lib/bankscrap/santander/bank.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
require 'bankscrap'
require 'securerandom'
require 'open-uri'
require_relative 'account.rb'

module Bankscrap
Expand Down Expand Up @@ -37,6 +38,36 @@ def fetch_accounts
document.xpath('//cuentas/cuenta').map { |data| build_account(data) }
end

# Fetch all the cards for the given user
#
# Should returns an array of Bankscrap::Card objects
def fetch_cards
log 'fetch_cards'

headers = { "SOAPAction" => "http://www.isban.es/webservices/BAMOBI/Posglobal/F_bamobi_posicionglobal_lip/internet/BAMOBIPGL/v1/obtenerPosGlobal_LIP" }

response = with_headers(headers) { post(BASE_ENDPOINT + PRODUCTS_ENDPOINT, fields: xml_products) }

document = parse_context(response)

document.xpath('//tarjetas/tarjeta').map { |data| build_card(data) }
end

# Fetch all the loan for the given user
#
# Should returns an array of Bankscrap::Loan objects
def fetch_loans
log 'fetch_loans'

headers = { "SOAPAction" => "http://www.isban.es/webservices/BAMOBI/Posglobal/F_bamobi_posicionglobal_lip/internet/BAMOBIPGL/v1/obtenerPosGlobal_LIP" }

response = with_headers(headers) { post(BASE_ENDPOINT + PRODUCTS_ENDPOINT, fields: xml_products) }

document = parse_context(response)

document.xpath('//prestamos/prestamo').map { |data| build_loan(data) }
end

# Fetch transactions for the given account.
#
# Account should be a Bankscrap::Account object
Expand Down Expand Up @@ -110,6 +141,33 @@ def build_account(data)
)
end

# Build an Card object from API data
def build_card(data)
currency = value_at_xpath(data, 'impSaldoDispuesto/DIVISA', 'EUR')
Card.new(
bank: self,
id: value_at_xpath(data, 'comunes/contratoID/NUMERO_DE_CONTRATO'),
name: value_at_xpath(data, 'comunes/descContrato'),
pan: value_at_xpath(data, 'pan'),
amount: money(value_at_xpath(data, 'impSaldoDispuesto/IMPORTE'), currency),
avaliable: money(value_at_xpath(data, 'impDisponible/IMPORTE'), currency),
description: value_at_xpath(data, 'comunes/alias') || value_at_xpath(data, 'comunes/descContrato'),
is_credit: data.at_xpath('descTipoTarjeta').children.to_s == "Crédito"
)
end

# Build an Loan object from API data
def build_loan(data)
currency = value_at_xpath(data, 'impSaldoDispuesto/DIVISA')
Loan.new(
bank: self,
id: value_at_xpath(data, 'comunes/contratoID/NUMERO_DE_CONTRATO'),
name: value_at_xpath(data, 'comunes/descContrato'),
amount: money(value_at_xpath(data, 'impSaldoDispuesto/IMPORTE'), currency),
description: value_at_xpath(data, 'comunes/alias') || value_at_xpath(data, 'comunes/descContrato'),
)
end

# Build a transaction object from API data
def build_transaction(data, account)
currency = value_at_xpath(data, 'importe/DIVISA')
Expand Down Expand Up @@ -220,7 +278,7 @@ def xml_account(account, from_date, to_date, repo, importe_cta)

def value_at_xpath(node, xpath, default = '')
value = node.at_xpath(xpath)
value ? value.content.strip : default
value && !value.content.blank? ? value.content.strip : default
end

def money(data, currency)
Expand Down
2 changes: 1 addition & 1 deletion lib/bankscrap/santander/version.rb
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module Bankscrap
module Santander
VERSION = '1.1.0'.freeze
VERSION = '2.0.0'.freeze
end
end

0 comments on commit 4d84d41

Please sign in to comment.