bank_scrap 0.0.13 → 0.0.14

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 72a10733f8205d87884e40ba46e1d783317c0670
4
- data.tar.gz: 03caab3dceaf26a5101bf18f1078b19c0382f6ef
3
+ metadata.gz: 032037fabd4f7fdb19e19a15c284f1f4d81ebd98
4
+ data.tar.gz: 0084c4701ff1ceb0e498c173e63819ce4a8d9404
5
5
  SHA512:
6
- metadata.gz: a0b2753998bdd9c2d523c0bf058080afd56b595d4fcb24a0199c8fcfed5d2b805b94b211b3d465359ed7a887e6c5bfa5f35eea8e3b78f954883be3198e4a3c87
7
- data.tar.gz: 0a50ff4c20b0f2423f358dd7114f53960c1034629ed29b3b042bcfcb223564e8c526be6c38d1200d4bce6c0c746c4122fe780d429982fd26cfa5a3dc6c89cbc1
6
+ metadata.gz: 30a368317e1cc336e7d179ce2119d4937ef666eef1ef3603e159b9a273414c49e57734d100f7ac2882ade92520d294358162b9745497342b3936a99f9af5f30c
7
+ data.tar.gz: a73e6cf9b6cc440d37c3bee5edb9e54418eed33b668ff96cf3d44f7b28717ab4b99cec78dbc36a513190061e43b41dc1f160fe006c822c60097e39450e39393b
@@ -57,7 +57,6 @@ module BankScrap
57
57
  # Returns an array of BankScrap::Transaction objects
58
58
  def fetch_transactions_for(account, start_date: Date.today - 1.month, end_date: Date.today)
59
59
  from_date = start_date.strftime('%Y-%m-%d')
60
- to_date = end_date.strftime('%Y-%m-%d')
61
60
 
62
61
  # Misteriously we need a specific content-type here
63
62
  funny_headers = {
@@ -65,24 +64,36 @@ module BankScrap
65
64
  'BBVA-Method' => 'GET'
66
65
  }
67
66
 
67
+ # The API accepts a toDate param that we could pass the end_date argument,
68
+ # however when we pass the toDate param, the API stops returning the account balance.
69
+ # Therefore we need to take a workaround: only filter with fromDate and loop
70
+ # over all the available pages, filtering out the movements that doesn't match
71
+ # the end_date argument.
68
72
  url = BASE_ENDPOINT +
69
73
  ACCOUNT_ENDPOINT +
70
74
  account.id +
71
- "/movements/v1?fromDate=#{from_date}&toDate=#{to_date}"
75
+ "/movements/v1?fromDate=#{from_date}"
76
+
72
77
  offset = nil
78
+ pagination_balance = nil
73
79
  transactions = []
74
80
 
75
81
  with_headers(funny_headers) do
76
82
  # Loop over pagination
77
83
  loop do
78
84
  new_url = offset ? (url + "&offset=#{offset}") : url
85
+ new_url = pagination_balance ? (new_url + "&paginationBalance=#{pagination_balance}") : new_url
79
86
  json = JSON.parse(post(new_url, {}))
80
87
 
81
88
  unless json['movements'].blank?
82
- transactions += json['movements'].map do |data|
89
+ # As explained before, we have to discard records newer than end_date.
90
+ filtered_movements = json['movements'].select { |m| Date.parse(m['operationDate']) <= end_date }
91
+
92
+ transactions += filtered_movements.map do |data|
83
93
  build_transaction(data, account)
84
94
  end
85
95
  offset = json['offset']
96
+ pagination_balance = json['paginationBalance']
86
97
  end
87
98
 
88
99
  break unless json['thereAreMoreMovements'] == true
@@ -1,3 +1,3 @@
1
1
  module BankScrap
2
- VERSION = '0.0.13'
2
+ VERSION = '0.0.14'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bank_scrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 0.0.14
5
5
  platform: ruby
6
6
  authors:
7
7
  - Ismael Sánchez
@@ -11,7 +11,7 @@ authors:
11
11
  autorequire:
12
12
  bindir: bin
13
13
  cert_chain: []
14
- date: 2015-05-12 00:00:00.000000000 Z
14
+ date: 2015-06-17 00:00:00.000000000 Z
15
15
  dependencies:
16
16
  - !ruby/object:Gem::Dependency
17
17
  name: bundler