santander_chile-api_client 1.0.0 → 1.1.0

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
  SHA256:
3
- metadata.gz: 771a6b84cdb5be50f473e910aea00e9afe3f458d91674aaa5f5487deae311f5b
4
- data.tar.gz: fcb01d7f84b575f907b7c429b936b827263a8d69e6739565254d20c3cbf5dd4e
3
+ metadata.gz: 5030c20dc94cc769d2e401983e8599e74aa3501af62764c6101d94d267083dc8
4
+ data.tar.gz: 6f2b26299c52a1790716c11cd67ebdb01f42a0a1dc378e8cf9ffce1098c4074a
5
5
  SHA512:
6
- metadata.gz: 2379249a58802e803829e4dd8c0f2cf9555ba4841dabc4f672ba6b9e2a7c2b3f331721e1cbcf9c24a38898ed7a8674e7ba454ffec30319ff8a9a573da346b896
7
- data.tar.gz: fa7105defabcb5c31451d640097419df0ac80f8e305d755686aa96d76ba1eb3d9a01e74c1a13a98581462c66ae92f1aca82a79882e7f1101c900594ef64377b3
6
+ metadata.gz: 392bd5e435c57f90e20ed75c0fc76471c409ac467b0096e960ea1ff14013a08603e6692c104b57ef5758fdc4bbad78b1f9fa41dacd7d5d41e349f889a23e3b6f
7
+ data.tar.gz: e159bd0bf5192384ba400181c71c44885e1fae5ba65c3bda1ff2b60acbf98b580d7fbca1436b16c57d61ccd889eab8357355cb3844445af9265d89b4ee22cabb
data/Gemfile.lock CHANGED
@@ -1,15 +1,19 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- santander_chile-api_client (1.0.0)
4
+ santander_chile-api_client (1.1.0)
5
+ erb (>= 2.2)
5
6
  faraday (~> 1.7)
6
7
  faraday_middleware (~> 1.1)
7
8
 
8
9
  GEM
9
10
  remote: https://rubygems.org/
10
11
  specs:
12
+ cgi (0.1.0)
11
13
  diff-lcs (1.4.4)
12
14
  dotenv (2.7.6)
15
+ erb (2.2.3)
16
+ cgi
13
17
  faraday (1.7.1)
14
18
  faraday-em_http (~> 1.0)
15
19
  faraday-em_synchrony (~> 1.0)
data/README.md CHANGED
@@ -64,10 +64,20 @@ movements.each { |x| x }
64
64
 
65
65
  ```
66
66
 
67
+ #### Contacts
68
+ ```rb
69
+ contacts = client.contacts
70
+ #=> SantanderChile::ApiClient::Collection
71
+
72
+ contacts.each { |x| x }
73
+ #=> <SantanderChile::ApiClient::Contact>
74
+ #=> <SantanderChile::ApiClient::Contact>
75
+ ```
67
76
 
68
77
  ### Todo
69
78
  - [x] ~~Products (accounts)~~
70
79
  - [x] ~~Movements~~
80
+ - [x] ~~Contacts~~
71
81
  - [ ] Balance
72
82
  - [ ] Transfers
73
83
  - [ ] Payments
@@ -89,4 +99,4 @@ The gem is available as open source under the terms of the [MIT License](https:/
89
99
 
90
100
  ## Code of Conduct
91
101
 
92
- Everyone interacting in the SantanderChile::ApiClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/[USERNAME]/santander_chile-api_client/blob/master/CODE_OF_CONDUCT.md).
102
+ Everyone interacting in the SantanderChile::ApiClient project's codebases, issue trackers, chat rooms and mailing lists is expected to follow the [code of conduct](https://github.com/jerrymendoza/santander_chile-api_client/blob/master/CODE_OF_CONDUCT.md).
@@ -4,11 +4,17 @@ module SantanderChile
4
4
  class Configuration
5
5
  ATTRIBUTES = %i[
6
6
  client_id
7
+ canal_id
8
+ canal_fisico
9
+ canal_logico
7
10
  faraday
8
11
  ].freeze
9
12
  attr_accessor(*ATTRIBUTES)
10
13
 
11
14
  def initialize
15
+ self.canal_id = "078"
16
+ self.canal_fisico = "78"
17
+ self.canal_logico = "74"
12
18
  self.faraday = ->(faraday) { }
13
19
  end
14
20
 
@@ -21,7 +21,7 @@ module SantanderChile
21
21
  Faraday.new(url: host) do |config|
22
22
  config.request :url_encoded if login
23
23
  config.request :oauth2, client.token.access_token, token_type: :bearer if client.token # TODO check token timeout
24
- config.request :json if !login
24
+ config.request :json
25
25
  config.response :raise_error
26
26
  config.response :json, content_type: "application/json"
27
27
  client.config.faraday.call(config)
@@ -0,0 +1,33 @@
1
+ module SantanderChile
2
+ module ApiClient
3
+ class Client
4
+ AUTH_BASE_URL = "https://apideveloper.santander.cl/sancl/privado/Cliente/v1/"
5
+ BASE_URL = "https://apiper.santander.cl/appper/facade/"
6
+
7
+ include Authentication
8
+ attr_accessor :config
9
+
10
+ def initialize
11
+ self.config = Configuration.new
12
+ yield(config) if block_given?
13
+ config.validate!
14
+ end
15
+
16
+ def connection(host: BASE_URL)
17
+ Connection.new(client: self, host: host)
18
+ end
19
+
20
+ def products
21
+ ProductsResource.new(self).list
22
+ end
23
+
24
+ def movements(account)
25
+ MovementsResource.new(self).list(account)
26
+ end
27
+
28
+ def contacts
29
+ PaymentsResource.new(self).contacts.data
30
+ end
31
+ end
32
+ end
33
+ end
@@ -8,10 +8,10 @@ module SantanderChile
8
8
  @data = data
9
9
  end
10
10
 
11
- def self.from_response(response, keys_to:, type:)
11
+ def self.from_response(response, dig_keys:, type:)
12
12
  body = response.body
13
13
  new(
14
- data: body.dig(*keys_to).map {
14
+ data: body.dig(*dig_keys).map {
15
15
  |attrs|
16
16
  type.new(attrs)
17
17
  },
@@ -0,0 +1,16 @@
1
+ module SantanderChile
2
+ module ApiClient
3
+ class Contact < Object
4
+ ATTRIBUTES = {
5
+ "rut" => "RUT-CLIENTE",
6
+ "name" => "NOMBRE-CLIENTE",
7
+ "account_number" => "NUMERO-CUENTA",
8
+ "account_bank" => "CODIGO-BANCO-CCA",
9
+ "account_type" => "TIPO_CUENTA",
10
+ "email" => "CORREO_ELECTRONICO",
11
+ }
12
+
13
+ attr_accessor(*ATTRIBUTES.keys.map { |x| x.to_sym })
14
+ end
15
+ end
16
+ end
@@ -1,31 +1,17 @@
1
1
  module SantanderChile
2
2
  module ApiClient
3
3
  class MovementsResource < Resource
4
- ## PATHS on santander_chile/api_client/endpoints.rb
5
- def movements_params(client, account)
6
- {
7
- "Cabecera" => {
8
- "HOST" => {
9
- "USUARIO-ALT" => "GHOBP",
10
- "TERMINAL-ALT" => "",
11
- "CANAL-ID" => "078",
12
- },
13
- "CanalFisico" => "78",
14
- "CanalLogico" => "74",
15
- "RutCliente" => client.username,
16
- "RutUsuario" => client.username,
17
- "IpCliente" => "",
18
- "InfoDispositivo" => "xx",
19
- },
20
- "Entrada" => {
21
- "NumeroCuenta" => account.account_number,
22
- },
23
- }
4
+ DIG_RESPONSE = ["DATA", "MovimientosDepositos"]
5
+
6
+ def list(account, **params)
7
+ response = post_request("Consultas/MvtosYDeposiDocCtas", body: body_builder(account))
8
+ Collection.from_response(response, dig_keys: DIG_RESPONSE, type: Movement)
24
9
  end
25
10
 
26
- def list(account, *params)
27
- response = post_request(MOVEMENTS[:PATH], body: movements_params(@client, account).to_json)
28
- Collection.from_response(response, keys_to: MOVEMENTS[:KEYS_TO], type: Movement)
11
+ private
12
+
13
+ def body_builder(account)
14
+ with_template "requests/MvtosYDeposiDocCtas", client: @client, account: account
29
15
  end
30
16
  end
31
17
  end
@@ -0,0 +1,18 @@
1
+ module SantanderChile
2
+ module ApiClient
3
+ class PaymentsResource < Resource
4
+ DIG_CONTACTS = ["DATA", "Mvld_SP_Consulta_Ult_Destinatarios_Response", "OUTPUT", "MATRICES", "MATRIZ-ULTIMOS-DESTINATARIOS", "e"]
5
+
6
+ def contacts
7
+ response = post_request("UltimosDestinatarios", body: body_builder_contacts)
8
+ Collection.from_response(response, dig_keys: DIG_CONTACTS, type: Contact)
9
+ end
10
+
11
+ private
12
+
13
+ def body_builder_contacts
14
+ with_template "requests/UltimosDestinatarios", client: @client
15
+ end
16
+ end
17
+ end
18
+ end
@@ -1,17 +1,17 @@
1
1
  module SantanderChile
2
2
  module ApiClient
3
3
  class ProductsResource < Resource
4
- ## PATHS on santander_chile/api_client/endpoints.rb
5
- def products_params(username)
6
- {
7
- "cabecera" => { "RutUsuario" => username },
8
- "INPUT" => { "NUMERODOCUMENTO" => username },
9
- }
10
- end
4
+ DIG_RESPONSE = ["DATA", "OUTPUT", "MATRICES", "MATRIZCAPTACIONES", "e1"]
11
5
 
12
6
  def list(**params)
13
- response = post_request(PRODUCTS[:PATH], body: products_params(@client.username).to_json)
14
- Collection.from_response(response, keys_to: PRODUCTS[:KEYS_TO], type: Account)
7
+ response = post_request("CruceProductoOnline", body: body_builder)
8
+ Collection.from_response(response, dig_keys: DIG_RESPONSE, type: Account)
9
+ end
10
+
11
+ private
12
+
13
+ def body_builder
14
+ with_template "requests/CruceProductoOnline", client: @client
15
15
  end
16
16
  end
17
17
  end
@@ -1,6 +1,7 @@
1
1
  module SantanderChile
2
2
  module ApiClient
3
3
  class Resource
4
+ include Template
4
5
  attr_reader :client
5
6
 
6
7
  def initialize(client)
@@ -9,7 +10,7 @@ module SantanderChile
9
10
 
10
11
  private
11
12
 
12
- def post_request(url, body: {}, headers: { "Content-Type" => "application/json" })
13
+ def post_request(url, body: {}, headers: {})
13
14
  handle_response client.connection.post(url, body: body, headers: headers)
14
15
  end
15
16
 
@@ -0,0 +1,18 @@
1
+ {
2
+ "cabecera": {
3
+ "HOST": {
4
+ "USUARIO-ALT": "GHOBP",
5
+ "TERMINAL-ALT": "",
6
+ "CANAL-ID": "<%= @client.config.canal_id %>"
7
+ },
8
+ "CanalFisico": "<%= @client.config.canal_fisico %>",
9
+ "CanalLogico": "<%= @client.config.canal_logico %>",
10
+ "RutCliente": "<%= @client.username %>",
11
+ "RutUsuario": "<%= @client.username %>",
12
+ "IpCliente": "",
13
+ "InfoDispositivo": "xx"
14
+ },
15
+ "INPUT": {
16
+ "NUMERODOCUMENTO": "<%= @client.username %>"
17
+ }
18
+ }
@@ -0,0 +1,18 @@
1
+ {
2
+ "Cabecera": {
3
+ "HOST": {
4
+ "USUARIO-ALT": "GHOBP",
5
+ "TERMINAL-ALT": "",
6
+ "CANAL-ID": "<%= @client.config.canal_id %>"
7
+ },
8
+ "CanalFisico": "<%= @client.config.canal_fisico %>",
9
+ "CanalLogico": "<%= @client.config.canal_logico %>",
10
+ "RutCliente": "<%= @client.username %>",
11
+ "RutUsuario": "<%= @client.username %>",
12
+ "IpCliente": "",
13
+ "InfoDispositivo": "xx"
14
+ },
15
+ "Entrada": {
16
+ "NumeroCuenta": "<%= @account.account_number %>"
17
+ }
18
+ }
@@ -0,0 +1,17 @@
1
+ {
2
+ "cabecera": {
3
+ "HOST": {
4
+ "USUARIO-ALT": "GHOBP",
5
+ "TERMINAL-ALT": "",
6
+ "CANAL-ID": "<%= @client.config.canal_id %>"
7
+ },
8
+ "CanalFisico": "<%= @client.config.canal_fisico %>",
9
+ "CanalLogico": "<%= @client.config.canal_logico %>",
10
+ "RutCliente": "<%= @client.username %>",
11
+ "RutUsuario": "<%= @client.username %>",
12
+ "InfoDispositivo": "xx"
13
+ },
14
+ "INPUT": {
15
+ "RUT-CLIENTE": "<%= @client.username %>"
16
+ }
17
+ }
@@ -0,0 +1,34 @@
1
+ module SantanderChile
2
+ module ApiClient
3
+ module Template
4
+ class ERBContext
5
+ def initialize(hash)
6
+ hash.each_pair do |key, value|
7
+ instance_variable_set("@" + key.to_s, value)
8
+ end
9
+ end
10
+
11
+ def get_binding
12
+ binding
13
+ end
14
+ end
15
+
16
+ path_templates = File.expand_path("./lib/santander_chile/api_client/templates")
17
+ TEMPLATES = {}
18
+
19
+ ["requests"].each do |category|
20
+ Dir.foreach(path_templates + "/#{category}/") do |filename|
21
+ next if !filename.include? "_template.json.erb"
22
+ filename.slice! "_template.json.erb"
23
+ TEMPLATES["#{category}/#{filename}"] = "#{path_templates}/#{category}/#{filename}_template.json.erb"
24
+ end
25
+ end
26
+
27
+ def with_template(path, **objs)
28
+ template_file = File.read(TEMPLATES[path])
29
+ context = ERBContext.new(objs)
30
+ ERB.new(template_file).result(context.get_binding)
31
+ end
32
+ end
33
+ end
34
+ end
@@ -1,5 +1,5 @@
1
1
  module SantanderChile
2
2
  module ApiClient
3
- VERSION = "1.0.0"
3
+ VERSION = "1.1.0"
4
4
  end
5
5
  end
@@ -1,47 +1,31 @@
1
1
  require "faraday"
2
2
  require "faraday_middleware"
3
+ require "erb"
3
4
  require "santander_chile/api_client/version"
4
- require "santander_chile/api_client/endpoints"
5
5
 
6
6
  module SantanderChile
7
7
  module ApiClient
8
8
  autoload :Error, "santander_chile/api_client/error"
9
9
  autoload :Token, "santander_chile/api_client/token"
10
10
 
11
+ #models
11
12
  autoload :Object, "santander_chile/api_client/models/object"
12
13
  autoload :Account, "santander_chile/api_client/models/account"
13
14
  autoload :Movement, "santander_chile/api_client/models/movement"
15
+ autoload :Contact, "santander_chile/api_client/models/contact"
14
16
  autoload :Collection, "santander_chile/api_client/collection"
17
+ autoload :Template, "santander_chile/api_client/templates/templates"
15
18
 
19
+ #resources
16
20
  autoload :Resource, "santander_chile/api_client/resources/resource"
17
21
  autoload :ProductsResource, "santander_chile/api_client/resources/products"
18
22
  autoload :MovementsResource, "santander_chile/api_client/resources/movements"
23
+ autoload :PaymentsResource, "santander_chile/api_client/resources/payments"
19
24
 
20
- class Client
21
- autoload :Configuration, "santander_chile/api_client/client/configuration"
22
- autoload :Connection, "santander_chile/api_client/client/connection"
23
- autoload :Authentication, "santander_chile/api_client/client/authentication"
24
-
25
- include Authentication
26
- attr_accessor :config
27
-
28
- def initialize
29
- self.config = Configuration.new
30
- yield(config) if block_given?
31
- config.validate!
32
- end
33
-
34
- def connection(host: BASE_URL)
35
- Connection.new(client: self, host: host)
36
- end
37
-
38
- def products
39
- ProductsResource.new(self).list
40
- end
41
-
42
- def movements(account)
43
- MovementsResource.new(self).list(account)
44
- end
45
- end
25
+ #client
26
+ autoload :Configuration, "santander_chile/api_client/client/configuration"
27
+ autoload :Connection, "santander_chile/api_client/client/connection"
28
+ autoload :Authentication, "santander_chile/api_client/client/authentication"
29
+ autoload :Client, "santander_chile/api_client/client"
46
30
  end
47
31
  end
@@ -26,6 +26,7 @@ Gem::Specification.new do |spec|
26
26
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
27
  spec.require_paths = ["lib"]
28
28
 
29
+ spec.add_dependency "erb", ">= 2.2"
29
30
  spec.add_dependency "faraday", "~> 1.7"
30
31
  spec.add_dependency "faraday_middleware", "~> 1.1"
31
32
  end
metadata CHANGED
@@ -1,15 +1,29 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: santander_chile-api_client
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jerry Mendoza
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2021-10-20 00:00:00.000000000 Z
11
+ date: 2021-11-05 00:00:00.000000000 Z
12
12
  dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: erb
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '2.2'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '2.2'
13
27
  - !ruby/object:Gem::Dependency
14
28
  name: faraday
15
29
  requirement: !ruby/object:Gem::Requirement
@@ -57,18 +71,24 @@ files:
57
71
  - bin/console
58
72
  - bin/setup
59
73
  - lib/santander_chile/api_client.rb
74
+ - lib/santander_chile/api_client/client.rb
60
75
  - lib/santander_chile/api_client/client/authentication.rb
61
76
  - lib/santander_chile/api_client/client/configuration.rb
62
77
  - lib/santander_chile/api_client/client/connection.rb
63
78
  - lib/santander_chile/api_client/collection.rb
64
- - lib/santander_chile/api_client/endpoints.rb
65
79
  - lib/santander_chile/api_client/error.rb
66
80
  - lib/santander_chile/api_client/models/account.rb
81
+ - lib/santander_chile/api_client/models/contact.rb
67
82
  - lib/santander_chile/api_client/models/movement.rb
68
83
  - lib/santander_chile/api_client/models/object.rb
69
84
  - lib/santander_chile/api_client/resources/movements.rb
85
+ - lib/santander_chile/api_client/resources/payments.rb
70
86
  - lib/santander_chile/api_client/resources/products.rb
71
87
  - lib/santander_chile/api_client/resources/resource.rb
88
+ - lib/santander_chile/api_client/templates/requests/CruceProductoOnline_template.json.erb
89
+ - lib/santander_chile/api_client/templates/requests/MvtosYDeposiDocCtas_template.json.erb
90
+ - lib/santander_chile/api_client/templates/requests/UltimosDestinatarios_template.json.erb
91
+ - lib/santander_chile/api_client/templates/templates.rb
72
92
  - lib/santander_chile/api_client/token.rb
73
93
  - lib/santander_chile/api_client/version.rb
74
94
  - santander_chile-api_client.gemspec
@@ -1,18 +0,0 @@
1
- module SantanderChile
2
- module ApiClient
3
- AUTH_BASE_URL = "https://apideveloper.santander.cl/sancl/privado/Cliente/v1/"
4
- BASE_URL = "https://apiper.santander.cl/appper/facade/"
5
- PRODUCTS = {
6
- "PATH": "CruceProductoOnline",
7
- "KEYS_TO": ["DATA", "OUTPUT", "MATRICES", "MATRIZCAPTACIONES", "e1"],
8
- }
9
- BALANCE = {
10
- "PATH": "ConsultaSaldo",
11
- "KEYS_TO": ["DATA", "AS_TIB_Consulta_Saldo_Response", "OUTPUT", "ESCALARES"],
12
- }
13
- MOVEMENTS = {
14
- "PATH": "Consultas/MvtosYDeposiDocCtas",
15
- "KEYS_TO": ["DATA", "MovimientosDepositos"],
16
- }
17
- end
18
- end