apibanca-client 0.0.1 → 0.0.2
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 +4 -4
- data/CHANGELOG.md +23 -0
- data/README.md +23 -0
- data/lib/apibanca/client.rb +18 -33
- data/lib/apibanca/client/bank.rb +24 -12
- data/lib/apibanca/client/deposit.rb +1 -1
- data/lib/apibanca/client/routine.rb +5 -5
- data/lib/apibanca/client/version.rb +1 -1
- metadata +2 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: a05aac810bc32fe182122fb2cd8ef1961d683928
|
4
|
+
data.tar.gz: f2775c0ade0e6ec278975bcd0cc5cab7cc05dcf4
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4235bcaabe647464ebfe812462eb381b3a0fefcc63426193a48609fb82b8d92520c466bdfa88f50e8ed18f7abfec1c5947a29ad9e6048ed9600bccd372880596
|
7
|
+
data.tar.gz: fc953a05aeae0d3f9cd95451bcce25f5d4e77909093375a26578e92b5c81b40a97c17e28d9b993b50b834672773a7efae438539f6f53c48565c602d0a5567681
|
data/CHANGELOG.md
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# Bitácora de cambios
|
2
|
+
|
3
|
+
## 0.0.2
|
4
|
+
|
5
|
+
### Configuración del cliente
|
6
|
+
El cliente ya no guarda el secreto y la URI de manera estática. En vez de eso, (a) dichos parámetros son argumentos del constructor, y (b) el cliente debe ser pasado como argumento en los métodos estáticos de `Apibanca::Bank`.
|
7
|
+
|
8
|
+
```ruby
|
9
|
+
# a)
|
10
|
+
# Antes: Apibanca::Client.configure { |c| c.secret = "API_KEY..."}
|
11
|
+
client = Apibanca::Client.new("API_KEY...")
|
12
|
+
|
13
|
+
# b)
|
14
|
+
# Antes: bank = Apibanca::Bank.create(params)
|
15
|
+
bank = Apibanca::Bank.create(client, params)
|
16
|
+
```
|
17
|
+
|
18
|
+
### Búsqueda de bancos
|
19
|
+
La función `Bank.index` ahora recibe un hash de parámetros opcionales. Ese hash soporta `name` y `user`.
|
20
|
+
|
21
|
+
```ruby
|
22
|
+
banks = Apibanca::Bank.index(client, name: "BICE") # retorna todos los bancos con name == BICE
|
23
|
+
```
|
data/README.md
CHANGED
@@ -20,3 +20,26 @@ O bien instálala tú mismo:
|
|
20
20
|
|
21
21
|
$ gem install apibanca-client
|
22
22
|
|
23
|
+
## Uso
|
24
|
+
|
25
|
+
### Instanciar el cliente
|
26
|
+
|
27
|
+
Para realizar cualquier operación desde la gema, hay que autentificarse con la API-Key obtenida en http://api-banca.herokuapp.com.
|
28
|
+
|
29
|
+
```ruby
|
30
|
+
# Obtenida desde http://api-banca.herokuapp.com
|
31
|
+
API_KEY = "b3e0f65c-dea6-4003-d9d0-9a8745d9988"
|
32
|
+
client = Apibanca::Client.new(API_KEY)
|
33
|
+
```
|
34
|
+
|
35
|
+
### Crear un banco
|
36
|
+
|
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
|
+
|
39
|
+
```ruby
|
40
|
+
params = Apibanca::Bank::BankCreationParams.new(name: "BICE", user: "<rut del usuario>", pass: "<password para la web del banco>", account: "<número de cuenta>"
|
41
|
+
# => #<Apibanca::Bank::BankCreationParams account="..." name="BICE" pass="..." user="...">
|
42
|
+
banco = Apibanca::Bank.create(client, params)
|
43
|
+
# -> POST http://api-banca.herokuapp.com/api/2013-11-4/banks/ [{:bank=>{"name"=>"BICE", "user"=>"...", "pass"=>"...", "account"=>"..."}} params]
|
44
|
+
# Banco BICE / 157768441 / unica
|
45
|
+
```
|
data/lib/apibanca/client.rb
CHANGED
@@ -8,17 +8,16 @@ require "faraday/response/apibanca_errors"
|
|
8
8
|
|
9
9
|
module Apibanca
|
10
10
|
class Client
|
11
|
-
|
12
|
-
class << self
|
11
|
+
module Http
|
13
12
|
def get uri, params=nil
|
14
|
-
|
13
|
+
conn_url.get do |req|
|
15
14
|
req.url uri, params
|
16
15
|
req.headers['bc-auth-token'] = @secret
|
17
16
|
end
|
18
17
|
end
|
19
18
|
|
20
19
|
def post uri, body=nil
|
21
|
-
|
20
|
+
conn_form.post do |req|
|
22
21
|
req.url uri
|
23
22
|
req.headers['bc-auth-token'] = @secret
|
24
23
|
req.body = body if body
|
@@ -26,7 +25,7 @@ module Apibanca
|
|
26
25
|
end
|
27
26
|
|
28
27
|
def patch uri, body=nil
|
29
|
-
|
28
|
+
conn_form.patch do |req|
|
30
29
|
req.url uri
|
31
30
|
req.headers['bc-auth-token'] = @secret
|
32
31
|
req.body = body if body
|
@@ -34,7 +33,7 @@ module Apibanca
|
|
34
33
|
end
|
35
34
|
|
36
35
|
def delete uri
|
37
|
-
|
36
|
+
conn_form.delete do |req|
|
38
37
|
req.url uri
|
39
38
|
req.headers['bc-auth-token'] = @secret
|
40
39
|
end
|
@@ -42,7 +41,7 @@ module Apibanca
|
|
42
41
|
|
43
42
|
def conn_form
|
44
43
|
check_requirements!
|
45
|
-
@
|
44
|
+
@conn_form ||= Faraday.new(:url => @base_uri) do |f|
|
46
45
|
f.request :apibanca_request_logger
|
47
46
|
f.request :json
|
48
47
|
f.response :apibanca_errors
|
@@ -54,7 +53,7 @@ module Apibanca
|
|
54
53
|
|
55
54
|
def conn_url
|
56
55
|
check_requirements!
|
57
|
-
@
|
56
|
+
@conn_url ||= Faraday.new(:url => @base_uri) do |f|
|
58
57
|
f.request :apibanca_request_logger
|
59
58
|
f.request :url_encoded
|
60
59
|
f.response :apibanca_errors
|
@@ -63,33 +62,19 @@ module Apibanca
|
|
63
62
|
f.adapter Faraday.default_adapter
|
64
63
|
end
|
65
64
|
end
|
65
|
+
end
|
66
|
+
include Http
|
66
67
|
|
67
|
-
|
68
|
-
|
69
|
-
|
70
|
-
|
71
|
-
|
72
|
-
def secret= value
|
73
|
-
@secret = value
|
74
|
-
end
|
75
|
-
|
76
|
-
def secret
|
77
|
-
@secret
|
78
|
-
end
|
79
|
-
|
80
|
-
def base_uri= value
|
81
|
-
@base_uri = value
|
82
|
-
end
|
83
|
-
|
84
|
-
def base_uri
|
85
|
-
@base_uri ||= "http://localhost:3000/api/2013-11-4"
|
86
|
-
end
|
68
|
+
def initialize secret, api_uri = "http://api-banca.herokuapp.com/api/2013-11-4"
|
69
|
+
raise ArgumentError, "Debe indicar el secreto para acceder a la API" unless secret
|
70
|
+
@secret = secret
|
71
|
+
@base_uri = api_uri
|
72
|
+
end
|
87
73
|
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
end
|
74
|
+
private
|
75
|
+
def check_requirements!
|
76
|
+
raise ArgumentError, "Debe indicar el secreto" unless @secret
|
77
|
+
raise ArgumentError, "Debe indicar la URI" unless @base_uri
|
93
78
|
end
|
94
79
|
end
|
95
80
|
end
|
data/lib/apibanca/client/bank.rb
CHANGED
@@ -3,26 +3,29 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
3
3
|
set_relative_url "banks"
|
4
4
|
|
5
5
|
class << self
|
6
|
-
def create bank_params
|
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
|
-
r =
|
8
|
+
r = client.post url, { bank: bank_params.to_hash }
|
9
9
|
bank = Apibanca::Bank.new(r.body)
|
10
|
+
bank.obj_client = client
|
10
11
|
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
11
12
|
bank
|
12
13
|
end
|
13
14
|
|
14
|
-
def load id, recursive=true
|
15
|
-
r =
|
15
|
+
def load client, id, recursive=true
|
16
|
+
r = client.get url("#{id}")
|
16
17
|
bank = Apibanca::Bank.new(r.body)
|
18
|
+
bank.obj_client = client
|
17
19
|
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
18
20
|
bank.routines.each { |r| r.refresh! } if recursive
|
19
21
|
bank
|
20
22
|
end
|
21
23
|
|
22
|
-
def index recursive=false
|
23
|
-
r =
|
24
|
+
def index client, params=nil, recursive=false
|
25
|
+
r = client.get url, params
|
24
26
|
r.body.map do |raw|
|
25
27
|
bank = Apibanca::Bank.new(raw)
|
28
|
+
bank.obj_client = client
|
26
29
|
bank.routines.map! { |r| Apibanca::Routine.new(r) }
|
27
30
|
bank.routines.each { |r| r.refresh! } if recursive
|
28
31
|
bank
|
@@ -31,7 +34,7 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
31
34
|
end
|
32
35
|
|
33
36
|
def refresh! recursive=true
|
34
|
-
r =
|
37
|
+
r = obj_client.get url
|
35
38
|
old_routines = self.routines
|
36
39
|
self.merge! r.body
|
37
40
|
self.routines = old_routines
|
@@ -40,29 +43,38 @@ class Apibanca::Bank < Apibanca::ProxyBase
|
|
40
43
|
end
|
41
44
|
|
42
45
|
def change_password new_pass
|
43
|
-
r =
|
46
|
+
r = obj_client.patch url("change_password"), pass: new_pass
|
44
47
|
true
|
45
48
|
end
|
46
49
|
|
47
50
|
def add_routine routine_params
|
48
51
|
raise ArgumentError, "Los parámetros deben ser ApiBanca::Bank::RoutineCreationParams" unless routine_params.is_a? Apibanca::Bank::RoutineCreationParams
|
49
|
-
r =
|
52
|
+
r = obj_client.post url("add_routine"), { routine: routine_params.to_hash }
|
50
53
|
r.body.routines.each do |routine|
|
51
54
|
new_routine = Apibanca::Routine.new(routine) unless self.routines.map { |i| i.id }.include?(routine.id)
|
52
55
|
next unless new_routine
|
56
|
+
new_routine.obj_client = self.obj_client
|
53
57
|
new_routine.refresh!
|
54
58
|
self.routines << new_routine
|
55
59
|
end
|
56
60
|
end
|
57
61
|
|
58
62
|
def delete
|
59
|
-
r =
|
63
|
+
r = obj_client.delete url
|
60
64
|
true
|
61
65
|
end
|
62
66
|
|
63
67
|
def load_deposits params=nil
|
64
|
-
r =
|
65
|
-
self.deposits = r.body.map { |d| nd = Apibanca::Deposit.new(d); nd.obj_bank = self; nd }
|
68
|
+
r = obj_client.get url("deposits"), params
|
69
|
+
self.deposits = r.body.map { |d| nd = Apibanca::Deposit.new(d); nd.obj_bank = self; nd.obj_client = obj_client; nd }
|
70
|
+
end
|
71
|
+
|
72
|
+
def to_s
|
73
|
+
"Banco #{name} / #{user} / #{account}"
|
74
|
+
end
|
75
|
+
|
76
|
+
def inspect
|
77
|
+
to_s
|
66
78
|
end
|
67
79
|
|
68
80
|
class BankCreationParams < Hashie::Dash
|
@@ -1,6 +1,6 @@
|
|
1
1
|
class Apibanca::Deposit < Apibanca::ProxyBase
|
2
2
|
def load_history
|
3
|
-
h =
|
3
|
+
h = obj_client.get obj_bank.url("deposits/#{self.id}/history")
|
4
4
|
@history = h.body.map { |d| dv = Apibanca::DepositVersion.new(d); dv.obj_deposit = self; dv }
|
5
5
|
end
|
6
6
|
|
@@ -3,28 +3,28 @@ class Apibanca::Routine < Apibanca::ProxyBase
|
|
3
3
|
set_relative_url "routines"
|
4
4
|
|
5
5
|
def refresh!
|
6
|
-
r =
|
6
|
+
r = obj_client.get url
|
7
7
|
self.merge! r.body
|
8
8
|
end
|
9
9
|
|
10
10
|
def turn_on
|
11
|
-
r =
|
11
|
+
r = obj_client.patch url("turn_on")
|
12
12
|
self.merge! r.body
|
13
13
|
end
|
14
14
|
|
15
15
|
def turn_off
|
16
|
-
r =
|
16
|
+
r = obj_client.patch url("turn_off")
|
17
17
|
self.merge! r.body
|
18
18
|
end
|
19
19
|
|
20
20
|
def schedule params
|
21
21
|
raise ArgumentError, "Los parámetros deben ser ApiBanca::Routine::ScheduleParams" unless params.is_a? Apibanca::Routine::ScheduleParams
|
22
|
-
r =
|
22
|
+
r = obj_client.patch url("schedule"), params.to_hash
|
23
23
|
self.merge! r.body
|
24
24
|
end
|
25
25
|
|
26
26
|
def load_tasks
|
27
|
-
r =
|
27
|
+
r = obj_client.get url("tasks")
|
28
28
|
self.tasks = r.body
|
29
29
|
end
|
30
30
|
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
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.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Pablo Marambio
|
@@ -104,6 +104,7 @@ files:
|
|
104
104
|
- .gitignore
|
105
105
|
- .rvmrc
|
106
106
|
- .travis.yml
|
107
|
+
- CHANGELOG.md
|
107
108
|
- Gemfile
|
108
109
|
- LICENSE.txt
|
109
110
|
- README.md
|