bzapper 0.7.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 +7 -0
- data/LICENSE +21 -0
- data/README.md +323 -0
- data/lib/bzapper/client.rb +122 -0
- data/lib/bzapper/codec.rb +112 -0
- data/lib/bzapper/errors.rb +126 -0
- data/lib/bzapper/resources/accounts.rb +394 -0
- data/lib/bzapper/resources/advanced.rb +388 -0
- data/lib/bzapper/resources/advisories.rb +39 -0
- data/lib/bzapper/resources/base.rb +56 -0
- data/lib/bzapper/resources/billing.rb +177 -0
- data/lib/bzapper/resources/campaigns.rb +273 -0
- data/lib/bzapper/resources/connect.rb +35 -0
- data/lib/bzapper/resources/contacts.rb +481 -0
- data/lib/bzapper/resources/conversations.rb +47 -0
- data/lib/bzapper/resources/groups.rb +252 -0
- data/lib/bzapper/resources/instances.rb +287 -0
- data/lib/bzapper/resources/messages.rb +920 -0
- data/lib/bzapper/resources/partner.rb +134 -0
- data/lib/bzapper/resources/pools.rb +69 -0
- data/lib/bzapper/resources/scheduling.rb +38 -0
- data/lib/bzapper/resources/system.rb +21 -0
- data/lib/bzapper/resources/usage.rb +42 -0
- data/lib/bzapper/resources/webhooks.rb +147 -0
- data/lib/bzapper/resources.rb +100 -0
- data/lib/bzapper/transport.rb +248 -0
- data/lib/bzapper/unset.rb +27 -0
- data/lib/bzapper/upload.rb +61 -0
- data/lib/bzapper/version.rb +7 -0
- data/lib/bzapper/webhook.rb +194 -0
- data/lib/bzapper.rb +30 -0
- metadata +74 -0
|
@@ -0,0 +1,134 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Operações do bZapper Connect do lado do PARCEIRO (`/partner/*`) — métodos do
|
|
8
|
+
# {Bzapper::PartnerClient}.
|
|
9
|
+
module PartnerOperations
|
|
10
|
+
# Partner identity (who the partner secret belongs to). `GET /partner/me`
|
|
11
|
+
#
|
|
12
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
13
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
14
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
15
|
+
def get_partner_me(timeout: nil)
|
|
16
|
+
request("GET", "/partner/me", timeout: timeout)
|
|
17
|
+
end
|
|
18
|
+
|
|
19
|
+
# Open a Connect session for one of your customers (backend → bZapper). `POST
|
|
20
|
+
# /partner/connect-sessions`
|
|
21
|
+
#
|
|
22
|
+
# Creates (or reuses) the **connection** of your customer (`external_id` = the customer id in
|
|
23
|
+
# YOUR system) and returns a short-lived `session_token` (30 min) that opens the embedded
|
|
24
|
+
# component (`BzapperConnect.open({ session })`). The customer data you send is trusted: you
|
|
25
|
+
# already authenticated this person in your product, so inside the component the account is
|
|
26
|
+
# created **without password, captcha or email confirmation**. Exception: if the email already
|
|
27
|
+
# has a bZapper account, the component asks for a code sent to that email before linking it.
|
|
28
|
+
# Call this from your **backend** only — the partner secret must never reach a browser.
|
|
29
|
+
#
|
|
30
|
+
# @param external_id [String] (corpo) Your id for this customer. Same id = same connection.
|
|
31
|
+
# @param customer [Hash] (corpo) Your customer, as authenticated in your product. `name` or
|
|
32
|
+
# `company` is required.
|
|
33
|
+
# @param locale [String, nil] (corpo)
|
|
34
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
35
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
36
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
37
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
38
|
+
def create_connect_session(external_id:, customer:, locale: UNSET, idempotency_key: nil,
|
|
39
|
+
timeout: nil)
|
|
40
|
+
payload = compact(
|
|
41
|
+
"external_id" => external_id,
|
|
42
|
+
"customer" => customer,
|
|
43
|
+
"locale" => locale
|
|
44
|
+
)
|
|
45
|
+
request("POST",
|
|
46
|
+
"/partner/connect-sessions",
|
|
47
|
+
body: payload,
|
|
48
|
+
idempotency_key: idempotency_key,
|
|
49
|
+
timeout: timeout)
|
|
50
|
+
end
|
|
51
|
+
|
|
52
|
+
# Exchange the completion code for the customer's API key. `POST /partner/connect/exchange`
|
|
53
|
+
#
|
|
54
|
+
# When the customer finishes (Pro paid + WhatsApp connected), the component emits
|
|
55
|
+
# `bzapper:complete` with a one-time `code` (valid 10 min). Send it to your backend and exchange
|
|
56
|
+
# it here. The response carries the **raw API key** (`bz_live_...`) — store it; it is not shown
|
|
57
|
+
# again (use `rotate-key` if lost).
|
|
58
|
+
#
|
|
59
|
+
# @param code [String] (corpo)
|
|
60
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
61
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
62
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
63
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
64
|
+
def exchange_connect_code(code:, idempotency_key: nil, timeout: nil)
|
|
65
|
+
payload = compact(
|
|
66
|
+
"code" => code
|
|
67
|
+
)
|
|
68
|
+
request("POST",
|
|
69
|
+
"/partner/connect/exchange",
|
|
70
|
+
body: payload,
|
|
71
|
+
idempotency_key: idempotency_key,
|
|
72
|
+
timeout: timeout)
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# List your connections (filter by external_id / status). `GET /partner/connections`
|
|
76
|
+
#
|
|
77
|
+
# @param external_id [String, nil] (query)
|
|
78
|
+
# @param status [String, nil] (query)
|
|
79
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
80
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
81
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
82
|
+
def list_partner_connections(external_id: nil, status: nil, timeout: nil)
|
|
83
|
+
query = {
|
|
84
|
+
"external_id" => external_id,
|
|
85
|
+
"status" => status
|
|
86
|
+
}
|
|
87
|
+
request("GET", "/partner/connections", query: query, timeout: timeout)
|
|
88
|
+
end
|
|
89
|
+
|
|
90
|
+
# Get one connection (status, account, numbers). `GET /partner/connections/{id}`
|
|
91
|
+
#
|
|
92
|
+
# @param id [String] Instance ID (UUID).
|
|
93
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
94
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
95
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
96
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
97
|
+
def get_partner_connection(id, timeout: nil)
|
|
98
|
+
request("GET", "/partner/connections/#{segment(id, "id")}", timeout: timeout)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
# End a connection (revokes the key; does NOT cancel the customer's plan). `DELETE
|
|
102
|
+
# /partner/connections/{id}`
|
|
103
|
+
#
|
|
104
|
+
# @param id [String] Instance ID (UUID).
|
|
105
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
106
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
107
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
108
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
109
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
110
|
+
def revoke_partner_connection(id, idempotency_key: nil, timeout: nil)
|
|
111
|
+
request("DELETE",
|
|
112
|
+
"/partner/connections/#{segment(id, "id")}",
|
|
113
|
+
idempotency_key: idempotency_key,
|
|
114
|
+
timeout: timeout)
|
|
115
|
+
end
|
|
116
|
+
|
|
117
|
+
# Issue a new API key for a completed connection (the previous key stops working). `POST
|
|
118
|
+
# /partner/connections/{id}/rotate-key`
|
|
119
|
+
#
|
|
120
|
+
# @param id [String] Instance ID (UUID).
|
|
121
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
122
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
123
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
124
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
125
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
126
|
+
def rotate_partner_connection_key(id, idempotency_key: nil, timeout: nil)
|
|
127
|
+
request("POST",
|
|
128
|
+
"/partner/connections/#{segment(id, "id")}/rotate-key",
|
|
129
|
+
idempotency_key: idempotency_key,
|
|
130
|
+
timeout: timeout)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
end
|
|
134
|
+
end
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Pools de números (rotação) — `client.pools`.
|
|
8
|
+
class Pools < Base
|
|
9
|
+
# List the tenant's pools. `GET /pools`
|
|
10
|
+
#
|
|
11
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
12
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
13
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
14
|
+
def list_pools(timeout: nil)
|
|
15
|
+
request("GET", "/pools", timeout: timeout)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Create a number pool. `POST /pools`
|
|
19
|
+
#
|
|
20
|
+
# @param name [String, nil] (corpo)
|
|
21
|
+
# @param strategy [String, nil] (corpo) Pool rotation strategy.
|
|
22
|
+
# @param is_default [Boolean, nil] (corpo)
|
|
23
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
24
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
25
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
26
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
27
|
+
def create_pool(name: UNSET, strategy: UNSET, is_default: UNSET, idempotency_key: nil,
|
|
28
|
+
timeout: nil)
|
|
29
|
+
payload = compact(
|
|
30
|
+
"name" => name,
|
|
31
|
+
"strategy" => strategy,
|
|
32
|
+
"is_default" => is_default
|
|
33
|
+
)
|
|
34
|
+
request("POST", "/pools", body: payload, idempotency_key: idempotency_key, timeout: timeout)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Get a pool (with members). `GET /pools/{id}`
|
|
38
|
+
#
|
|
39
|
+
# @param id [String] Instance ID (UUID).
|
|
40
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
41
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
42
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
43
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
44
|
+
def get_pool(id, timeout: nil)
|
|
45
|
+
request("GET", "/pools/#{segment(id, "id")}", timeout: timeout)
|
|
46
|
+
end
|
|
47
|
+
|
|
48
|
+
# Add a number to the pool. `POST /pools/{id}/numbers`
|
|
49
|
+
#
|
|
50
|
+
# @param id [String] Instance ID (UUID).
|
|
51
|
+
# @param instance_id [String] (corpo)
|
|
52
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
53
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
54
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
55
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
56
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
57
|
+
def add_pool_number(id, instance_id:, idempotency_key: nil, timeout: nil)
|
|
58
|
+
payload = compact(
|
|
59
|
+
"instance_id" => instance_id
|
|
60
|
+
)
|
|
61
|
+
request("POST",
|
|
62
|
+
"/pools/#{segment(id, "id")}/numbers",
|
|
63
|
+
body: payload,
|
|
64
|
+
idempotency_key: idempotency_key,
|
|
65
|
+
timeout: timeout)
|
|
66
|
+
end
|
|
67
|
+
end
|
|
68
|
+
end
|
|
69
|
+
end
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Envios agendados — `client.scheduling`.
|
|
8
|
+
class Scheduling < Base
|
|
9
|
+
# List scheduled sends. `GET /messages/scheduled`
|
|
10
|
+
#
|
|
11
|
+
# @param limit [Integer, nil] (query) Max items.
|
|
12
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
13
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
14
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
15
|
+
def list_scheduled(limit: nil, timeout: nil)
|
|
16
|
+
query = {
|
|
17
|
+
"limit" => limit
|
|
18
|
+
}
|
|
19
|
+
request("GET", "/messages/scheduled", query: query, timeout: timeout)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
# Cancel a pending scheduled send. `DELETE /messages/scheduled/{id}`
|
|
23
|
+
#
|
|
24
|
+
# @param id [String] parâmetro de caminho
|
|
25
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
26
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
27
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
28
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
29
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
30
|
+
def cancel_scheduled(id, idempotency_key: nil, timeout: nil)
|
|
31
|
+
request("DELETE",
|
|
32
|
+
"/messages/scheduled/#{segment(id, "id")}",
|
|
33
|
+
idempotency_key: idempotency_key,
|
|
34
|
+
timeout: timeout)
|
|
35
|
+
end
|
|
36
|
+
end
|
|
37
|
+
end
|
|
38
|
+
end
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Saúde e meta — `client.system`.
|
|
8
|
+
class System < Base
|
|
9
|
+
# Health check. `GET /healthz`
|
|
10
|
+
#
|
|
11
|
+
# Service liveness/readiness. No authentication.
|
|
12
|
+
#
|
|
13
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
14
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
15
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
16
|
+
def get_health(timeout: nil)
|
|
17
|
+
request("GET", "/healthz", timeout: timeout)
|
|
18
|
+
end
|
|
19
|
+
end
|
|
20
|
+
end
|
|
21
|
+
end
|
|
@@ -0,0 +1,42 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Uso medido (consumo) — `client.usage`.
|
|
8
|
+
class Usage < Base
|
|
9
|
+
# AGGREGATE account usage + per project (admin). `GET /account/usage`
|
|
10
|
+
#
|
|
11
|
+
# Billing basis — sums all projects and breaks it down per project.
|
|
12
|
+
#
|
|
13
|
+
# @param from [Time, String, nil] (query)
|
|
14
|
+
# @param to [Time, String, nil] (query)
|
|
15
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
16
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
17
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
18
|
+
def get_account_usage(from: nil, to: nil, timeout: nil)
|
|
19
|
+
query = {
|
|
20
|
+
"from" => from,
|
|
21
|
+
"to" => to
|
|
22
|
+
}
|
|
23
|
+
request("GET", "/account/usage", query: query, timeout: timeout)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
# Tenant usage summary (by period/type/number). `GET /usage`
|
|
27
|
+
#
|
|
28
|
+
# @param from [Time, String, nil] (query)
|
|
29
|
+
# @param to [Time, String, nil] (query)
|
|
30
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
31
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
32
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
33
|
+
def get_usage(from: nil, to: nil, timeout: nil)
|
|
34
|
+
query = {
|
|
35
|
+
"from" => from,
|
|
36
|
+
"to" => to
|
|
37
|
+
}
|
|
38
|
+
request("GET", "/usage", query: query, timeout: timeout)
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
end
|
|
42
|
+
end
|
|
@@ -0,0 +1,147 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
module Bzapper
|
|
6
|
+
module Resources
|
|
7
|
+
# Webhooks de eventos (gestão, teste, entregas) — `client.webhooks`.
|
|
8
|
+
class Webhooks < Base
|
|
9
|
+
# List webhooks. `GET /webhooks`
|
|
10
|
+
#
|
|
11
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
12
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
13
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
14
|
+
def list_webhooks(timeout: nil)
|
|
15
|
+
request("GET", "/webhooks", timeout: timeout)
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
# Register a webhook. `POST /webhooks`
|
|
19
|
+
#
|
|
20
|
+
# @param url [String] (corpo)
|
|
21
|
+
# @param secret [String, nil] (corpo) HMAC-SHA256 secret (stored encrypted). Omit to have a
|
|
22
|
+
# strong `whsec_...` secret generated and returned once.
|
|
23
|
+
# @param event_types [Array<String>, nil] (corpo) Empty = all events.
|
|
24
|
+
# @param number_filter [String, nil] (corpo) instance_id; empty = all.
|
|
25
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
26
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
27
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
28
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
29
|
+
def create_webhook(url:, secret: UNSET, event_types: UNSET, number_filter: UNSET,
|
|
30
|
+
idempotency_key: nil, timeout: nil)
|
|
31
|
+
payload = compact(
|
|
32
|
+
"url" => url,
|
|
33
|
+
"secret" => secret,
|
|
34
|
+
"event_types" => event_types,
|
|
35
|
+
"number_filter" => number_filter
|
|
36
|
+
)
|
|
37
|
+
request("POST",
|
|
38
|
+
"/webhooks",
|
|
39
|
+
body: payload,
|
|
40
|
+
idempotency_key: idempotency_key,
|
|
41
|
+
timeout: timeout)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
# Update a webhook (send `secret: "regenerate"` to rotate the secret). `PATCH /webhooks/{id}`
|
|
45
|
+
#
|
|
46
|
+
# Replaces url, event types, number filter and active flag. `url` is required. `active` omitted
|
|
47
|
+
# = true. With `secret: "regenerate"` a new secret is generated and returned ONCE in the
|
|
48
|
+
# response; any other non-empty `secret` replaces it.
|
|
49
|
+
#
|
|
50
|
+
# @param id [String] Resource ID (UUID).
|
|
51
|
+
# @param url [String] (corpo)
|
|
52
|
+
# @param secret [String, nil] (corpo) Empty = keep. "regenerate" = rotate (returned once).
|
|
53
|
+
# @param event_types [Array<String>, nil] (corpo) Empty = all events.
|
|
54
|
+
# @param number_filter [String, nil] (corpo) instance_id; empty = all.
|
|
55
|
+
# @param active [Boolean, nil] (corpo)
|
|
56
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
57
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
58
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
59
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
60
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
61
|
+
def update_webhook(id, url:, secret: UNSET, event_types: UNSET, number_filter: UNSET,
|
|
62
|
+
active: UNSET, idempotency_key: nil, timeout: nil)
|
|
63
|
+
payload = compact(
|
|
64
|
+
"url" => url,
|
|
65
|
+
"secret" => secret,
|
|
66
|
+
"event_types" => event_types,
|
|
67
|
+
"number_filter" => number_filter,
|
|
68
|
+
"active" => active
|
|
69
|
+
)
|
|
70
|
+
request("PATCH",
|
|
71
|
+
"/webhooks/#{segment(id, "id")}",
|
|
72
|
+
body: payload,
|
|
73
|
+
idempotency_key: idempotency_key,
|
|
74
|
+
timeout: timeout)
|
|
75
|
+
end
|
|
76
|
+
|
|
77
|
+
# Remove a webhook. `DELETE /webhooks/{id}`
|
|
78
|
+
#
|
|
79
|
+
# @param id [String] Instance ID (UUID).
|
|
80
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
81
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
82
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
83
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
84
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
85
|
+
def delete_webhook(id, idempotency_key: nil, timeout: nil)
|
|
86
|
+
request("DELETE",
|
|
87
|
+
"/webhooks/#{segment(id, "id")}",
|
|
88
|
+
idempotency_key: idempotency_key,
|
|
89
|
+
timeout: timeout)
|
|
90
|
+
end
|
|
91
|
+
|
|
92
|
+
# Send a signed sample event to this webhook and report the result. `POST /webhooks/{id}/test`
|
|
93
|
+
#
|
|
94
|
+
# @param id [String] Resource ID (UUID).
|
|
95
|
+
# @param event_type [String, nil] (corpo) Event type of the sample (default a generic one).
|
|
96
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
97
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
98
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
99
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
100
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
101
|
+
def test_webhook(id, event_type: UNSET, idempotency_key: nil, timeout: nil)
|
|
102
|
+
payload = compact(
|
|
103
|
+
"event_type" => event_type
|
|
104
|
+
)
|
|
105
|
+
request("POST",
|
|
106
|
+
"/webhooks/#{segment(id, "id")}/test",
|
|
107
|
+
body: payload,
|
|
108
|
+
idempotency_key: idempotency_key,
|
|
109
|
+
timeout: timeout)
|
|
110
|
+
end
|
|
111
|
+
|
|
112
|
+
# Latest deliveries of a webhook. `GET /webhooks/{id}/deliveries`
|
|
113
|
+
#
|
|
114
|
+
# @param id [String] Resource ID (UUID).
|
|
115
|
+
# @param limit [Integer, nil] (query) 1–200 (default 50).
|
|
116
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
117
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
118
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
119
|
+
# @raise [ArgumentError] parâmetro de caminho vazio, "." ou "..".
|
|
120
|
+
def list_webhook_deliveries(id, limit: nil, timeout: nil)
|
|
121
|
+
query = {
|
|
122
|
+
"limit" => limit
|
|
123
|
+
}
|
|
124
|
+
request("GET", "/webhooks/#{segment(id, "id")}/deliveries", query: query, timeout: timeout)
|
|
125
|
+
end
|
|
126
|
+
|
|
127
|
+
# Emit a sample event to the project's stream and webhooks (like `stripe trigger`). `POST
|
|
128
|
+
# /webhooks/trigger`
|
|
129
|
+
#
|
|
130
|
+
# @param event_type [String, nil] (corpo)
|
|
131
|
+
# @param idempotency_key [String, nil] chave de idempotência (senão a SDK gera uma).
|
|
132
|
+
# @param timeout [Numeric, nil] segundos por tentativa (padrão: o do cliente).
|
|
133
|
+
# @return [Hash, Array, nil] o JSON da resposta, inteiro (nil em 204).
|
|
134
|
+
# @raise [Bzapper::Error] resposta fora de 2xx ou falha de rede.
|
|
135
|
+
def trigger_webhook_event(event_type: UNSET, idempotency_key: nil, timeout: nil)
|
|
136
|
+
payload = compact(
|
|
137
|
+
"event_type" => event_type
|
|
138
|
+
)
|
|
139
|
+
request("POST",
|
|
140
|
+
"/webhooks/trigger",
|
|
141
|
+
body: payload,
|
|
142
|
+
idempotency_key: idempotency_key,
|
|
143
|
+
timeout: timeout)
|
|
144
|
+
end
|
|
145
|
+
end
|
|
146
|
+
end
|
|
147
|
+
end
|
|
@@ -0,0 +1,100 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
# GERADO por script/generate.rb a partir de packages/sdk/openapi.yaml — não edite à mão.
|
|
4
|
+
|
|
5
|
+
require_relative "resources/base"
|
|
6
|
+
require_relative "resources/accounts"
|
|
7
|
+
require_relative "resources/contacts"
|
|
8
|
+
require_relative "resources/usage"
|
|
9
|
+
require_relative "resources/billing"
|
|
10
|
+
require_relative "resources/advanced"
|
|
11
|
+
require_relative "resources/conversations"
|
|
12
|
+
require_relative "resources/instances"
|
|
13
|
+
require_relative "resources/groups"
|
|
14
|
+
require_relative "resources/system"
|
|
15
|
+
require_relative "resources/messages"
|
|
16
|
+
require_relative "resources/scheduling"
|
|
17
|
+
require_relative "resources/campaigns"
|
|
18
|
+
require_relative "resources/advisories"
|
|
19
|
+
require_relative "resources/webhooks"
|
|
20
|
+
require_relative "resources/pools"
|
|
21
|
+
require_relative "resources/connect"
|
|
22
|
+
require_relative "resources/partner"
|
|
23
|
+
|
|
24
|
+
module Bzapper
|
|
25
|
+
# Os recursos do {Client} (um por tag da spec). Incluído no {Client}.
|
|
26
|
+
# @api private
|
|
27
|
+
module ResourceAccessors
|
|
28
|
+
# @return [Resources::Accounts] Conta, perfil, chaves de API, marca, projetos e usuários.
|
|
29
|
+
attr_reader :accounts
|
|
30
|
+
|
|
31
|
+
# @return [Resources::Contacts] Contatos (CRM), tags, grupos de contatos, opt-in/out, supressões e checagem.
|
|
32
|
+
attr_reader :contacts
|
|
33
|
+
|
|
34
|
+
# @return [Resources::Usage] Uso medido (consumo).
|
|
35
|
+
attr_reader :usage
|
|
36
|
+
|
|
37
|
+
# @return [Resources::Billing] Cobrança: plano, assinatura, add-ons, faturas e preços.
|
|
38
|
+
attr_reader :billing
|
|
39
|
+
|
|
40
|
+
# @return [Resources::Advanced] Recursos avançados: editar/apagar/encaminhar, perfil, privacidade, chats, etiquetas, bloqueio e chamadas.
|
|
41
|
+
attr_reader :advanced
|
|
42
|
+
|
|
43
|
+
# @return [Resources::Conversations] Conversas (inbox) e histórico.
|
|
44
|
+
attr_reader :conversations
|
|
45
|
+
|
|
46
|
+
# @return [Resources::Instances] Números (instâncias): conexão, QR, sessão, proxy, filtros de entrada e conta oficial.
|
|
47
|
+
attr_reader :instances
|
|
48
|
+
|
|
49
|
+
# @return [Resources::Groups] Grupos do WhatsApp: info, participantes, convite, prévia e pedidos de entrada.
|
|
50
|
+
attr_reader :groups
|
|
51
|
+
|
|
52
|
+
# @return [Resources::System] Saúde e meta.
|
|
53
|
+
attr_reader :system
|
|
54
|
+
|
|
55
|
+
# @return [Resources::Messages] Envio de mensagens (todos os tipos, OTP), presença e confirmação de leitura.
|
|
56
|
+
attr_reader :messages
|
|
57
|
+
|
|
58
|
+
# @return [Resources::Scheduling] Envios agendados.
|
|
59
|
+
attr_reader :scheduling
|
|
60
|
+
|
|
61
|
+
# @return [Resources::Campaigns] Campanhas: estimativa, destinatários, simulação e controle.
|
|
62
|
+
attr_reader :campaigns
|
|
63
|
+
|
|
64
|
+
# @return [Resources::Advisories] Avisos "atualize sua integração".
|
|
65
|
+
attr_reader :advisories
|
|
66
|
+
|
|
67
|
+
# @return [Resources::Webhooks] Webhooks de eventos (gestão, teste, entregas).
|
|
68
|
+
attr_reader :webhooks
|
|
69
|
+
|
|
70
|
+
# @return [Resources::Pools] Pools de números (rotação).
|
|
71
|
+
attr_reader :pools
|
|
72
|
+
|
|
73
|
+
# @return [Resources::Connect] bZapper Connect do lado do CLIENTE: apps parceiros conectados à conta.
|
|
74
|
+
attr_reader :connect
|
|
75
|
+
|
|
76
|
+
# Nomes dos recursos, na ordem da spec.
|
|
77
|
+
RESOURCES = %i[accounts contacts usage billing advanced conversations instances groups system messages scheduling campaigns advisories webhooks pools connect].freeze
|
|
78
|
+
|
|
79
|
+
private
|
|
80
|
+
|
|
81
|
+
def build_resources(transport)
|
|
82
|
+
@accounts = Resources::Accounts.new(transport)
|
|
83
|
+
@contacts = Resources::Contacts.new(transport)
|
|
84
|
+
@usage = Resources::Usage.new(transport)
|
|
85
|
+
@billing = Resources::Billing.new(transport)
|
|
86
|
+
@advanced = Resources::Advanced.new(transport)
|
|
87
|
+
@conversations = Resources::Conversations.new(transport)
|
|
88
|
+
@instances = Resources::Instances.new(transport)
|
|
89
|
+
@groups = Resources::Groups.new(transport)
|
|
90
|
+
@system = Resources::System.new(transport)
|
|
91
|
+
@messages = Resources::Messages.new(transport)
|
|
92
|
+
@scheduling = Resources::Scheduling.new(transport)
|
|
93
|
+
@campaigns = Resources::Campaigns.new(transport)
|
|
94
|
+
@advisories = Resources::Advisories.new(transport)
|
|
95
|
+
@webhooks = Resources::Webhooks.new(transport)
|
|
96
|
+
@pools = Resources::Pools.new(transport)
|
|
97
|
+
@connect = Resources::Connect.new(transport)
|
|
98
|
+
end
|
|
99
|
+
end
|
|
100
|
+
end
|