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.
Files changed (45) hide show
  1. checksums.yaml +7 -0
  2. data/CHANGELOG.md +27 -0
  3. data/LICENSE +21 -0
  4. data/README.md +330 -0
  5. data/SECURITY.md +32 -0
  6. data/lib/api_brasil/client.rb +252 -0
  7. data/lib/api_brasil/core/env.rb +34 -0
  8. data/lib/api_brasil/core/errors.rb +167 -0
  9. data/lib/api_brasil/core/http_client.rb +342 -0
  10. data/lib/api_brasil/core/retry.rb +69 -0
  11. data/lib/api_brasil/core/transport/faraday_transport.rb +76 -0
  12. data/lib/api_brasil/core/transport/net_http_transport.rb +126 -0
  13. data/lib/api_brasil/core/transport.rb +114 -0
  14. data/lib/api_brasil/generated/catalog.rb +526 -0
  15. data/lib/api_brasil/legacy/service.rb +155 -0
  16. data/lib/api_brasil/services/base_service.rb +49 -0
  17. data/lib/api_brasil/services/data/bulk_service.rb +26 -0
  18. data/lib/api_brasil/services/data/cep_service.rb +58 -0
  19. data/lib/api_brasil/services/data/chip_virtual_service.rb +40 -0
  20. data/lib/api_brasil/services/data/consulta_service.rb +97 -0
  21. data/lib/api_brasil/services/data/correios_service.rb +23 -0
  22. data/lib/api_brasil/services/data/dados_service.rb +30 -0
  23. data/lib/api_brasil/services/data/database_ip_service.rb +19 -0
  24. data/lib/api_brasil/services/data/fipe_service.rb +61 -0
  25. data/lib/api_brasil/services/data/proxies.rb +146 -0
  26. data/lib/api_brasil/services/data/ura_service.rb +26 -0
  27. data/lib/api_brasil/services/data/vehicles_service.rb +46 -0
  28. data/lib/api_brasil/services/device_proxy_service.rb +46 -0
  29. data/lib/api_brasil/services/messaging/evolution_service.rb +38 -0
  30. data/lib/api_brasil/services/messaging/sms_service.rb +40 -0
  31. data/lib/api_brasil/services/messaging/whats_meow_service.rb +30 -0
  32. data/lib/api_brasil/services/messaging/whatsapp_service.rb +120 -0
  33. data/lib/api_brasil/services/platform/account_service.rb +138 -0
  34. data/lib/api_brasil/services/platform/auth_service.rb +204 -0
  35. data/lib/api_brasil/services/platform/bearer_rate_limit_service.rb +29 -0
  36. data/lib/api_brasil/services/platform/catalog_service.rb +111 -0
  37. data/lib/api_brasil/services/platform/devices_service.rb +73 -0
  38. data/lib/api_brasil/services/platform/ip_whitelist_service.rb +73 -0
  39. data/lib/api_brasil/services/platform/payments_service.rb +124 -0
  40. data/lib/api_brasil/services/platform/reports_service.rb +96 -0
  41. data/lib/api_brasil/version.rb +6 -0
  42. data/lib/api_brasil.rb +72 -0
  43. data/lib/apigratis-sdk-ruby.rb +5 -0
  44. data/lib/apigratis.rb +11 -0
  45. metadata +149 -0
@@ -0,0 +1,146 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_service"
4
+ require_relative "../device_proxy_service"
5
+
6
+ module ApiBrasil
7
+ module Services
8
+ module Data
9
+ # Geolocalizacao (device-based): `/geolocation/{action}`.
10
+ class GeolocationService < DeviceProxyService
11
+ def initialize(http)
12
+ super(http, "geolocation")
13
+ end
14
+
15
+ # Converte endereco em coordenadas: `POST /geolocation/geocode`.
16
+ #
17
+ # @return [Object]
18
+ def geocode(body, options = {})
19
+ request("geocode", body, options)
20
+ end
21
+
22
+ # Geocoding direto: `POST /geolocation/forward-geocoding`.
23
+ #
24
+ # @return [Object]
25
+ def forward_geocoding(body, options = {})
26
+ request("forward-geocoding", body, options)
27
+ end
28
+ end
29
+
30
+ # Matriz de distancias (device-based): `/geomatrix/{action}`.
31
+ class GeomatrixService < DeviceProxyService
32
+ def initialize(http)
33
+ super(http, "geomatrix")
34
+ end
35
+
36
+ # Distancia entre pontos: `POST /geomatrix/distance`.
37
+ #
38
+ # @return [Object]
39
+ def distance(body, options = {})
40
+ request("distance", body, options)
41
+ end
42
+ end
43
+
44
+ # OCR / Google Vision (device-based): `/recognize/{action}`.
45
+ class RecognizeService < DeviceProxyService
46
+ def initialize(http)
47
+ super(http, "recognize")
48
+ end
49
+
50
+ # Reconhece uma imagem em base64: `POST /recognize/base64`.
51
+ #
52
+ # @return [Object]
53
+ def base64(body, options = {})
54
+ request("base64", body, options)
55
+ end
56
+
57
+ # Reconhece uma imagem por URL: `POST /recognize/uri`.
58
+ #
59
+ # @return [Object]
60
+ def uri(body, options = {})
61
+ request("uri", body, options)
62
+ end
63
+ end
64
+
65
+ # DDD (device-based): `/ddd/{action}`.
66
+ class DddService < DeviceProxyService
67
+ def initialize(http)
68
+ super(http, "ddd")
69
+ end
70
+ end
71
+
72
+ # Feriados (device-based): `/holidays/{action}`.
73
+ class HolidaysService < DeviceProxyService
74
+ def initialize(http)
75
+ super(http, "holidays")
76
+ end
77
+
78
+ # Lista os feriados: `POST /holidays/feriados`.
79
+ #
80
+ # @return [Object]
81
+ def feriados(body, options = {})
82
+ request("feriados", body, options)
83
+ end
84
+ end
85
+
86
+ # Traducao (device-based): `/translate/{action}`.
87
+ class TranslateService < DeviceProxyService
88
+ def initialize(http)
89
+ super(http, "translate")
90
+ end
91
+
92
+ # Identifica o idioma de um texto: `POST /translate/identify`.
93
+ #
94
+ # @return [Object]
95
+ def identify(body, options = {})
96
+ request("identify", body, options)
97
+ end
98
+
99
+ # Lista os modelos de traducao: `POST /translate/models`.
100
+ #
101
+ # @return [Object]
102
+ def models(body = nil, options = {})
103
+ request("models", body, options)
104
+ end
105
+ end
106
+
107
+ # Clima (device-based): `/weather/{action}`.
108
+ class WeatherService < DeviceProxyService
109
+ def initialize(http)
110
+ super(http, "weather")
111
+ end
112
+
113
+ # Clima por cidade: `POST /weather/city`.
114
+ #
115
+ # @return [Object]
116
+ def city(body, options = {})
117
+ request("city", body, options)
118
+ end
119
+
120
+ # Clima por coordenadas: `POST /weather/coordenates`.
121
+ #
122
+ # @return [Object]
123
+ def coordenates(body, options = {})
124
+ request("coordenates", body, options)
125
+ end
126
+ end
127
+
128
+ # Loterias (device-based): `/loterias/{sorteio}/*`.
129
+ class LoteriasService < BaseService
130
+ # Resultado de um concurso: `POST /loterias/{sorteio}/{concurso}`.
131
+ #
132
+ # @return [Object]
133
+ def resultado(sorteio, concurso, body = nil, options = {})
134
+ post("/loterias/#{sorteio}/#{concurso}", body, options)
135
+ end
136
+
137
+ # Ultimo resultado: `POST /loterias/{sorteio}/latest`.
138
+ #
139
+ # @return [Object]
140
+ def latest(sorteio, body = nil, options = {})
141
+ post("/loterias/#{sorteio}/latest", body, options)
142
+ end
143
+ end
144
+ end
145
+ end
146
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Data
8
+ # URA reversa / ligacoes: `/ura/call/*`.
9
+ class UraService < BaseService
10
+ # Disca uma ligacao: `POST /ura/call/dialler`.
11
+ #
12
+ # @return [Object]
13
+ def dialler(body, options = {})
14
+ post("/ura/call/dialler", body, options)
15
+ end
16
+
17
+ # Consulta status da ligacao: `POST /ura/call/status`.
18
+ #
19
+ # @return [Object]
20
+ def status(body, options = {})
21
+ post("/ura/call/status", body, options)
22
+ end
23
+ end
24
+ end
25
+ end
26
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "uri"
4
+
5
+ require_relative "../device_proxy_service"
6
+
7
+ module ApiBrasil
8
+ module Services
9
+ module Data
10
+ # Veiculos por placa (device-based): `/vehicles/{action}`.
11
+ class VehiclesService < DeviceProxyService
12
+ def initialize(http)
13
+ super(http, "vehicles")
14
+ end
15
+
16
+ # Dados do veiculo pela placa: `POST /vehicles/dados` body `{"placa" => ...}`.
17
+ #
18
+ # @return [Object]
19
+ def dados(body, options = {})
20
+ request("dados", body, options)
21
+ end
22
+
23
+ # FIPE pela placa: `POST /vehicles/fipe` body `{"placa" => ...}`.
24
+ #
25
+ # @return [Object]
26
+ def fipe(body, options = {})
27
+ request("fipe", body, options)
28
+ end
29
+
30
+ # Consulta FIPE: `POST /vehicles/consultafipe/{placa}`.
31
+ #
32
+ # @return [Object]
33
+ def consulta_fipe(placa, options = {})
34
+ request("consultafipe/#{Core::HttpClient.escape_path_segment(placa)}", nil, options)
35
+ end
36
+
37
+ # Base dedicada: `POST /vehicles/base/000/{base}` (`dados` ou `fipe`).
38
+ #
39
+ # @return [Object]
40
+ def base(dataset, body, options = {})
41
+ post("/vehicles/base/000/#{dataset}", body, options)
42
+ end
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,46 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "base_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ # Base dos servicos "device-based" do gateway (`/api/v2/{servico}/{action}`).
8
+ # Exigem `Authorization: Bearer` + header `DeviceToken`.
9
+ #
10
+ # Todos expoem `request(action, body)` como porta de saida generica - as
11
+ # actions sao dinamicas por provedor, consulte a documentacao em
12
+ # https://doc.apibrasil.io
13
+ #
14
+ # A resposta segue o envelope device-based
15
+ # (`{"error" => ..., "message" => ..., "response" => ...}`).
16
+ class DeviceProxyService < BaseService
17
+ # @return [String] nome do servico no gateway (primeiro segmento da rota)
18
+ attr_reader :service
19
+
20
+ # @param http [ApiBrasil::Core::HttpClient]
21
+ # @param service [String]
22
+ def initialize(http, service)
23
+ super(http)
24
+ @service = service
25
+ end
26
+
27
+ # Executa uma action do servico: `POST /{servico}/{action}`.
28
+ #
29
+ # @param action [String]
30
+ # @param body [Hash, nil]
31
+ # @param options [Hash]
32
+ # @return [Object]
33
+ def request(action, body = nil, options = {})
34
+ post("/#{service}/#{action.to_s.gsub(%r{\A/+|/+\z}, "")}", body, options)
35
+ end
36
+
37
+ # Executa a mesma action de forma assincrona via fila:
38
+ # `POST /{servico}/{action}/queue`.
39
+ #
40
+ # @return [Object]
41
+ def queue(action, body = nil, options = {})
42
+ post("/#{service}/#{action.to_s.gsub(%r{\A/+|/+\z}, "")}/queue", body, options)
43
+ end
44
+ end
45
+ end
46
+ end
@@ -0,0 +1,38 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Messaging
8
+ # Evolution API (device-based): `POST /evolution/{controller}/{action}`.
9
+ # Exige `Authorization: Bearer` + `DeviceToken`.
10
+ #
11
+ # Exemplos de controller/action: `instance/create`, `message/sendText`.
12
+ # Os caminhos documentados estao em
13
+ # `ApiBrasil::Generated::Catalog::EVOLUTION_PATHS`.
14
+ class EvolutionService < BaseService
15
+ # Executa `POST /evolution/{controller}/{action}`.
16
+ #
17
+ # @return [Object]
18
+ def request(controller, action, body = nil, options = {})
19
+ post("/evolution/#{controller}/#{action}", body, options)
20
+ end
21
+
22
+ # Executa um caminho completo do catalogo: `POST /evolution/{path}`.
23
+ #
24
+ # @return [Object]
25
+ def call(path, body = nil, options = {})
26
+ post("/evolution/#{path.to_s.sub(%r{\A/+}, "")}", body, options)
27
+ end
28
+
29
+ # Executa a mesma chamada de forma assincrona via fila.
30
+ #
31
+ # @return [Object]
32
+ def queue(controller, action, body = nil, options = {})
33
+ post("/evolution/#{controller}/#{action}/queue", body, options)
34
+ end
35
+ end
36
+ end
37
+ end
38
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../device_proxy_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Messaging
8
+ # API de SMS (device-based): `POST /sms/{action}`.
9
+ # Exige `Authorization: Bearer` + `DeviceToken`.
10
+ class SmsService < DeviceProxyService
11
+ def initialize(http)
12
+ super(http, "sms")
13
+ end
14
+
15
+ # Envia um SMS pelo device: `POST /sms/send`.
16
+ #
17
+ # Campos: `number`, `message`, `operator`, `user_reply`, `webhook_url`.
18
+ #
19
+ # @return [Object]
20
+ def send_message(body, options = {})
21
+ request("send", body, options)
22
+ end
23
+
24
+ # `send` mantem a paridade com as demais SDKs (`api.sms.send(...)`).
25
+ # `send_message` e o alias idiomatico em Ruby, ja que `Object#send`
26
+ # tem outro significado na linguagem - `public_send` e `__send__`
27
+ # continuam disponiveis normalmente.
28
+ alias send send_message
29
+
30
+ # Envia um SMS debitando creditos da conta (sem DeviceToken):
31
+ # `POST /sms/send/credits`.
32
+ #
33
+ # @return [Object]
34
+ def send_with_credits(body, options = {})
35
+ post("/sms/send/credits", body, options)
36
+ end
37
+ end
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,30 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Messaging
8
+ # WhatsMeow API (device-based): `POST /whatsmeow/{action}`.
9
+ # Exige `Authorization: Bearer` + `DeviceToken`.
10
+ #
11
+ # As actions documentadas estao em
12
+ # `ApiBrasil::Generated::Catalog::WHATSMEOW_ACTIONS`.
13
+ class WhatsMeowService < BaseService
14
+ # Executa `POST /whatsmeow/{action}`.
15
+ #
16
+ # @return [Object]
17
+ def request(action, body = nil, options = {})
18
+ post("/whatsmeow/#{action.to_s.sub(%r{\A/+}, "")}", body, options)
19
+ end
20
+
21
+ # Executa a mesma chamada de forma assincrona via fila.
22
+ #
23
+ # @return [Object]
24
+ def queue(action, body = nil, options = {})
25
+ post("/whatsmeow/#{action.to_s.sub(%r{\A/+}, "")}/queue", body, options)
26
+ end
27
+ end
28
+ end
29
+ end
30
+ end
@@ -0,0 +1,120 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../device_proxy_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Messaging
8
+ # API de WhatsApp (device-based): `POST /whatsapp/{action}`.
9
+ # Exige `Authorization: Bearer` + `DeviceToken`.
10
+ #
11
+ # Alem dos metodos nomeados, `request(action, body)` aceita qualquer
12
+ # action do catalogo (`ApiBrasil::Generated::Catalog::WHATSAPP_ACTIONS`).
13
+ class WhatsAppService < DeviceProxyService
14
+ def initialize(http)
15
+ super(http, "whatsapp")
16
+ end
17
+
18
+ # Inicia a sessao do device (aceita webhooks opcionais):
19
+ # `webhook_wh_status`, `webhook_wh_message`, `webhook_wh_connect`,
20
+ # `webhook_wh_qrcode`.
21
+ #
22
+ # @return [Object]
23
+ def start(body = nil, options = {})
24
+ request("start", body, options)
25
+ end
26
+
27
+ # Retorna o QR Code de pareamento (`response.qrcode` em base64).
28
+ #
29
+ # @return [Object]
30
+ def qrcode(body = nil, options = {})
31
+ request("qrcode", body, options)
32
+ end
33
+
34
+ # Encerra a sessao.
35
+ #
36
+ # @return [Object]
37
+ def logout(body = nil, options = {})
38
+ request("logout", body, options)
39
+ end
40
+
41
+ # Fecha o navegador/sessao no servidor.
42
+ #
43
+ # @return [Object]
44
+ def close(body = nil, options = {})
45
+ request("close", body, options)
46
+ end
47
+
48
+ # Apaga a sessao no servidor.
49
+ #
50
+ # @return [Object]
51
+ def delete_session(body = nil, options = {})
52
+ request("deleteSession", body, options)
53
+ end
54
+
55
+ # Status da conexao: `POST /whatsapp/getConnectionStatus`.
56
+ #
57
+ # @return [Object]
58
+ def connection_status(body = nil, options = {})
59
+ request("getConnectionStatus", body, options)
60
+ end
61
+
62
+ # Envia mensagem de texto: `{"number" => "5511999999999", "text" => "Ola!"}`.
63
+ #
64
+ # @return [Object]
65
+ def send_text(body, options = {})
66
+ request("sendText", body, options)
67
+ end
68
+
69
+ # Envia arquivo a partir de uma URL: `{"number" => ..., "path" => ...}`.
70
+ #
71
+ # @return [Object]
72
+ def send_file(body, options = {})
73
+ request("sendFile", body, options)
74
+ end
75
+
76
+ # Envia arquivo em base64.
77
+ #
78
+ # @return [Object]
79
+ def send_file64(body, options = {})
80
+ request("sendFile64", body, options)
81
+ end
82
+
83
+ # Envia audio (URL; convertido para mp3 pelo gateway, max. 6 min).
84
+ #
85
+ # @return [Object]
86
+ def send_audio(body, options = {})
87
+ request("sendAudio", body, options)
88
+ end
89
+
90
+ # Envia video a partir de uma URL.
91
+ #
92
+ # @return [Object]
93
+ def send_video(body, options = {})
94
+ request("sendVideo", body, options)
95
+ end
96
+
97
+ # Envia um link com preview.
98
+ #
99
+ # @return [Object]
100
+ def send_link(body, options = {})
101
+ request("sendLink", body, options)
102
+ end
103
+
104
+ # Envia uma localizacao: `{"number" => ..., "lat" => ..., "lng" => ...}`.
105
+ #
106
+ # @return [Object]
107
+ def send_location(body, options = {})
108
+ request("sendLocation", body, options)
109
+ end
110
+
111
+ # Envia um contato.
112
+ #
113
+ # @return [Object]
114
+ def send_contact(body, options = {})
115
+ request("sendContact", body, options)
116
+ end
117
+ end
118
+ end
119
+ end
120
+ end
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ require_relative "../base_service"
4
+
5
+ module ApiBrasil
6
+ module Services
7
+ module Platform
8
+ # Conta, saldo, faturas, notificacoes e tickets.
9
+ class AccountService < BaseService
10
+ # Saldo/creditos da conta: `GET /balance`.
11
+ #
12
+ # @return [Object]
13
+ def balance(options = {})
14
+ get("/balance", options)
15
+ end
16
+
17
+ # Plano atual: `GET /plan`.
18
+ #
19
+ # @return [Object]
20
+ def plan(options = {})
21
+ get("/plan", options)
22
+ end
23
+
24
+ # Faturas: `GET /invoices`.
25
+ #
26
+ # @return [Object]
27
+ def invoices(options = {})
28
+ get("/invoices", options)
29
+ end
30
+
31
+ # Notas fiscais das faturas: `GET /invoices/notes`.
32
+ #
33
+ # @return [Object]
34
+ def invoice_notes(options = {})
35
+ get("/invoices/notes", options)
36
+ end
37
+
38
+ # Paga uma fatura: `POST /invoices/pay`.
39
+ #
40
+ # @return [Object]
41
+ def pay_invoice(body, options = {})
42
+ post("/invoices/pay", body, options)
43
+ end
44
+
45
+ # Historico de requisicoes da conta: `POST /requests`.
46
+ #
47
+ # @return [Object]
48
+ def requests(body = nil, options = {})
49
+ post("/requests", body, options)
50
+ end
51
+
52
+ # Historico de requisicoes por API: `POST /api/requests`.
53
+ #
54
+ # @return [Object]
55
+ def api_requests(body = nil, options = {})
56
+ post("/api/requests", body, options)
57
+ end
58
+
59
+ # Jobs em fila do usuario: `GET /jobs`.
60
+ #
61
+ # @return [Object]
62
+ def jobs(options = {})
63
+ get("/jobs", options)
64
+ end
65
+
66
+ # Credenciais do usuario: `GET /credentials`.
67
+ #
68
+ # @return [Object]
69
+ def credentials(options = {})
70
+ get("/credentials", options)
71
+ end
72
+
73
+ # Indicacoes do usuario: `GET /indications`.
74
+ #
75
+ # @return [Object]
76
+ def indications(options = {})
77
+ get("/indications", options)
78
+ end
79
+
80
+ # Notificacoes: `GET /notifications`.
81
+ #
82
+ # @return [Object]
83
+ def notifications(options = {})
84
+ get("/notifications", options)
85
+ end
86
+
87
+ # Marca uma notificacao como lida: `PATCH /notifications/{id}/read`.
88
+ #
89
+ # @return [Object]
90
+ def mark_notification_read(id, options = {})
91
+ patch("/notifications/#{id}/read", nil, options)
92
+ end
93
+
94
+ # Marca todas as notificacoes como lidas: `POST /notifications/mark-all-read`.
95
+ #
96
+ # @return [Object]
97
+ def mark_all_notifications_read(options = {})
98
+ post("/notifications/mark-all-read", nil, options)
99
+ end
100
+
101
+ # Tickets de suporte: `GET /tickets`.
102
+ #
103
+ # @return [Object]
104
+ def tickets(options = {})
105
+ get("/tickets", options)
106
+ end
107
+
108
+ # Abre um ticket: `POST /ticket`.
109
+ #
110
+ # @return [Object]
111
+ def create_ticket(body, options = {})
112
+ post("/ticket", body, options)
113
+ end
114
+
115
+ # Atualiza um ticket: `PUT /ticket/{id}`.
116
+ #
117
+ # @return [Object]
118
+ def update_ticket(id, body, options = {})
119
+ put("/ticket/#{id}", body, options)
120
+ end
121
+
122
+ # Mensagens de um ticket: `GET /ticket/{id}/messages`.
123
+ #
124
+ # @return [Object]
125
+ def ticket_messages(id, options = {})
126
+ get("/ticket/#{id}/messages", options)
127
+ end
128
+
129
+ # Responde um ticket: `POST /ticket/{id}/messages`.
130
+ #
131
+ # @return [Object]
132
+ def add_ticket_message(id, body, options = {})
133
+ post("/ticket/#{id}/messages", body, options)
134
+ end
135
+ end
136
+ end
137
+ end
138
+ end