apigratis-sdk-ruby 0.0.1
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 +7 -0
- data/CHANGELOG.md +27 -0
- data/LICENSE +21 -0
- data/README.md +330 -0
- data/SECURITY.md +32 -0
- data/lib/api_brasil/client.rb +252 -0
- data/lib/api_brasil/core/env.rb +34 -0
- data/lib/api_brasil/core/errors.rb +167 -0
- data/lib/api_brasil/core/http_client.rb +342 -0
- data/lib/api_brasil/core/retry.rb +69 -0
- data/lib/api_brasil/core/transport/faraday_transport.rb +76 -0
- data/lib/api_brasil/core/transport/net_http_transport.rb +126 -0
- data/lib/api_brasil/core/transport.rb +114 -0
- data/lib/api_brasil/generated/catalog.rb +526 -0
- data/lib/api_brasil/legacy/service.rb +155 -0
- data/lib/api_brasil/services/base_service.rb +49 -0
- data/lib/api_brasil/services/data/bulk_service.rb +26 -0
- data/lib/api_brasil/services/data/cep_service.rb +58 -0
- data/lib/api_brasil/services/data/chip_virtual_service.rb +40 -0
- data/lib/api_brasil/services/data/consulta_service.rb +97 -0
- data/lib/api_brasil/services/data/correios_service.rb +23 -0
- data/lib/api_brasil/services/data/dados_service.rb +30 -0
- data/lib/api_brasil/services/data/database_ip_service.rb +19 -0
- data/lib/api_brasil/services/data/fipe_service.rb +61 -0
- data/lib/api_brasil/services/data/proxies.rb +146 -0
- data/lib/api_brasil/services/data/ura_service.rb +26 -0
- data/lib/api_brasil/services/data/vehicles_service.rb +46 -0
- data/lib/api_brasil/services/device_proxy_service.rb +46 -0
- data/lib/api_brasil/services/messaging/evolution_service.rb +38 -0
- data/lib/api_brasil/services/messaging/sms_service.rb +40 -0
- data/lib/api_brasil/services/messaging/whats_meow_service.rb +30 -0
- data/lib/api_brasil/services/messaging/whatsapp_service.rb +120 -0
- data/lib/api_brasil/services/platform/account_service.rb +138 -0
- data/lib/api_brasil/services/platform/auth_service.rb +204 -0
- data/lib/api_brasil/services/platform/bearer_rate_limit_service.rb +29 -0
- data/lib/api_brasil/services/platform/catalog_service.rb +111 -0
- data/lib/api_brasil/services/platform/devices_service.rb +73 -0
- data/lib/api_brasil/services/platform/ip_whitelist_service.rb +73 -0
- data/lib/api_brasil/services/platform/payments_service.rb +124 -0
- data/lib/api_brasil/services/platform/reports_service.rb +96 -0
- data/lib/api_brasil/version.rb +6 -0
- data/lib/api_brasil.rb +72 -0
- data/lib/apigratis-sdk-ruby.rb +5 -0
- data/lib/apigratis.rb +11 -0
- metadata +149 -0
|
@@ -0,0 +1,204 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_service"
|
|
4
|
+
|
|
5
|
+
module ApiBrasil
|
|
6
|
+
module Services
|
|
7
|
+
module Platform
|
|
8
|
+
# Autenticacao e conta (`/auth/*`, `/profile*`, `/password/*`).
|
|
9
|
+
#
|
|
10
|
+
# `login` e `verify_2fa` guardam automaticamente o Bearer Token
|
|
11
|
+
# retornado no cliente, deixando as proximas chamadas autenticadas.
|
|
12
|
+
class AuthService < BaseService
|
|
13
|
+
# Autentica com email/senha: `POST /auth/login`.
|
|
14
|
+
# Se a conta tiver 2FA, retorna `{"requires_2fa" => true, "challenge" => ...}` -
|
|
15
|
+
# use `send_2fa` + `verify_2fa` para concluir.
|
|
16
|
+
#
|
|
17
|
+
# @param body [Hash] `email`, `password`, `turnstile_token`
|
|
18
|
+
# @return [Object]
|
|
19
|
+
def login(body, options = {})
|
|
20
|
+
response = post("/auth/login", body, options)
|
|
21
|
+
store_token(response)
|
|
22
|
+
response
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Envia o codigo 2FA pelo metodo escolhido: `POST /auth/2fa/send`.
|
|
26
|
+
#
|
|
27
|
+
# @param body [Hash] `challenge`, `method` (email|sms|whatsapp|call)
|
|
28
|
+
# @return [Object]
|
|
29
|
+
def send_2fa(body, options = {})
|
|
30
|
+
post("/auth/2fa/send", body, options)
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
# Conclui o login com o codigo 2FA: `POST /auth/login/verify-2fa`.
|
|
34
|
+
#
|
|
35
|
+
# @param body [Hash] `challenge`, `code`
|
|
36
|
+
# @return [Object]
|
|
37
|
+
def verify_2fa(body, options = {})
|
|
38
|
+
response = post("/auth/login/verify-2fa", body, options)
|
|
39
|
+
store_token(response)
|
|
40
|
+
response
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Lista os metodos 2FA ativos da conta: `GET /auth/2fa/methods`.
|
|
44
|
+
#
|
|
45
|
+
# @return [Object]
|
|
46
|
+
def two_factor_methods(options = {})
|
|
47
|
+
get("/auth/2fa/methods", options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Cria uma conta: `POST /auth/register`.
|
|
51
|
+
#
|
|
52
|
+
# @param body [Hash] `first_name`, `email`, `cellphone`, `password`, `terms_accepted`
|
|
53
|
+
# @return [Object]
|
|
54
|
+
def register(body, options = {})
|
|
55
|
+
post("/auth/register", body, options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Cadastro simplificado: `POST /auth/register/simple`.
|
|
59
|
+
#
|
|
60
|
+
# @return [Object]
|
|
61
|
+
def register_simple(body, options = {})
|
|
62
|
+
post("/auth/register/simple", body, options)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Dispara verificacao de email/celular: `POST /auth/verification/send`.
|
|
66
|
+
#
|
|
67
|
+
# @param body [Hash] `type` (email|cellphone)
|
|
68
|
+
# @return [Object]
|
|
69
|
+
def verification_send(body, options = {})
|
|
70
|
+
post("/auth/verification/send", body, options)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Confirma o codigo de verificacao: `POST /auth/verification/verify`.
|
|
74
|
+
#
|
|
75
|
+
# @param body [Hash] `code`, `type`
|
|
76
|
+
# @return [Object]
|
|
77
|
+
def verification_verify(body, options = {})
|
|
78
|
+
post("/auth/verification/verify", body, options)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
# Esqueci a senha: `POST /auth/password/forgot`.
|
|
82
|
+
#
|
|
83
|
+
# @param body [Hash] `identifier`, `method` (email|sms|whatsapp)
|
|
84
|
+
# @return [Object]
|
|
85
|
+
def password_forgot(body, options = {})
|
|
86
|
+
post("/auth/password/forgot", body, options)
|
|
87
|
+
end
|
|
88
|
+
|
|
89
|
+
# Valida o codigo de recuperacao: `POST /auth/password/verify-code`.
|
|
90
|
+
#
|
|
91
|
+
# @param body [Hash] `identifier`, `code`
|
|
92
|
+
# @return [Object]
|
|
93
|
+
def password_verify_code(body, options = {})
|
|
94
|
+
post("/auth/password/verify-code", body, options)
|
|
95
|
+
end
|
|
96
|
+
|
|
97
|
+
# Redefine a senha: `POST /auth/password/reset`.
|
|
98
|
+
#
|
|
99
|
+
# @param body [Hash] `reset_token`, `password`, `password_confirmation`
|
|
100
|
+
# @return [Object]
|
|
101
|
+
def password_reset(body, options = {})
|
|
102
|
+
post("/auth/password/reset", body, options)
|
|
103
|
+
end
|
|
104
|
+
|
|
105
|
+
# Reenvia o codigo de recuperacao: `POST /auth/password/resend`.
|
|
106
|
+
#
|
|
107
|
+
# @return [Object]
|
|
108
|
+
def password_resend(body, options = {})
|
|
109
|
+
post("/auth/password/resend", body, options)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Troca a senha logado: `POST /password/change`.
|
|
113
|
+
#
|
|
114
|
+
# @param body [Hash] `current_password`, `password`, `password_confirmation`
|
|
115
|
+
# @return [Object]
|
|
116
|
+
def change_password(body, options = {})
|
|
117
|
+
post("/password/change", body, options)
|
|
118
|
+
end
|
|
119
|
+
|
|
120
|
+
# Perfil completo (com estatisticas): `POST /profile`.
|
|
121
|
+
#
|
|
122
|
+
# @return [Object]
|
|
123
|
+
def profile(options = {})
|
|
124
|
+
post("/profile", nil, options)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Perfil atual: `GET /profile/me`.
|
|
128
|
+
#
|
|
129
|
+
# @return [Object]
|
|
130
|
+
def me(options = {})
|
|
131
|
+
get("/profile/me", options)
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
# Atualiza o perfil: `PUT /profile/me`.
|
|
135
|
+
#
|
|
136
|
+
# @return [Object]
|
|
137
|
+
def update_me(body, options = {})
|
|
138
|
+
put("/profile/me", body, options)
|
|
139
|
+
end
|
|
140
|
+
|
|
141
|
+
# Valida o token atual: `GET /auth/verify`.
|
|
142
|
+
#
|
|
143
|
+
# @return [Object]
|
|
144
|
+
def verify(options = {})
|
|
145
|
+
get("/auth/verify", options)
|
|
146
|
+
end
|
|
147
|
+
|
|
148
|
+
# Renova o JWT: `POST /refresh`.
|
|
149
|
+
#
|
|
150
|
+
# @return [Object]
|
|
151
|
+
def refresh(options = {})
|
|
152
|
+
response = post("/refresh", nil, options)
|
|
153
|
+
|
|
154
|
+
token = nil
|
|
155
|
+
if response.is_a?(Hash)
|
|
156
|
+
authorization = response["authorization"]
|
|
157
|
+
token = authorization["token"] if authorization.is_a?(Hash)
|
|
158
|
+
token ||= response["token"]
|
|
159
|
+
end
|
|
160
|
+
|
|
161
|
+
http.bearer_token = token if token.is_a?(String) && !token.empty?
|
|
162
|
+
|
|
163
|
+
response
|
|
164
|
+
end
|
|
165
|
+
|
|
166
|
+
# Rotaciona o token: `POST /auth/token/rotate`.
|
|
167
|
+
#
|
|
168
|
+
# @return [Object]
|
|
169
|
+
def token_rotate(options = {})
|
|
170
|
+
post("/auth/token/rotate", nil, options)
|
|
171
|
+
end
|
|
172
|
+
|
|
173
|
+
# Revoga o token atual: `POST /auth/token/revoke`.
|
|
174
|
+
#
|
|
175
|
+
# @return [Object]
|
|
176
|
+
def token_revoke(options = {})
|
|
177
|
+
post("/auth/token/revoke", nil, options)
|
|
178
|
+
end
|
|
179
|
+
|
|
180
|
+
# Encerra a sessao: `POST /auth/logout`.
|
|
181
|
+
#
|
|
182
|
+
# @return [Object]
|
|
183
|
+
def logout(options = {})
|
|
184
|
+
response = post("/auth/logout", nil, options)
|
|
185
|
+
http.bearer_token = nil
|
|
186
|
+
response
|
|
187
|
+
end
|
|
188
|
+
|
|
189
|
+
private
|
|
190
|
+
|
|
191
|
+
# Guarda o Bearer Token quando a resposta trouxer `authorization.token`.
|
|
192
|
+
def store_token(response)
|
|
193
|
+
return unless response.is_a?(Hash)
|
|
194
|
+
|
|
195
|
+
authorization = response["authorization"]
|
|
196
|
+
return unless authorization.is_a?(Hash)
|
|
197
|
+
|
|
198
|
+
token = authorization["token"]
|
|
199
|
+
http.bearer_token = token if token.is_a?(String) && !token.empty?
|
|
200
|
+
end
|
|
201
|
+
end
|
|
202
|
+
end
|
|
203
|
+
end
|
|
204
|
+
end
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_service"
|
|
4
|
+
|
|
5
|
+
module ApiBrasil
|
|
6
|
+
module Services
|
|
7
|
+
module Platform
|
|
8
|
+
# Rate limit por Bearer Token (`/bearer-rate-limit`).
|
|
9
|
+
#
|
|
10
|
+
# `get`/`set` seguem os nomes usados nas demais SDKs; por isso as
|
|
11
|
+
# chamadas internas usam `http.*` diretamente.
|
|
12
|
+
class BearerRateLimitService < BaseService
|
|
13
|
+
# Limite atual: `GET /bearer-rate-limit`.
|
|
14
|
+
#
|
|
15
|
+
# @return [Object]
|
|
16
|
+
def get(options = {})
|
|
17
|
+
http.get("/bearer-rate-limit", options)
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
# Define o limite por minuto: `PUT /bearer-rate-limit`.
|
|
21
|
+
#
|
|
22
|
+
# @return [Object]
|
|
23
|
+
def set(body, options = {})
|
|
24
|
+
http.put("/bearer-rate-limit", body, options)
|
|
25
|
+
end
|
|
26
|
+
end
|
|
27
|
+
end
|
|
28
|
+
end
|
|
29
|
+
end
|
|
@@ -0,0 +1,111 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require "uri"
|
|
4
|
+
|
|
5
|
+
require_relative "../base_service"
|
|
6
|
+
|
|
7
|
+
module ApiBrasil
|
|
8
|
+
module Services
|
|
9
|
+
module Platform
|
|
10
|
+
# Catalogo publico da plataforma: APIs, planos, documentacoes e servidores.
|
|
11
|
+
# A maioria das rotas e publica (nao exige Bearer Token).
|
|
12
|
+
class CatalogService < BaseService
|
|
13
|
+
# Lista/busca APIs disponiveis: `GET /apis?search=`.
|
|
14
|
+
#
|
|
15
|
+
# @return [Object]
|
|
16
|
+
def apis(search = nil, options = {})
|
|
17
|
+
options = Core::HttpClient.normalize_keys(options)
|
|
18
|
+
query = search.nil? || search.to_s.empty? ? {} : { "search" => search }
|
|
19
|
+
options[:query] = query.merge(options[:query] || {})
|
|
20
|
+
|
|
21
|
+
get("/apis", options)
|
|
22
|
+
end
|
|
23
|
+
|
|
24
|
+
# Detalha uma API por identificador: `GET /apis/{identifier}`.
|
|
25
|
+
#
|
|
26
|
+
# @return [Object]
|
|
27
|
+
def api(identifier, options = {})
|
|
28
|
+
get("/apis/#{identifier}", options)
|
|
29
|
+
end
|
|
30
|
+
|
|
31
|
+
# Detalha uma API pelo nome: `GET /apis/name/{name}`.
|
|
32
|
+
#
|
|
33
|
+
# @return [Object]
|
|
34
|
+
def api_by_name(name, options = {})
|
|
35
|
+
get("/apis/name/#{Core::HttpClient.escape_path_segment(name)}", options)
|
|
36
|
+
end
|
|
37
|
+
|
|
38
|
+
# Categorias de APIs: `GET /apis/categories`.
|
|
39
|
+
#
|
|
40
|
+
# @return [Object]
|
|
41
|
+
def api_categories(options = {})
|
|
42
|
+
get("/apis/categories", options)
|
|
43
|
+
end
|
|
44
|
+
|
|
45
|
+
# APIs contratadas pelo usuario (autenticado): `GET /apis/list`.
|
|
46
|
+
#
|
|
47
|
+
# @return [Object]
|
|
48
|
+
def my_apis(options = {})
|
|
49
|
+
get("/apis/list", options)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# APIs vinculadas a um device: `GET /apis/device/{device_token}`.
|
|
53
|
+
#
|
|
54
|
+
# @return [Object]
|
|
55
|
+
def apis_by_device(device_token, options = {})
|
|
56
|
+
get("/apis/device/#{device_token}", options)
|
|
57
|
+
end
|
|
58
|
+
|
|
59
|
+
# Planos disponiveis: `GET /plans`.
|
|
60
|
+
#
|
|
61
|
+
# @return [Object]
|
|
62
|
+
def plans(options = {})
|
|
63
|
+
get("/plans", options)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
# Documentacoes: `GET /documentations`.
|
|
67
|
+
#
|
|
68
|
+
# @return [Object]
|
|
69
|
+
def documentations(options = {})
|
|
70
|
+
get("/documentations", options)
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Documentacao por servidor: `GET /documentations/server/{server_search}`.
|
|
74
|
+
#
|
|
75
|
+
# @return [Object]
|
|
76
|
+
def documentations_by_server(server_search, options = {})
|
|
77
|
+
get("/documentations/server/#{server_search}", options)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Servidores disponiveis: `GET /servers`.
|
|
81
|
+
#
|
|
82
|
+
# @return [Object]
|
|
83
|
+
def servers(options = {})
|
|
84
|
+
get("/servers", options)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Resolve a URL de uma action (descoberta dinamica de endpoints):
|
|
88
|
+
# `POST /endpoint/url`.
|
|
89
|
+
#
|
|
90
|
+
# @return [Object]
|
|
91
|
+
def endpoint_url(body, options = {})
|
|
92
|
+
post("/endpoint/url", body, options)
|
|
93
|
+
end
|
|
94
|
+
|
|
95
|
+
# Body esperado por uma action: `POST /endpoint/body`.
|
|
96
|
+
#
|
|
97
|
+
# @return [Object]
|
|
98
|
+
def endpoint_body(body, options = {})
|
|
99
|
+
post("/endpoint/body", body, options)
|
|
100
|
+
end
|
|
101
|
+
|
|
102
|
+
# Status do gateway: `GET /status`.
|
|
103
|
+
#
|
|
104
|
+
# @return [Object]
|
|
105
|
+
def status(options = {})
|
|
106
|
+
get("/status", options)
|
|
107
|
+
end
|
|
108
|
+
end
|
|
109
|
+
end
|
|
110
|
+
end
|
|
111
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_service"
|
|
4
|
+
|
|
5
|
+
module ApiBrasil
|
|
6
|
+
module Services
|
|
7
|
+
module Platform
|
|
8
|
+
# Gestao de devices (`/devices/*`).
|
|
9
|
+
#
|
|
10
|
+
# Devices sao a credencial de consumo dos servicos device-based:
|
|
11
|
+
# crie um device com a `SecretKey` da API desejada e use o
|
|
12
|
+
# `device_token` retornado como header `DeviceToken`.
|
|
13
|
+
class DevicesService < BaseService
|
|
14
|
+
# Lista os devices do usuario: `GET /devices`.
|
|
15
|
+
#
|
|
16
|
+
# @param query [Hash] ex: `{ paginate: true }`
|
|
17
|
+
# @return [Object]
|
|
18
|
+
def list(query = {}, options = {})
|
|
19
|
+
options = Core::HttpClient.normalize_keys(options)
|
|
20
|
+
options[:query] = query.merge(options[:query] || {})
|
|
21
|
+
|
|
22
|
+
get("/devices", options)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
# Cria um device: `POST /devices/store`.
|
|
26
|
+
#
|
|
27
|
+
# A `SecretKey` da API (painel APIBrasil) vai no header - passe em
|
|
28
|
+
# `options[:secret_key]` ou configure `secret_key` no cliente.
|
|
29
|
+
#
|
|
30
|
+
# @param body [Hash] `device_name`, `type`, `device_key`, webhooks...
|
|
31
|
+
# @return [Object]
|
|
32
|
+
def store(body, options = {})
|
|
33
|
+
options = Core::HttpClient.normalize_keys(options)
|
|
34
|
+
secret = options[:secret_key] || http.secret_key
|
|
35
|
+
options[:secret_key] = secret unless secret.nil?
|
|
36
|
+
|
|
37
|
+
post("/devices/store", body, options)
|
|
38
|
+
end
|
|
39
|
+
|
|
40
|
+
# Detalha um device: `GET /devices/show?search={device_token}`.
|
|
41
|
+
#
|
|
42
|
+
# @return [Object]
|
|
43
|
+
def show(device_token = nil, options = {})
|
|
44
|
+
options = Core::HttpClient.normalize_keys(options)
|
|
45
|
+
options[:query] = { "search" => device_token || http.device_token }.merge(options[:query] || {})
|
|
46
|
+
|
|
47
|
+
get("/devices/show", options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Atualiza um device: `POST /devices/update` (body com `device_token` + campos).
|
|
51
|
+
#
|
|
52
|
+
# @return [Object]
|
|
53
|
+
def update(body, options = {})
|
|
54
|
+
post("/devices/update", body, options)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Remove um device: `DELETE /devices/destroy`.
|
|
58
|
+
#
|
|
59
|
+
# @return [Object]
|
|
60
|
+
def destroy(device_token = nil, options = {})
|
|
61
|
+
delete("/devices/destroy", { "search" => device_token || http.device_token }, options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# Historico de requisicoes do device: `POST /devices/requests`.
|
|
65
|
+
#
|
|
66
|
+
# @return [Object]
|
|
67
|
+
def requests(body = nil, options = {})
|
|
68
|
+
post("/devices/requests", body, options)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,73 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_service"
|
|
4
|
+
|
|
5
|
+
module ApiBrasil
|
|
6
|
+
module Services
|
|
7
|
+
module Platform
|
|
8
|
+
# IP Whitelist da conta (`/ip-whitelist/*`).
|
|
9
|
+
# Restringe de quais IPs o Bearer Token pode ser usado.
|
|
10
|
+
#
|
|
11
|
+
# `get`/`set` seguem os nomes usados nas demais SDKs; por isso as
|
|
12
|
+
# chamadas internas usam `http.*` diretamente.
|
|
13
|
+
class IpWhitelistService < BaseService
|
|
14
|
+
# Configuracao atual: `GET /ip-whitelist`.
|
|
15
|
+
#
|
|
16
|
+
# @return [Object]
|
|
17
|
+
def get(options = {})
|
|
18
|
+
http.get("/ip-whitelist", options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Substitui a lista inteira: `PUT /ip-whitelist`.
|
|
22
|
+
#
|
|
23
|
+
# @param ip_whitelist [String, Array<String>]
|
|
24
|
+
# @return [Object]
|
|
25
|
+
def set(ip_whitelist, options = {})
|
|
26
|
+
http.put("/ip-whitelist", { "ip_whitelist" => ip_whitelist }, options)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Adiciona uma entrada: `POST /ip-whitelist/add`.
|
|
30
|
+
#
|
|
31
|
+
# @return [Object]
|
|
32
|
+
def add(entry, options = {})
|
|
33
|
+
http.post("/ip-whitelist/add", { "entry" => entry }, options)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Remove uma entrada: `DELETE /ip-whitelist/remove`.
|
|
37
|
+
#
|
|
38
|
+
# @return [Object]
|
|
39
|
+
def remove(entry, options = {})
|
|
40
|
+
http.delete("/ip-whitelist/remove", { "entry" => entry }, options)
|
|
41
|
+
end
|
|
42
|
+
|
|
43
|
+
# Adiciona o IP atual: `POST /ip-whitelist/add-current`.
|
|
44
|
+
#
|
|
45
|
+
# @return [Object]
|
|
46
|
+
def add_current(options = {})
|
|
47
|
+
http.post("/ip-whitelist/add-current", nil, options)
|
|
48
|
+
end
|
|
49
|
+
|
|
50
|
+
# Libera todos os IPs (wildcard): `POST /ip-whitelist/reset`.
|
|
51
|
+
#
|
|
52
|
+
# @return [Object]
|
|
53
|
+
def reset(options = {})
|
|
54
|
+
http.post("/ip-whitelist/reset", nil, options)
|
|
55
|
+
end
|
|
56
|
+
|
|
57
|
+
# Valida uma entrada: `POST /ip-whitelist/validate`.
|
|
58
|
+
#
|
|
59
|
+
# @return [Object]
|
|
60
|
+
def validate(entry, options = {})
|
|
61
|
+
http.post("/ip-whitelist/validate", { "entry" => entry }, options)
|
|
62
|
+
end
|
|
63
|
+
|
|
64
|
+
# IP atual visto pelo gateway: `GET /ip-whitelist/current-ip`.
|
|
65
|
+
#
|
|
66
|
+
# @return [Object]
|
|
67
|
+
def current_ip(options = {})
|
|
68
|
+
http.get("/ip-whitelist/current-ip", options)
|
|
69
|
+
end
|
|
70
|
+
end
|
|
71
|
+
end
|
|
72
|
+
end
|
|
73
|
+
end
|
|
@@ -0,0 +1,124 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
require_relative "../base_service"
|
|
4
|
+
|
|
5
|
+
module ApiBrasil
|
|
6
|
+
module Services
|
|
7
|
+
module Platform
|
|
8
|
+
# Pagamentos e recargas (PIX, boleto e cartao) - `/recharge`,
|
|
9
|
+
# `/{provider}/pix/*`, `/{provider}/boleto/*`, `/mercadopago/card/*`.
|
|
10
|
+
class PaymentsService < BaseService
|
|
11
|
+
# Provedores de pagamento suportados pelo gateway.
|
|
12
|
+
PROVIDERS = %w[santander inter mercadopago sicoob].freeze
|
|
13
|
+
|
|
14
|
+
# Lista as recargas: `GET /recharges`.
|
|
15
|
+
#
|
|
16
|
+
# @return [Object]
|
|
17
|
+
def recharges(options = {})
|
|
18
|
+
get("/recharges", options)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Cria uma recarga (pix|boleto): `POST /recharge`.
|
|
22
|
+
#
|
|
23
|
+
# @param body [Hash] `amount`, `type`
|
|
24
|
+
# @return [Object]
|
|
25
|
+
def recharge(body, options = {})
|
|
26
|
+
post("/recharge", body, options)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Detalha uma recarga: `GET /recharge/{identifier}`.
|
|
30
|
+
#
|
|
31
|
+
# @return [Object]
|
|
32
|
+
def recharge_show(identifier, options = {})
|
|
33
|
+
get("/recharge/#{identifier}", options)
|
|
34
|
+
end
|
|
35
|
+
|
|
36
|
+
# Gera uma cobranca PIX: `POST /{provider}/pix/generate`.
|
|
37
|
+
#
|
|
38
|
+
# @param provider [String] um de `PROVIDERS`
|
|
39
|
+
# @return [Object]
|
|
40
|
+
def pix_generate(provider, body, options = {})
|
|
41
|
+
post("/#{provider}/pix/generate", body, options)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Consulta uma cobranca PIX: `GET /{provider}/pix/{tx_id}`.
|
|
45
|
+
#
|
|
46
|
+
# @return [Object]
|
|
47
|
+
def pix_status(provider, tx_id, options = {})
|
|
48
|
+
get("/#{provider}/pix/#{tx_id}", options)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
# Gera um boleto: `POST /{provider}/boleto/generate`.
|
|
52
|
+
#
|
|
53
|
+
# @return [Object]
|
|
54
|
+
def boleto_generate(provider, body, options = {})
|
|
55
|
+
post("/#{provider}/boleto/generate", body, options)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
# Consulta um boleto: `GET /{provider}/boleto/{id}`.
|
|
59
|
+
#
|
|
60
|
+
# @return [Object]
|
|
61
|
+
def boleto_status(provider, id, options = {})
|
|
62
|
+
get("/#{provider}/boleto/#{id}", options)
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Baixa o PDF de um boleto: `GET /{provider}/boleto/{id}/pdf`.
|
|
66
|
+
# Devolve o conteudo binario do arquivo.
|
|
67
|
+
#
|
|
68
|
+
# @return [String]
|
|
69
|
+
def boleto_pdf(provider, id, options = {})
|
|
70
|
+
get("/#{provider}/boleto/#{id}/pdf", { response_type: "raw" }.merge(options))
|
|
71
|
+
end
|
|
72
|
+
|
|
73
|
+
# Processa pagamento com cartao (Mercado Pago): `POST /mercadopago/card/process`.
|
|
74
|
+
#
|
|
75
|
+
# @return [Object]
|
|
76
|
+
def card_process(body, options = {})
|
|
77
|
+
post("/mercadopago/card/process", body, options)
|
|
78
|
+
end
|
|
79
|
+
|
|
80
|
+
# Consulta parcelas do cartao: `POST /mercadopago/card/installments`.
|
|
81
|
+
#
|
|
82
|
+
# @return [Object]
|
|
83
|
+
def card_installments(body, options = {})
|
|
84
|
+
post("/mercadopago/card/installments", body, options)
|
|
85
|
+
end
|
|
86
|
+
|
|
87
|
+
# Consulta um pagamento de cartao: `GET /mercadopago/card/{id}`.
|
|
88
|
+
#
|
|
89
|
+
# @return [Object]
|
|
90
|
+
def card_status(id, options = {})
|
|
91
|
+
get("/mercadopago/card/#{id}", options)
|
|
92
|
+
end
|
|
93
|
+
|
|
94
|
+
# Metodos de pagamento do checkout: `GET /checkout/payment-methods`.
|
|
95
|
+
#
|
|
96
|
+
# @return [Object]
|
|
97
|
+
def checkout_payment_methods(options = {})
|
|
98
|
+
get("/checkout/payment-methods", options)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# Periodos do checkout: `GET /checkout/periods`.
|
|
102
|
+
#
|
|
103
|
+
# @return [Object]
|
|
104
|
+
def checkout_periods(options = {})
|
|
105
|
+
get("/checkout/periods", options)
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Valida um cupom: `POST /checkout/validate-coupon`.
|
|
109
|
+
#
|
|
110
|
+
# @return [Object]
|
|
111
|
+
def validate_coupon(body, options = {})
|
|
112
|
+
post("/checkout/validate-coupon", body, options)
|
|
113
|
+
end
|
|
114
|
+
|
|
115
|
+
# Finaliza o checkout: `POST /checkout/finalize`.
|
|
116
|
+
#
|
|
117
|
+
# @return [Object]
|
|
118
|
+
def checkout_finalize(body, options = {})
|
|
119
|
+
post("/checkout/finalize", body, options)
|
|
120
|
+
end
|
|
121
|
+
end
|
|
122
|
+
end
|
|
123
|
+
end
|
|
124
|
+
end
|