apibanca-client 0.0.2 → 0.0.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +5 -0
- data/README.md +77 -2
- data/lib/apibanca/client/bank.rb +23 -22
- data/lib/apibanca/client/deposit.rb +6 -5
- data/lib/apibanca/client/job.rb +13 -0
- data/lib/apibanca/client/proxy_base.rb +9 -0
- data/lib/apibanca/client/routine.rb +15 -0
- data/lib/apibanca/client/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a11196cbf7114b0d8f73ee499966ccce88bbac70
|
4
|
+
data.tar.gz: 83c6061b12ba78d65e0092010f2460183f7d7867
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c332c62906ff60196c88eef8b4ac11461b854ca01871496622b8cbdc61e7019a01065a7bbea834f508cf0142d90a46481cfb01e4a62bdfc240fdc46a0afeea23
|
7
|
+
data.tar.gz: 814cbbb7f4399a44a358cb918c94b479255eb1942a8e2e5a046f09fed324152ecfcaf565428edf2f627d95e11309ec26fad27cb7c20e39b30926387403292b1a
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -37,9 +37,84 @@ client = Apibanca::Client.new(API_KEY)
|
|
37
37
|
Los bancos pueden ser creados a través de la interfaz web o desde esta gema. Para crear un banco desde la gema, hay que proveer todos los parámetros solicitados por la clase `Apibanca::Bank::BankCreationParams`.
|
38
38
|
|
39
39
|
```ruby
|
40
|
-
params = Apibanca::Bank::BankCreationParams.new(name: "BICE", user: "
|
40
|
+
params = Apibanca::Bank::BankCreationParams.new(name: "BICE", user: "...", pass: "...", account: "...")
|
41
41
|
# => #<Apibanca::Bank::BankCreationParams account="..." name="BICE" pass="..." user="...">
|
42
|
+
|
42
43
|
banco = Apibanca::Bank.create(client, params)
|
43
44
|
# -> POST http://api-banca.herokuapp.com/api/2013-11-4/banks/ [{:bank=>{"name"=>"BICE", "user"=>"...", "pass"=>"...", "account"=>"..."}} params]
|
44
|
-
# Banco BICE /
|
45
|
+
# => (Banco 3304) BICE / <usuario> / <cuenta>
|
46
|
+
|
47
|
+
banco.id
|
48
|
+
# => 3304
|
49
|
+
```
|
50
|
+
|
51
|
+
### Estatus del banco
|
52
|
+
|
53
|
+
Indica si los parámetros de acceso a la cuenta son correctos. Nota: asegúrate de que lo sean; de otra forma el banco puede bloquear el acceso a la cuenta.
|
54
|
+
|
55
|
+
```ruby
|
56
|
+
# banco = Apibanca::Bank.create(...)
|
57
|
+
banco.status # sólo se puede utilizar cuando cambie a 'ready'. Este cambio de estado toma 5 minutos aproximadamente.
|
58
|
+
# => idle
|
59
|
+
|
60
|
+
banco.refresh! # recarga el proxy desde el servidor
|
61
|
+
# -> GET http://api-banca.herokuapp.com/api/2013-11-4/banks/3304
|
62
|
+
# -> GET http://api-banca.herokuapp.com/api/2013-11-4/routines/23444
|
63
|
+
# => (Banco 3304) BICE / <usuario> / <cuenta>
|
64
|
+
banco.status
|
65
|
+
# => working
|
66
|
+
|
67
|
+
banco.refresh! # unos minutos más tarde...
|
68
|
+
# ...
|
69
|
+
banco.status
|
70
|
+
# => ready
|
71
|
+
```
|
72
|
+
|
73
|
+
### Rutinas
|
74
|
+
|
75
|
+
Permiten agendar una tarea periódica en un banco. Por ejemplo, leer la cartola.
|
76
|
+
|
77
|
+
```ruby
|
78
|
+
# Todos los bancos incluyen una rutina inicial que se ejecuta cuando el banco es creado.
|
79
|
+
banco.routines
|
80
|
+
# => [(Rutina 23444) Setup inicial
|
81
|
+
|
82
|
+
# Añadiremos una rutina para leer la cartola y crear depósitos
|
83
|
+
banco.add_routine Apibanca::Bank::RoutineCreationParams.new(nombre: "LectorDepósitos", target: "cartola", what_to_do: "acumular")
|
84
|
+
# => (Rutina 23449) LectorDepósitos acumular:cartola tasks=0
|
85
|
+
|
86
|
+
# Para que la rutina trabaje, hay que indicar la frecuencia
|
87
|
+
routine = bank.routines.last
|
88
|
+
# => (Rutina 23449) LectorDepósitos acumular:cartola tasks=0
|
89
|
+
|
90
|
+
routine.schedule Apibanca::Routine::ScheduleParams.new( unit: "minutes", interval: "60" )
|
91
|
+
# -> PATCH http://api-banca.herokuapp.com/api/2013-11-4/routines/23449/schedule [params]
|
92
|
+
# => (Rutina 23449) LectorDepósitos acumular:cartola tasks=3
|
93
|
+
```
|
94
|
+
|
95
|
+
### Descarga de depósitos
|
96
|
+
|
97
|
+
A medida que las rutinas de lectura de depósitos procesen la cartola y las transacciones, se puede invocar una función para descargar los depósitos leídos
|
98
|
+
|
99
|
+
```ruby
|
100
|
+
# arreglo con todos los depósitos
|
101
|
+
banco.load_deposits
|
102
|
+
# => [...]
|
103
|
+
|
104
|
+
banco.deposits.first
|
105
|
+
# => (Deposit 209070) 03/01/2014 / cheque / 79.695
|
106
|
+
```
|
107
|
+
|
108
|
+
### Otras funciones
|
109
|
+
|
110
|
+
#### Listado de bancos creados
|
111
|
+
|
112
|
+
Es posible cargar un arreglo con los bancos cargados en la cuenta
|
113
|
+
|
114
|
+
```ruby
|
115
|
+
banks = Apibanca::Bank.index(client)
|
116
|
+
# -> GET http://api-banca.herokuapp.com/api/2013-11-4/banks/
|
117
|
+
# => [(Banco 3304) BICE / <usuario> / <cuenta>, (Banco 3323) SCOTIA / <usuario> / <cuenta>]
|
118
|
+
banks.first.id
|
119
|
+
# => 3304
|
45
120
|
```
|
data/lib/apibanca/client/bank.rb
CHANGED
@@ -6,28 +6,23 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
6
6
|
def create client, bank_params
|
7
7
|
raise ArgumentError, "Los parámetros deben ser ApiBanca::Bank::BankCreationParams" unless bank_params.is_a? Apibanca::Bank::BankCreationParams
|
8
8
|
r = client.post url, { bank: bank_params.to_hash }
|
9
|
-
bank = Apibanca::Bank.new(r.body)
|
10
|
-
bank.
|
11
|
-
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
9
|
+
bank = Apibanca::Bank.new(client, r.body)
|
10
|
+
bank.load_routines! false
|
12
11
|
bank
|
13
12
|
end
|
14
13
|
|
15
14
|
def load client, id, recursive=true
|
16
15
|
r = client.get url("#{id}")
|
17
|
-
bank = Apibanca::Bank.new(r.body)
|
18
|
-
bank.
|
19
|
-
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
20
|
-
bank.routines.each { |r| r.refresh! } if recursive
|
16
|
+
bank = Apibanca::Bank.new(client, r.body)
|
17
|
+
bank.load_routines! recursive
|
21
18
|
bank
|
22
19
|
end
|
23
20
|
|
24
21
|
def index client, params=nil, recursive=false
|
25
22
|
r = client.get url, params
|
26
23
|
r.body.map do |raw|
|
27
|
-
bank = Apibanca::Bank.new(raw)
|
28
|
-
bank.
|
29
|
-
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
30
|
-
bank.routines.each { |r| r.refresh! } if recursive
|
24
|
+
bank = Apibanca::Bank.new(client, raw)
|
25
|
+
bank.load_routines! recursive
|
31
26
|
bank
|
32
27
|
end
|
33
28
|
end
|
@@ -35,10 +30,8 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
35
30
|
|
36
31
|
def refresh! recursive=true
|
37
32
|
r = obj_client.get url
|
38
|
-
old_routines = self.routines
|
39
33
|
self.merge! r.body
|
40
|
-
self.
|
41
|
-
self.routines.each { |r| r.refresh! } if recursive
|
34
|
+
self.load_routines! recursive
|
42
35
|
self
|
43
36
|
end
|
44
37
|
|
@@ -51,30 +44,38 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
51
44
|
raise ArgumentError, "Los parámetros deben ser ApiBanca::Bank::RoutineCreationParams" unless routine_params.is_a? Apibanca::Bank::RoutineCreationParams
|
52
45
|
r = obj_client.post url("add_routine"), { routine: routine_params.to_hash }
|
53
46
|
r.body.routines.each do |routine|
|
54
|
-
|
55
|
-
|
56
|
-
new_routine.obj_client = self.obj_client
|
47
|
+
next unless self.routines.any? { |r| r.id == routine.id }
|
48
|
+
new_routine = Apibanca::Routine.new(obj_client, self, routine)
|
57
49
|
new_routine.refresh!
|
58
50
|
self.routines << new_routine
|
59
51
|
end
|
52
|
+
routines.last
|
60
53
|
end
|
61
54
|
|
62
55
|
def delete
|
63
|
-
|
56
|
+
obj_client.delete url
|
64
57
|
true
|
65
58
|
end
|
66
59
|
|
67
60
|
def load_deposits params=nil
|
68
61
|
r = obj_client.get url("deposits"), params
|
69
|
-
self.deposits = r.body.map { |d| nd = Apibanca::Deposit.new(
|
62
|
+
self.deposits = r.body.map { |d| nd = Apibanca::Deposit.new(obj_client, self, d) }
|
63
|
+
end
|
64
|
+
|
65
|
+
def load_jobs params=nil
|
66
|
+
r = obj_client.get url, params
|
67
|
+
self.jobs = r.body.each do |raw|
|
68
|
+
Apibanca::Job.new(obj_client, raw)
|
69
|
+
end
|
70
70
|
end
|
71
71
|
|
72
72
|
def to_s
|
73
|
-
"Banco #{name} / #{user} / #{account}"
|
73
|
+
"(Banco #{id}) #{name} / #{user} / #{account}"
|
74
74
|
end
|
75
75
|
|
76
|
-
def
|
77
|
-
|
76
|
+
def load_routines! recursive=true
|
77
|
+
self.routines.map! { |r| Apibanca::Routine.new(self.obj_client, self, r) }
|
78
|
+
self.routines.each { |r| r.refresh! } if recursive
|
78
79
|
end
|
79
80
|
|
80
81
|
class BankCreationParams < Hashie::Dash
|
@@ -5,14 +5,15 @@ class Apibanca::Deposit < Apibanca::ProxyBase
|
|
5
5
|
end
|
6
6
|
|
7
7
|
def to_s
|
8
|
-
"#{self.raw_date} #{self.psd_type ? self.psd_type : self.raw_comment}
|
9
|
-
end
|
10
|
-
|
11
|
-
def inspect
|
12
|
-
to_s
|
8
|
+
"(Deposit #{id}) #{self.raw_date} / #{self.psd_type ? self.psd_type : self.raw_comment} / #{self.raw_amount}"
|
13
9
|
end
|
14
10
|
|
15
11
|
def history
|
16
12
|
@history ||= load_history
|
17
13
|
end
|
14
|
+
|
15
|
+
def initialize(client, bank, source_hash = nil, default = nil, &block)
|
16
|
+
super(client, source_hash, default, &block)
|
17
|
+
self.obj_bank = bank
|
18
|
+
end
|
18
19
|
end
|
@@ -28,6 +28,21 @@ class Apibanca::Routine < Apibanca::ProxyBase
|
|
28
28
|
self.tasks = r.body
|
29
29
|
end
|
30
30
|
|
31
|
+
def delete
|
32
|
+
obj_client.delete url
|
33
|
+
self.obj_bank.routines.select! { |r| r.id != self.id } if self.obj_bank.routines.any?
|
34
|
+
true
|
35
|
+
end
|
36
|
+
|
37
|
+
def to_s
|
38
|
+
"(Rutina #{id}) #{nombre} #{target ? "#{what_to_do}:#{target}" : ""} tasks=#{scheduled_tasks} #{!active ? "INACTIVE" : ""}"
|
39
|
+
end
|
40
|
+
|
41
|
+
def initialize(client, bank, source_hash = nil, default = nil, &block)
|
42
|
+
super(client, source_hash, default, &block)
|
43
|
+
self.obj_bank = bank
|
44
|
+
end
|
45
|
+
|
31
46
|
class ScheduleParams < Hashie::Dash
|
32
47
|
property :unit, required: true
|
33
48
|
property :interval, required: true
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: apibanca-client
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.3
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Marambio
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2014-01-
|
11
|
+
date: 2014-01-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -115,6 +115,7 @@ files:
|
|
115
115
|
- lib/apibanca/client/deposit.rb
|
116
116
|
- lib/apibanca/client/deposit_version.rb
|
117
117
|
- lib/apibanca/client/exceptions.rb
|
118
|
+
- lib/apibanca/client/job.rb
|
118
119
|
- lib/apibanca/client/proxy_base.rb
|
119
120
|
- lib/apibanca/client/routine.rb
|
120
121
|
- lib/apibanca/client/version.rb
|