perata-sdk 0.2.0 → 0.3.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 +4 -4
- data/README.md +15 -8
- data/lib/perata/client.rb +50 -0
- data/lib/perata/models.rb +1428 -38
- data/lib/perata/params.rb +626 -2
- data/lib/perata/services.rb +519 -19
- data/lib/perata/version.rb +1 -1
- data/lib/perata/webhooks.rb +19 -1
- metadata +1 -1
data/lib/perata/services.rb
CHANGED
|
@@ -3,13 +3,152 @@
|
|
|
3
3
|
# Code generated by sdk/generator. DO NOT EDIT.
|
|
4
4
|
|
|
5
5
|
module Perata
|
|
6
|
+
# The API's benefits.
|
|
7
|
+
class BenefitsService
|
|
8
|
+
def initialize(client)
|
|
9
|
+
@client = client
|
|
10
|
+
end
|
|
11
|
+
|
|
12
|
+
# Criar um benefício custom, license_key, feature_flag ou meter_credit; downloads e os benefícios do Discord e do GitHub se configuram no painel.
|
|
13
|
+
#
|
|
14
|
+
# @param params [BenefitsCreateParams, Hash]
|
|
15
|
+
# @return [Benefit]
|
|
16
|
+
def create(params, idempotency_key: nil, api_key: nil)
|
|
17
|
+
data = @client.request("POST", "/api/v1/benefits", body: BenefitsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
18
|
+
Benefit.from_hash(data)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
# Excluir um benefício: ele sai de todos os produtos e é revogado de quem o tem. The API answers 204, so there is nothing to return.
|
|
22
|
+
#
|
|
23
|
+
# @return [nil]
|
|
24
|
+
def delete(benefit, idempotency_key: nil, api_key: nil)
|
|
25
|
+
@client.request("DELETE", "/api/v1/benefits/#{Perata.segment(benefit)}", idempotency_key: idempotency_key, api_key: api_key)
|
|
26
|
+
nil
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
# Ler um benefício.
|
|
30
|
+
#
|
|
31
|
+
# @return [Benefit]
|
|
32
|
+
def get(benefit, api_key: nil)
|
|
33
|
+
data = @client.request("GET", "/api/v1/benefits/#{Perata.segment(benefit)}", api_key: api_key)
|
|
34
|
+
Benefit.from_hash(data)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
# Listar benefícios, opcionalmente de um tipo (type). One page; +list_iter+ walks every page.
|
|
38
|
+
#
|
|
39
|
+
# @return [Page<Benefit>]
|
|
40
|
+
def list(page: nil, limit: nil, type: nil, api_key: nil)
|
|
41
|
+
query = { "page" => page, "limit" => limit, "type" => type }
|
|
42
|
+
data = @client.request("GET", "/api/v1/benefits", query: query, api_key: api_key)
|
|
43
|
+
Page.from_hash(data) { |item| Benefit.from_hash(item) }
|
|
44
|
+
end
|
|
45
|
+
|
|
46
|
+
# Walks every page of benefits:list from +page+, item by item.
|
|
47
|
+
#
|
|
48
|
+
# @return [Enumerator<Benefit>]
|
|
49
|
+
def list_iter(page: nil, limit: nil, type: nil, api_key: nil, &block)
|
|
50
|
+
items = Page.iterate(page) do |at|
|
|
51
|
+
list(page: at, limit: limit, type: type, api_key: api_key)
|
|
52
|
+
end
|
|
53
|
+
block ? items.each(&block) : items
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
# Listar as concessões de um benefício, opcionalmente de um cliente (customer_id) ou só as vigentes (is_granted). One page; +list_grants_iter+ walks every page.
|
|
57
|
+
#
|
|
58
|
+
# @return [Page<BenefitGrant>]
|
|
59
|
+
def list_grants(benefit, page: nil, limit: nil, customer_id: nil, is_granted: nil, api_key: nil)
|
|
60
|
+
query = { "page" => page, "limit" => limit, "customer_id" => customer_id, "is_granted" => is_granted }
|
|
61
|
+
data = @client.request("GET", "/api/v1/benefits/#{Perata.segment(benefit)}/grants", query: query, api_key: api_key)
|
|
62
|
+
Page.from_hash(data) { |item| BenefitGrant.from_hash(item) }
|
|
63
|
+
end
|
|
64
|
+
|
|
65
|
+
# Walks every page of benefits:list_grants from +page+, item by item.
|
|
66
|
+
#
|
|
67
|
+
# @return [Enumerator<BenefitGrant>]
|
|
68
|
+
def list_grants_iter(benefit, page: nil, limit: nil, customer_id: nil, is_granted: nil, api_key: nil, &block)
|
|
69
|
+
items = Page.iterate(page) do |at|
|
|
70
|
+
list_grants(benefit, page: at, limit: limit, customer_id: customer_id, is_granted: is_granted, api_key: api_key)
|
|
71
|
+
end
|
|
72
|
+
block ? items.each(&block) : items
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
# Atualizar o nome, a visibilidade, as propriedades e os metadados de um benefício; o tipo e a descrição dada na criação não mudam, e o que a concessão já entregou fica como foi entregue.
|
|
76
|
+
#
|
|
77
|
+
# @param params [BenefitsUpdateParams, Hash]
|
|
78
|
+
# @return [Benefit]
|
|
79
|
+
def update(benefit, params, idempotency_key: nil, api_key: nil)
|
|
80
|
+
data = @client.request("PATCH", "/api/v1/benefits/#{Perata.segment(benefit)}", body: BenefitsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
81
|
+
Benefit.from_hash(data)
|
|
82
|
+
end
|
|
83
|
+
end
|
|
84
|
+
|
|
85
|
+
# The API's checkout-links.
|
|
86
|
+
class CheckoutLinksService
|
|
87
|
+
def initialize(client)
|
|
88
|
+
@client = client
|
|
89
|
+
end
|
|
90
|
+
|
|
91
|
+
# Criar um link de checkout: uma oferta durável de um ou mais produtos, com desconto, quantidade e páginas de retorno.
|
|
92
|
+
#
|
|
93
|
+
# @param params [CheckoutLinksCreateParams, Hash]
|
|
94
|
+
# @return [CheckoutLink]
|
|
95
|
+
def create(params, idempotency_key: nil, api_key: nil)
|
|
96
|
+
data = @client.request("POST", "/api/v1/checkout-links", body: CheckoutLinksCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
97
|
+
CheckoutLink.from_hash(data)
|
|
98
|
+
end
|
|
99
|
+
|
|
100
|
+
# Excluir um link de checkout: ele deixa de abrir checkouts; os que já abriu continuam. The API answers 204, so there is nothing to return.
|
|
101
|
+
#
|
|
102
|
+
# @return [nil]
|
|
103
|
+
def delete(checkout_link, idempotency_key: nil, api_key: nil)
|
|
104
|
+
@client.request("DELETE", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", idempotency_key: idempotency_key, api_key: api_key)
|
|
105
|
+
nil
|
|
106
|
+
end
|
|
107
|
+
|
|
108
|
+
# Ler um link de checkout.
|
|
109
|
+
#
|
|
110
|
+
# @return [CheckoutLink]
|
|
111
|
+
def get(checkout_link, api_key: nil)
|
|
112
|
+
data = @client.request("GET", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", api_key: api_key)
|
|
113
|
+
CheckoutLink.from_hash(data)
|
|
114
|
+
end
|
|
115
|
+
|
|
116
|
+
# Listar links de checkout. One page; +list_iter+ walks every page.
|
|
117
|
+
#
|
|
118
|
+
# @return [Page<CheckoutLink>]
|
|
119
|
+
def list(page: nil, limit: nil, api_key: nil)
|
|
120
|
+
query = { "page" => page, "limit" => limit }
|
|
121
|
+
data = @client.request("GET", "/api/v1/checkout-links", query: query, api_key: api_key)
|
|
122
|
+
Page.from_hash(data) { |item| CheckoutLink.from_hash(item) }
|
|
123
|
+
end
|
|
124
|
+
|
|
125
|
+
# Walks every page of checkout-links:list from +page+, item by item.
|
|
126
|
+
#
|
|
127
|
+
# @return [Enumerator<CheckoutLink>]
|
|
128
|
+
def list_iter(page: nil, limit: nil, api_key: nil, &block)
|
|
129
|
+
items = Page.iterate(page) do |at|
|
|
130
|
+
list(page: at, limit: limit, api_key: api_key)
|
|
131
|
+
end
|
|
132
|
+
block ? items.each(&block) : items
|
|
133
|
+
end
|
|
134
|
+
|
|
135
|
+
# Atualizar o rótulo, as páginas de retorno, os produtos e os metadados de um link; a quantidade e o desconto ficam como foram publicados.
|
|
136
|
+
#
|
|
137
|
+
# @param params [CheckoutLinksUpdateParams, Hash]
|
|
138
|
+
# @return [CheckoutLink]
|
|
139
|
+
def update(checkout_link, params, idempotency_key: nil, api_key: nil)
|
|
140
|
+
data = @client.request("PATCH", "/api/v1/checkout-links/#{Perata.segment(checkout_link)}", body: CheckoutLinksUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
141
|
+
CheckoutLink.from_hash(data)
|
|
142
|
+
end
|
|
143
|
+
end
|
|
144
|
+
|
|
6
145
|
# The API's checkouts.
|
|
7
146
|
class CheckoutsService
|
|
8
147
|
def initialize(client)
|
|
9
148
|
@client = client
|
|
10
149
|
end
|
|
11
150
|
|
|
12
|
-
#
|
|
151
|
+
# Criar o endereço de um checkout para um produto e um preço.
|
|
13
152
|
#
|
|
14
153
|
# @param params [CheckoutsCreateParams, Hash]
|
|
15
154
|
# @return [Checkout]
|
|
@@ -17,6 +156,23 @@ module Perata
|
|
|
17
156
|
data = @client.request("POST", "/api/v1/checkouts", body: CheckoutsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
18
157
|
Checkout.from_hash(data)
|
|
19
158
|
end
|
|
159
|
+
|
|
160
|
+
# Ler um checkout: o endereço, o estado e as páginas de retorno.
|
|
161
|
+
#
|
|
162
|
+
# @return [Checkout]
|
|
163
|
+
def get(checkout, api_key: nil)
|
|
164
|
+
data = @client.request("GET", "/api/v1/checkouts/#{Perata.segment(checkout)}", api_key: api_key)
|
|
165
|
+
Checkout.from_hash(data)
|
|
166
|
+
end
|
|
167
|
+
|
|
168
|
+
# Atualizar o rótulo e as páginas de retorno de um checkout ativo.
|
|
169
|
+
#
|
|
170
|
+
# @param params [CheckoutsUpdateParams, Hash]
|
|
171
|
+
# @return [Checkout]
|
|
172
|
+
def update(checkout, params, idempotency_key: nil, api_key: nil)
|
|
173
|
+
data = @client.request("PATCH", "/api/v1/checkouts/#{Perata.segment(checkout)}", body: CheckoutsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
174
|
+
Checkout.from_hash(data)
|
|
175
|
+
end
|
|
20
176
|
end
|
|
21
177
|
|
|
22
178
|
# The API's customer-sessions.
|
|
@@ -25,7 +181,7 @@ module Perata
|
|
|
25
181
|
@client = client
|
|
26
182
|
end
|
|
27
183
|
|
|
28
|
-
#
|
|
184
|
+
# Entrar com um cliente no portal do cliente: o endereço o abre já autenticado.
|
|
29
185
|
#
|
|
30
186
|
# @param params [CustomerSessionsCreateParams, Hash]
|
|
31
187
|
# @return [CustomerSession]
|
|
@@ -41,7 +197,7 @@ module Perata
|
|
|
41
197
|
@client = client
|
|
42
198
|
end
|
|
43
199
|
|
|
44
|
-
#
|
|
200
|
+
# Criar um cliente.
|
|
45
201
|
#
|
|
46
202
|
# @param params [CustomersCreateParams, Hash]
|
|
47
203
|
# @return [Customer]
|
|
@@ -50,7 +206,15 @@ module Perata
|
|
|
50
206
|
Customer.from_hash(data)
|
|
51
207
|
end
|
|
52
208
|
|
|
53
|
-
#
|
|
209
|
+
# Excluir um cliente: as assinaturas terminam na hora, os benefícios são revogados e o ID externo é liberado; pedidos e pagamentos continuam. The API answers 204, so there is nothing to return.
|
|
210
|
+
#
|
|
211
|
+
# @return [nil]
|
|
212
|
+
def delete(customer, idempotency_key: nil, api_key: nil)
|
|
213
|
+
@client.request("DELETE", "/api/v1/customers/#{Perata.segment(customer)}", idempotency_key: idempotency_key, api_key: api_key)
|
|
214
|
+
nil
|
|
215
|
+
end
|
|
216
|
+
|
|
217
|
+
# Ler um cliente.
|
|
54
218
|
#
|
|
55
219
|
# @return [Customer]
|
|
56
220
|
def get(customer, api_key: nil)
|
|
@@ -58,7 +222,23 @@ module Perata
|
|
|
58
222
|
Customer.from_hash(data)
|
|
59
223
|
end
|
|
60
224
|
|
|
61
|
-
#
|
|
225
|
+
# Ler um cliente pelo ID dele no sistema do lojista (external_id).
|
|
226
|
+
#
|
|
227
|
+
# @return [Customer]
|
|
228
|
+
def get_external(external_id, api_key: nil)
|
|
229
|
+
data = @client.request("GET", "/api/v1/external-customers/#{Perata.segment(external_id)}", api_key: api_key)
|
|
230
|
+
Customer.from_hash(data)
|
|
231
|
+
end
|
|
232
|
+
|
|
233
|
+
# Ler o estado de um cliente: assinaturas ativas e benefícios vigentes, inclusive os feature flags.
|
|
234
|
+
#
|
|
235
|
+
# @return [CustomerState]
|
|
236
|
+
def get_state(customer, api_key: nil)
|
|
237
|
+
data = @client.request("GET", "/api/v1/customers/#{Perata.segment(customer)}/state", api_key: api_key)
|
|
238
|
+
CustomerState.from_hash(data)
|
|
239
|
+
end
|
|
240
|
+
|
|
241
|
+
# Listar clientes. One page; +list_iter+ walks every page.
|
|
62
242
|
#
|
|
63
243
|
# @return [Page<Customer>]
|
|
64
244
|
def list(page: nil, limit: nil, api_key: nil)
|
|
@@ -76,6 +256,178 @@ module Perata
|
|
|
76
256
|
end
|
|
77
257
|
block ? items.each(&block) : items
|
|
78
258
|
end
|
|
259
|
+
|
|
260
|
+
# Atualizar o nome, o e-mail ou o ID externo de um cliente; o ID externo não muda depois de definido.
|
|
261
|
+
#
|
|
262
|
+
# @param params [CustomersUpdateParams, Hash]
|
|
263
|
+
# @return [Customer]
|
|
264
|
+
def update(customer, params, idempotency_key: nil, api_key: nil)
|
|
265
|
+
data = @client.request("PATCH", "/api/v1/customers/#{Perata.segment(customer)}", body: CustomersUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
266
|
+
Customer.from_hash(data)
|
|
267
|
+
end
|
|
268
|
+
|
|
269
|
+
# Atualizar um cliente pelo ID dele no sistema do lojista (external_id).
|
|
270
|
+
#
|
|
271
|
+
# @param params [CustomersUpdateExternalParams, Hash]
|
|
272
|
+
# @return [Customer]
|
|
273
|
+
def update_external(external_id, params, idempotency_key: nil, api_key: nil)
|
|
274
|
+
data = @client.request("PATCH", "/api/v1/external-customers/#{Perata.segment(external_id)}", body: CustomersUpdateExternalParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
275
|
+
Customer.from_hash(data)
|
|
276
|
+
end
|
|
277
|
+
end
|
|
278
|
+
|
|
279
|
+
# The API's discounts.
|
|
280
|
+
class DiscountsService
|
|
281
|
+
def initialize(client)
|
|
282
|
+
@client = client
|
|
283
|
+
end
|
|
284
|
+
|
|
285
|
+
# Criar um desconto percentual (basis_points) ou fixo em reais (amount_cents).
|
|
286
|
+
#
|
|
287
|
+
# @param params [DiscountsCreateParams, Hash]
|
|
288
|
+
# @return [Discount]
|
|
289
|
+
def create(params, idempotency_key: nil, api_key: nil)
|
|
290
|
+
data = @client.request("POST", "/api/v1/discounts", body: DiscountsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
291
|
+
Discount.from_hash(data)
|
|
292
|
+
end
|
|
293
|
+
|
|
294
|
+
# Excluir um desconto: sai das listas e dos checkouts e o código fica livre; o que ele já descontou continua nos registros. The API answers 204, so there is nothing to return.
|
|
295
|
+
#
|
|
296
|
+
# @return [nil]
|
|
297
|
+
def delete(discount, idempotency_key: nil, api_key: nil)
|
|
298
|
+
@client.request("DELETE", "/api/v1/discounts/#{Perata.segment(discount)}", idempotency_key: idempotency_key, api_key: api_key)
|
|
299
|
+
nil
|
|
300
|
+
end
|
|
301
|
+
|
|
302
|
+
# Ler um desconto.
|
|
303
|
+
#
|
|
304
|
+
# @return [Discount]
|
|
305
|
+
def get(discount, api_key: nil)
|
|
306
|
+
data = @client.request("GET", "/api/v1/discounts/#{Perata.segment(discount)}", api_key: api_key)
|
|
307
|
+
Discount.from_hash(data)
|
|
308
|
+
end
|
|
309
|
+
|
|
310
|
+
# Listar descontos. One page; +list_iter+ walks every page.
|
|
311
|
+
#
|
|
312
|
+
# @return [Page<Discount>]
|
|
313
|
+
def list(page: nil, limit: nil, api_key: nil)
|
|
314
|
+
query = { "page" => page, "limit" => limit }
|
|
315
|
+
data = @client.request("GET", "/api/v1/discounts", query: query, api_key: api_key)
|
|
316
|
+
Page.from_hash(data) { |item| Discount.from_hash(item) }
|
|
317
|
+
end
|
|
318
|
+
|
|
319
|
+
# Walks every page of discounts:list from +page+, item by item.
|
|
320
|
+
#
|
|
321
|
+
# @return [Enumerator<Discount>]
|
|
322
|
+
def list_iter(page: nil, limit: nil, api_key: nil, &block)
|
|
323
|
+
items = Page.iterate(page) do |at|
|
|
324
|
+
list(page: at, limit: limit, api_key: api_key)
|
|
325
|
+
end
|
|
326
|
+
block ? items.each(&block) : items
|
|
327
|
+
end
|
|
328
|
+
|
|
329
|
+
# Atualizar um desconto; o tipo e a duração não mudam, e depois do primeiro uso o valor e os meses também não.
|
|
330
|
+
#
|
|
331
|
+
# @param params [DiscountsUpdateParams, Hash]
|
|
332
|
+
# @return [Discount]
|
|
333
|
+
def update(discount, params, idempotency_key: nil, api_key: nil)
|
|
334
|
+
data = @client.request("PATCH", "/api/v1/discounts/#{Perata.segment(discount)}", body: DiscountsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
335
|
+
Discount.from_hash(data)
|
|
336
|
+
end
|
|
337
|
+
end
|
|
338
|
+
|
|
339
|
+
# The API's disputes.
|
|
340
|
+
class DisputesService
|
|
341
|
+
def initialize(client)
|
|
342
|
+
@client = client
|
|
343
|
+
end
|
|
344
|
+
|
|
345
|
+
# Ler uma disputa.
|
|
346
|
+
#
|
|
347
|
+
# @return [Dispute]
|
|
348
|
+
def get(dispute, api_key: nil)
|
|
349
|
+
data = @client.request("GET", "/api/v1/disputes/#{Perata.segment(dispute)}", api_key: api_key)
|
|
350
|
+
Dispute.from_hash(data)
|
|
351
|
+
end
|
|
352
|
+
|
|
353
|
+
# Listar disputas, opcionalmente de um status (status). One page; +list_iter+ walks every page.
|
|
354
|
+
#
|
|
355
|
+
# @return [Page<Dispute>]
|
|
356
|
+
def list(page: nil, limit: nil, status: nil, api_key: nil)
|
|
357
|
+
query = { "page" => page, "limit" => limit, "status" => status }
|
|
358
|
+
data = @client.request("GET", "/api/v1/disputes", query: query, api_key: api_key)
|
|
359
|
+
Page.from_hash(data) { |item| Dispute.from_hash(item) }
|
|
360
|
+
end
|
|
361
|
+
|
|
362
|
+
# Walks every page of disputes:list from +page+, item by item.
|
|
363
|
+
#
|
|
364
|
+
# @return [Enumerator<Dispute>]
|
|
365
|
+
def list_iter(page: nil, limit: nil, status: nil, api_key: nil, &block)
|
|
366
|
+
items = Page.iterate(page) do |at|
|
|
367
|
+
list(page: at, limit: limit, status: status, api_key: api_key)
|
|
368
|
+
end
|
|
369
|
+
block ? items.each(&block) : items
|
|
370
|
+
end
|
|
371
|
+
end
|
|
372
|
+
|
|
373
|
+
# The API's events.
|
|
374
|
+
class EventsService
|
|
375
|
+
def initialize(client)
|
|
376
|
+
@client = client
|
|
377
|
+
end
|
|
378
|
+
|
|
379
|
+
# Listar os eventos de consumo que as origens enviaram, do mais novo ao mais antigo. One page; +list_iter+ walks every page.
|
|
380
|
+
#
|
|
381
|
+
# @return [Page<Event>]
|
|
382
|
+
def list(page: nil, limit: nil, customer_id: nil, start: nil, end_: nil, api_key: nil)
|
|
383
|
+
query = { "page" => page, "limit" => limit, "customer_id" => customer_id, "start" => start, "end" => end_ }
|
|
384
|
+
data = @client.request("GET", "/api/v1/events", query: query, api_key: api_key)
|
|
385
|
+
Page.from_hash(data) { |item| Event.from_hash(item) }
|
|
386
|
+
end
|
|
387
|
+
|
|
388
|
+
# Walks every page of events:list from +page+, item by item.
|
|
389
|
+
#
|
|
390
|
+
# @return [Enumerator<Event>]
|
|
391
|
+
def list_iter(page: nil, limit: nil, customer_id: nil, start: nil, end_: nil, api_key: nil, &block)
|
|
392
|
+
items = Page.iterate(page) do |at|
|
|
393
|
+
list(page: at, limit: limit, customer_id: customer_id, start: start, end_: end_, api_key: api_key)
|
|
394
|
+
end
|
|
395
|
+
block ? items.each(&block) : items
|
|
396
|
+
end
|
|
397
|
+
end
|
|
398
|
+
|
|
399
|
+
# The API's meters.
|
|
400
|
+
class MetersService
|
|
401
|
+
def initialize(client)
|
|
402
|
+
@client = client
|
|
403
|
+
end
|
|
404
|
+
|
|
405
|
+
# Ler um medidor: o filtro dos eventos que ele conta, a agregação e a unidade.
|
|
406
|
+
#
|
|
407
|
+
# @return [Meter]
|
|
408
|
+
def get(meter, api_key: nil)
|
|
409
|
+
data = @client.request("GET", "/api/v1/meters/#{Perata.segment(meter)}", api_key: api_key)
|
|
410
|
+
Meter.from_hash(data)
|
|
411
|
+
end
|
|
412
|
+
|
|
413
|
+
# Listar medidores; os arquivados só com is_archived=true. One page; +list_iter+ walks every page.
|
|
414
|
+
#
|
|
415
|
+
# @return [Page<Meter>]
|
|
416
|
+
def list(page: nil, limit: nil, is_archived: nil, api_key: nil)
|
|
417
|
+
query = { "page" => page, "limit" => limit, "is_archived" => is_archived }
|
|
418
|
+
data = @client.request("GET", "/api/v1/meters", query: query, api_key: api_key)
|
|
419
|
+
Page.from_hash(data) { |item| Meter.from_hash(item) }
|
|
420
|
+
end
|
|
421
|
+
|
|
422
|
+
# Walks every page of meters:list from +page+, item by item.
|
|
423
|
+
#
|
|
424
|
+
# @return [Enumerator<Meter>]
|
|
425
|
+
def list_iter(page: nil, limit: nil, is_archived: nil, api_key: nil, &block)
|
|
426
|
+
items = Page.iterate(page) do |at|
|
|
427
|
+
list(page: at, limit: limit, is_archived: is_archived, api_key: api_key)
|
|
428
|
+
end
|
|
429
|
+
block ? items.each(&block) : items
|
|
430
|
+
end
|
|
79
431
|
end
|
|
80
432
|
|
|
81
433
|
# The API's orders.
|
|
@@ -84,7 +436,31 @@ module Perata
|
|
|
84
436
|
@client = client
|
|
85
437
|
end
|
|
86
438
|
|
|
87
|
-
#
|
|
439
|
+
# Ler um pedido: um checkout pago.
|
|
440
|
+
#
|
|
441
|
+
# @return [Order]
|
|
442
|
+
def get(order, api_key: nil)
|
|
443
|
+
data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}", api_key: api_key)
|
|
444
|
+
Order.from_hash(data)
|
|
445
|
+
end
|
|
446
|
+
|
|
447
|
+
# Ler a fatura de um pedido, o documento comercial que o lojista gerou; sem ela, 404.
|
|
448
|
+
#
|
|
449
|
+
# @return [OrderInvoice]
|
|
450
|
+
def get_invoice(order, api_key: nil)
|
|
451
|
+
data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}/invoice", api_key: api_key)
|
|
452
|
+
OrderInvoice.from_hash(data)
|
|
453
|
+
end
|
|
454
|
+
|
|
455
|
+
# Ler o recibo de um pedido: o que foi pago, quando e como.
|
|
456
|
+
#
|
|
457
|
+
# @return [OrderReceipt]
|
|
458
|
+
def get_receipt(order, api_key: nil)
|
|
459
|
+
data = @client.request("GET", "/api/v1/orders/#{Perata.segment(order)}/receipt", api_key: api_key)
|
|
460
|
+
OrderReceipt.from_hash(data)
|
|
461
|
+
end
|
|
462
|
+
|
|
463
|
+
# Listar pedidos: checkouts pagos. One page; +list_iter+ walks every page.
|
|
88
464
|
#
|
|
89
465
|
# @return [Page<Order>]
|
|
90
466
|
def list(page: nil, limit: nil, api_key: nil)
|
|
@@ -110,7 +486,7 @@ module Perata
|
|
|
110
486
|
@client = client
|
|
111
487
|
end
|
|
112
488
|
|
|
113
|
-
#
|
|
489
|
+
# Parar de cobrar um cartão guardado; recusado enquanto uma assinatura ativa o cobra.
|
|
114
490
|
#
|
|
115
491
|
# @return [PaymentMethodDetached]
|
|
116
492
|
def detach(payment_method, idempotency_key: nil, api_key: nil)
|
|
@@ -118,7 +494,7 @@ module Perata
|
|
|
118
494
|
PaymentMethodDetached.from_hash(data)
|
|
119
495
|
end
|
|
120
496
|
|
|
121
|
-
#
|
|
497
|
+
# Listar os cartões guardados de um cliente: bandeira, quatro últimos dígitos e validade. One page; +list_iter+ walks every page.
|
|
122
498
|
#
|
|
123
499
|
# @return [Page<PaymentMethod>]
|
|
124
500
|
def list(customer, page: nil, limit: nil, api_key: nil)
|
|
@@ -144,7 +520,7 @@ module Perata
|
|
|
144
520
|
@client = client
|
|
145
521
|
end
|
|
146
522
|
|
|
147
|
-
#
|
|
523
|
+
# Ler um pagamento.
|
|
148
524
|
#
|
|
149
525
|
# @return [Payment]
|
|
150
526
|
def get(payment, api_key: nil)
|
|
@@ -152,7 +528,7 @@ module Perata
|
|
|
152
528
|
Payment.from_hash(data)
|
|
153
529
|
end
|
|
154
530
|
|
|
155
|
-
#
|
|
531
|
+
# Listar pagamentos. One page; +list_iter+ walks every page.
|
|
156
532
|
#
|
|
157
533
|
# @return [Page<Payment>]
|
|
158
534
|
def list(page: nil, limit: nil, api_key: nil)
|
|
@@ -178,7 +554,7 @@ module Perata
|
|
|
178
554
|
@client = client
|
|
179
555
|
end
|
|
180
556
|
|
|
181
|
-
#
|
|
557
|
+
# Criar um preço em reais, avulso ou recorrente.
|
|
182
558
|
#
|
|
183
559
|
# @param params [PricesCreateParams, Hash]
|
|
184
560
|
# @return [Price]
|
|
@@ -187,7 +563,7 @@ module Perata
|
|
|
187
563
|
Price.from_hash(data)
|
|
188
564
|
end
|
|
189
565
|
|
|
190
|
-
#
|
|
566
|
+
# Listar preços, opcionalmente de um produto (product_id). One page; +list_iter+ walks every page.
|
|
191
567
|
#
|
|
192
568
|
# @return [Page<Price>]
|
|
193
569
|
def list(page: nil, limit: nil, product_id: nil, api_key: nil)
|
|
@@ -213,7 +589,15 @@ module Perata
|
|
|
213
589
|
@client = client
|
|
214
590
|
end
|
|
215
591
|
|
|
216
|
-
#
|
|
592
|
+
# Arquivar um produto: sai das vendas novas e o que já foi vendido continua apontando para ele.
|
|
593
|
+
#
|
|
594
|
+
# @return [Product]
|
|
595
|
+
def archive(product, idempotency_key: nil, api_key: nil)
|
|
596
|
+
data = @client.request("POST", "/api/v1/products/#{Perata.segment(product)}/archive", idempotency_key: idempotency_key, api_key: api_key)
|
|
597
|
+
Product.from_hash(data)
|
|
598
|
+
end
|
|
599
|
+
|
|
600
|
+
# Criar um produto.
|
|
217
601
|
#
|
|
218
602
|
# @param params [ProductsCreateParams, Hash]
|
|
219
603
|
# @return [Product]
|
|
@@ -222,7 +606,7 @@ module Perata
|
|
|
222
606
|
Product.from_hash(data)
|
|
223
607
|
end
|
|
224
608
|
|
|
225
|
-
#
|
|
609
|
+
# Ler um produto.
|
|
226
610
|
#
|
|
227
611
|
# @return [Product]
|
|
228
612
|
def get(product, api_key: nil)
|
|
@@ -230,7 +614,7 @@ module Perata
|
|
|
230
614
|
Product.from_hash(data)
|
|
231
615
|
end
|
|
232
616
|
|
|
233
|
-
#
|
|
617
|
+
# Listar produtos. One page; +list_iter+ walks every page.
|
|
234
618
|
#
|
|
235
619
|
# @return [Page<Product>]
|
|
236
620
|
def list(page: nil, limit: nil, api_key: nil)
|
|
@@ -248,6 +632,15 @@ module Perata
|
|
|
248
632
|
end
|
|
249
633
|
block ? items.each(&block) : items
|
|
250
634
|
end
|
|
635
|
+
|
|
636
|
+
# Atualizar o nome ou a descrição de um produto ativo.
|
|
637
|
+
#
|
|
638
|
+
# @param params [ProductsUpdateParams, Hash]
|
|
639
|
+
# @return [Product]
|
|
640
|
+
def update(product, params, idempotency_key: nil, api_key: nil)
|
|
641
|
+
data = @client.request("PATCH", "/api/v1/products/#{Perata.segment(product)}", body: ProductsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
642
|
+
Product.from_hash(data)
|
|
643
|
+
end
|
|
251
644
|
end
|
|
252
645
|
|
|
253
646
|
# The API's refunds.
|
|
@@ -256,7 +649,7 @@ module Perata
|
|
|
256
649
|
@client = client
|
|
257
650
|
end
|
|
258
651
|
|
|
259
|
-
#
|
|
652
|
+
# Reembolsar parte ou todo um pagamento.
|
|
260
653
|
#
|
|
261
654
|
# @param params [RefundsCreateParams, Hash]
|
|
262
655
|
# @return [Refund]
|
|
@@ -264,6 +657,25 @@ module Perata
|
|
|
264
657
|
data = @client.request("POST", "/api/v1/refunds", body: RefundsCreateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
265
658
|
Refund.from_hash(data)
|
|
266
659
|
end
|
|
660
|
+
|
|
661
|
+
# Listar reembolsos, opcionalmente de um pagamento (payment_id). One page; +list_iter+ walks every page.
|
|
662
|
+
#
|
|
663
|
+
# @return [Page<Refund>]
|
|
664
|
+
def list(page: nil, limit: nil, payment_id: nil, api_key: nil)
|
|
665
|
+
query = { "page" => page, "limit" => limit, "payment_id" => payment_id }
|
|
666
|
+
data = @client.request("GET", "/api/v1/refunds", query: query, api_key: api_key)
|
|
667
|
+
Page.from_hash(data) { |item| Refund.from_hash(item) }
|
|
668
|
+
end
|
|
669
|
+
|
|
670
|
+
# Walks every page of refunds:list from +page+, item by item.
|
|
671
|
+
#
|
|
672
|
+
# @return [Enumerator<Refund>]
|
|
673
|
+
def list_iter(page: nil, limit: nil, payment_id: nil, api_key: nil, &block)
|
|
674
|
+
items = Page.iterate(page) do |at|
|
|
675
|
+
list(page: at, limit: limit, payment_id: payment_id, api_key: api_key)
|
|
676
|
+
end
|
|
677
|
+
block ? items.each(&block) : items
|
|
678
|
+
end
|
|
267
679
|
end
|
|
268
680
|
|
|
269
681
|
# The API's subscriptions.
|
|
@@ -272,7 +684,7 @@ module Perata
|
|
|
272
684
|
@client = client
|
|
273
685
|
end
|
|
274
686
|
|
|
275
|
-
#
|
|
687
|
+
# Cancelar uma assinatura, por padrão no fim do período.
|
|
276
688
|
#
|
|
277
689
|
# @param params [SubscriptionsCancelParams, Hash]
|
|
278
690
|
# @return [Subscription]
|
|
@@ -281,7 +693,7 @@ module Perata
|
|
|
281
693
|
Subscription.from_hash(data)
|
|
282
694
|
end
|
|
283
695
|
|
|
284
|
-
#
|
|
696
|
+
# Ler uma assinatura.
|
|
285
697
|
#
|
|
286
698
|
# @return [Subscription]
|
|
287
699
|
def get(subscription, api_key: nil)
|
|
@@ -289,7 +701,7 @@ module Perata
|
|
|
289
701
|
Subscription.from_hash(data)
|
|
290
702
|
end
|
|
291
703
|
|
|
292
|
-
#
|
|
704
|
+
# Listar assinaturas, opcionalmente de um cliente (customer_id). One page; +list_iter+ walks every page.
|
|
293
705
|
#
|
|
294
706
|
# @return [Page<Subscription>]
|
|
295
707
|
def list(page: nil, limit: nil, customer_id: nil, api_key: nil)
|
|
@@ -307,5 +719,93 @@ module Perata
|
|
|
307
719
|
end
|
|
308
720
|
block ? items.each(&block) : items
|
|
309
721
|
end
|
|
722
|
+
|
|
723
|
+
# Trocar o plano de uma assinatura: outro preço e, se quiser, outra quantidade, com a forma de ratear a diferença (proration_behavior).
|
|
724
|
+
#
|
|
725
|
+
# @param params [SubscriptionsUpdateParams, Hash]
|
|
726
|
+
# @return [Subscription]
|
|
727
|
+
def update(subscription, params, idempotency_key: nil, api_key: nil)
|
|
728
|
+
data = @client.request("PATCH", "/api/v1/subscriptions/#{Perata.segment(subscription)}", body: SubscriptionsUpdateParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
729
|
+
Subscription.from_hash(data)
|
|
730
|
+
end
|
|
731
|
+
end
|
|
732
|
+
|
|
733
|
+
# The API's webhooks.
|
|
734
|
+
class WebhooksService
|
|
735
|
+
def initialize(client)
|
|
736
|
+
@client = client
|
|
737
|
+
end
|
|
738
|
+
|
|
739
|
+
# Criar um endpoint de webhook; o segredo que assina as mensagens vem só nesta resposta.
|
|
740
|
+
#
|
|
741
|
+
# @param params [WebhooksCreateEndpointParams, Hash]
|
|
742
|
+
# @return [WebhookEndpointCreated]
|
|
743
|
+
def create_endpoint(params, idempotency_key: nil, api_key: nil)
|
|
744
|
+
data = @client.request("POST", "/api/v1/webhooks/endpoints", body: WebhooksCreateEndpointParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
745
|
+
WebhookEndpointCreated.from_hash(data)
|
|
746
|
+
end
|
|
747
|
+
|
|
748
|
+
# Excluir um endpoint de webhook; as entregas que ainda esperavam por ele falham. The API answers 204, so there is nothing to return.
|
|
749
|
+
#
|
|
750
|
+
# @return [nil]
|
|
751
|
+
def delete_endpoint(endpoint, idempotency_key: nil, api_key: nil)
|
|
752
|
+
@client.request("DELETE", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", idempotency_key: idempotency_key, api_key: api_key)
|
|
753
|
+
nil
|
|
754
|
+
end
|
|
755
|
+
|
|
756
|
+
# Ler um endpoint de webhook.
|
|
757
|
+
#
|
|
758
|
+
# @return [WebhookEndpoint]
|
|
759
|
+
def get_endpoint(endpoint, api_key: nil)
|
|
760
|
+
data = @client.request("GET", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", api_key: api_key)
|
|
761
|
+
WebhookEndpoint.from_hash(data)
|
|
762
|
+
end
|
|
763
|
+
|
|
764
|
+
# Listar as últimas 100 entregas de eventos aos endpoints, opcionalmente de um endpoint (endpoint_id) ou de uma situação (status). One page; +list_deliveries_iter+ walks every page.
|
|
765
|
+
#
|
|
766
|
+
# @return [Page<WebhookDelivery>]
|
|
767
|
+
def list_deliveries(page: nil, limit: nil, endpoint_id: nil, status: nil, api_key: nil)
|
|
768
|
+
query = { "page" => page, "limit" => limit, "endpoint_id" => endpoint_id, "status" => status }
|
|
769
|
+
data = @client.request("GET", "/api/v1/webhooks/deliveries", query: query, api_key: api_key)
|
|
770
|
+
Page.from_hash(data) { |item| WebhookDelivery.from_hash(item) }
|
|
771
|
+
end
|
|
772
|
+
|
|
773
|
+
# Walks every page of webhooks:list_deliveries from +page+, item by item.
|
|
774
|
+
#
|
|
775
|
+
# @return [Enumerator<WebhookDelivery>]
|
|
776
|
+
def list_deliveries_iter(page: nil, limit: nil, endpoint_id: nil, status: nil, api_key: nil, &block)
|
|
777
|
+
items = Page.iterate(page) do |at|
|
|
778
|
+
list_deliveries(page: at, limit: limit, endpoint_id: endpoint_id, status: status, api_key: api_key)
|
|
779
|
+
end
|
|
780
|
+
block ? items.each(&block) : items
|
|
781
|
+
end
|
|
782
|
+
|
|
783
|
+
# Listar os endpoints de webhook do lojista. One page; +list_endpoints_iter+ walks every page.
|
|
784
|
+
#
|
|
785
|
+
# @return [Page<WebhookEndpoint>]
|
|
786
|
+
def list_endpoints(page: nil, limit: nil, api_key: nil)
|
|
787
|
+
query = { "page" => page, "limit" => limit }
|
|
788
|
+
data = @client.request("GET", "/api/v1/webhooks/endpoints", query: query, api_key: api_key)
|
|
789
|
+
Page.from_hash(data) { |item| WebhookEndpoint.from_hash(item) }
|
|
790
|
+
end
|
|
791
|
+
|
|
792
|
+
# Walks every page of webhooks:list_endpoints from +page+, item by item.
|
|
793
|
+
#
|
|
794
|
+
# @return [Enumerator<WebhookEndpoint>]
|
|
795
|
+
def list_endpoints_iter(page: nil, limit: nil, api_key: nil, &block)
|
|
796
|
+
items = Page.iterate(page) do |at|
|
|
797
|
+
list_endpoints(page: at, limit: limit, api_key: api_key)
|
|
798
|
+
end
|
|
799
|
+
block ? items.each(&block) : items
|
|
800
|
+
end
|
|
801
|
+
|
|
802
|
+
# Atualizar o endereço, o formato, os eventos ou a descrição de um endpoint, ou ligar e desligar o envio (enabled); o segredo não muda.
|
|
803
|
+
#
|
|
804
|
+
# @param params [WebhooksUpdateEndpointParams, Hash]
|
|
805
|
+
# @return [WebhookEndpoint]
|
|
806
|
+
def update_endpoint(endpoint, params, idempotency_key: nil, api_key: nil)
|
|
807
|
+
data = @client.request("PATCH", "/api/v1/webhooks/endpoints/#{Perata.segment(endpoint)}", body: WebhooksUpdateEndpointParams.coerce(params).to_wire, idempotency_key: idempotency_key, api_key: api_key)
|
|
808
|
+
WebhookEndpoint.from_hash(data)
|
|
809
|
+
end
|
|
310
810
|
end
|
|
311
811
|
end
|