perata-sdk 0.2.0 → 0.4.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.
data/lib/perata/models.rb CHANGED
@@ -3,14 +3,86 @@
3
3
  # Code generated by sdk/generator. DO NOT EDIT.
4
4
 
5
5
  module Perata
6
+ # Benefit is a resource of Peráta's API.
7
+ class Benefit < Model
8
+ MEMBERS = %i[created_at description id metadata modified_at name properties status type visibility].freeze
9
+
10
+ # @return [String]
11
+ attr_reader :created_at
12
+
13
+ # @return [String]
14
+ attr_reader :description
15
+
16
+ # @return [String]
17
+ attr_reader :id
18
+
19
+ # Metadados do lojista: pares chave e valor (texto, número ou booleano); no tipo feature_flag, os valores da flag.
20
+ # @return [Hash{String => Object}]
21
+ attr_reader :metadata
22
+
23
+ # @return [String]
24
+ attr_reader :modified_at
25
+
26
+ # Como o benefício aparece nos produtos e para o cliente.
27
+ # @return [String]
28
+ attr_reader :name
29
+
30
+ # Os campos do tipo do benefício.
31
+ # @return [Hash{String => Object}]
32
+ attr_reader :properties
33
+
34
+ # @return [String ("active", "archived")]
35
+ attr_reader :status
36
+
37
+ # @return [String ("custom", "license_key", "downloadable", "feature_flag", "meter_credit", "discord", "github_repository")]
38
+ attr_reader :type
39
+
40
+ # @return [String ("public", "private")]
41
+ attr_reader :visibility
42
+
43
+ def initialize(created_at:, description:, id:, metadata:, modified_at:, name:, properties:, status:, type:, visibility:)
44
+ @created_at = created_at
45
+ @description = description
46
+ @id = id
47
+ @metadata = metadata
48
+ @modified_at = modified_at
49
+ @name = name
50
+ @properties = properties
51
+ @status = status
52
+ @type = type
53
+ @visibility = visibility
54
+ freeze
55
+ end
56
+
57
+ # Builds a Benefit from the API's JSON.
58
+ def self.from_hash(data)
59
+ new(
60
+ created_at: data.fetch("created_at"),
61
+ description: data.fetch("description"),
62
+ id: data.fetch("id"),
63
+ metadata: data.fetch("metadata"),
64
+ modified_at: data.fetch("modified_at"),
65
+ name: data.fetch("name"),
66
+ properties: data.fetch("properties"),
67
+ status: data.fetch("status"),
68
+ type: data.fetch("type"),
69
+ visibility: data.fetch("visibility")
70
+ )
71
+ end
72
+ end
73
+
6
74
  # BenefitGrant is a resource of Peráta's API.
7
75
  class BenefitGrant < Model
8
- MEMBERS = %i[benefit_id benefit_type created_at customer_id granted_at id is_granted is_revoked revoked_at status].freeze
76
+ MEMBERS = %i[benefit_id benefit_metadata benefit_type created_at customer_id granted_at id is_granted is_revoked properties revoked_at status].freeze
9
77
 
10
78
  # @return [String]
11
79
  attr_reader :benefit_id
12
80
 
13
- # @return [String]
81
+ # Os metadados do benefício: os valores de uma feature flag.
82
+ # @return [Hash{String => Object}]
83
+ attr_reader :benefit_metadata
84
+
85
+ # @return [String ("custom", "license_key", "downloadable", "feature_flag", "meter_credit", "discord", "github_repository")]
14
86
  attr_reader :benefit_type
15
87
 
16
88
  # @return [String]
@@ -31,14 +103,19 @@ module Perata
31
103
  # @return [Boolean]
32
104
  attr_reader :is_revoked
33
105
 
106
+ # O que a concessão informa, conforme o tipo, sem credenciais.
107
+ # @return [Hash{String => Object}]
108
+ attr_reader :properties
109
+
34
110
  # @return [String, nil]
35
111
  attr_reader :revoked_at
36
112
 
37
113
  # @return [String ("granted", "revoked")]
38
114
  attr_reader :status
39
115
 
40
- def initialize(benefit_id:, benefit_type:, created_at:, customer_id:, granted_at:, id:, is_granted:, is_revoked:, revoked_at:, status:)
116
+ def initialize(benefit_id:, benefit_metadata:, benefit_type:, created_at:, customer_id:, granted_at:, id:, is_granted:, is_revoked:, properties:, revoked_at:, status:)
41
117
  @benefit_id = benefit_id
118
+ @benefit_metadata = benefit_metadata
42
119
  @benefit_type = benefit_type
43
120
  @created_at = created_at
44
121
  @customer_id = customer_id
@@ -46,6 +123,7 @@ module Perata
46
123
  @id = id
47
124
  @is_granted = is_granted
48
125
  @is_revoked = is_revoked
126
+ @properties = properties
49
127
  @revoked_at = revoked_at
50
128
  @status = status
51
129
  freeze
@@ -55,6 +133,7 @@ module Perata
55
133
  def self.from_hash(data)
56
134
  new(
57
135
  benefit_id: data.fetch("benefit_id"),
136
+ benefit_metadata: data.fetch("benefit_metadata"),
58
137
  benefit_type: data.fetch("benefit_type"),
59
138
  created_at: data.fetch("created_at"),
60
139
  customer_id: data.fetch("customer_id"),
@@ -62,12 +141,66 @@ module Perata
62
141
  id: data.fetch("id"),
63
142
  is_granted: data.fetch("is_granted"),
64
143
  is_revoked: data.fetch("is_revoked"),
144
+ properties: data.fetch("properties"),
65
145
  revoked_at: data["revoked_at"],
66
146
  status: data.fetch("status")
67
147
  )
68
148
  end
69
149
  end
70
150
 
151
+ # BillingAddress is a resource of Peráta's API.
152
+ class BillingAddress < Model
153
+ MEMBERS = %i[city country district line1 line2 postal_code state].freeze
154
+
155
+ # @return [String]
156
+ attr_reader :city
157
+
158
+ # @return [String]
159
+ attr_reader :country
160
+
161
+ # Bairro.
162
+ # @return [String]
163
+ attr_reader :district
164
+
165
+ # @return [String]
166
+ attr_reader :line1
167
+
168
+ # @return [String]
169
+ attr_reader :line2
170
+
171
+ # CEP, só dígitos.
172
+ # @return [String]
173
+ attr_reader :postal_code
174
+
175
+ # UF.
176
+ # @return [String]
177
+ attr_reader :state
178
+
179
+ def initialize(city:, country:, district:, line1:, line2:, postal_code:, state:)
180
+ @city = city
181
+ @country = country
182
+ @district = district
183
+ @line1 = line1
184
+ @line2 = line2
185
+ @postal_code = postal_code
186
+ @state = state
187
+ freeze
188
+ end
189
+
190
+ # Builds a BillingAddress from the API's JSON.
191
+ def self.from_hash(data)
192
+ new(
193
+ city: data.fetch("city"),
194
+ country: data.fetch("country"),
195
+ district: data.fetch("district"),
196
+ line1: data.fetch("line1"),
197
+ line2: data.fetch("line2"),
198
+ postal_code: data.fetch("postal_code"),
199
+ state: data.fetch("state")
200
+ )
201
+ end
202
+ end
203
+
71
204
  # Card is a resource of Peráta's API.
72
205
  class Card < Model
73
206
  MEMBERS = %i[brand exp_month exp_year last4].freeze
@@ -105,25 +238,58 @@ module Perata
105
238
 
106
239
  # Checkout is a resource of Peráta's API.
107
240
  class Checkout < Model
108
- MEMBERS = %i[id price_id product_id url].freeze
241
+ MEMBERS = %i[cancel_url created_at expires_at id label price_id product_id quantity status success_url url].freeze
242
+
243
+ # Endereço https para onde o comprador volta se desistir; vazio sem ele.
244
+ # @return [String]
245
+ attr_reader :cancel_url
246
+
247
+ # @return [String]
248
+ attr_reader :created_at
249
+
250
+ # Quando o checkout deixa de abrir sessões; nulo sem prazo.
251
+ # @return [String, nil]
252
+ attr_reader :expires_at
109
253
 
110
254
  # @return [String]
111
255
  attr_reader :id
112
256
 
257
+ # Como o lojista chama o checkout nas próprias telas; o comprador não vê.
258
+ # @return [String]
259
+ attr_reader :label
260
+
113
261
  # @return [String]
114
262
  attr_reader :price_id
115
263
 
116
264
  # @return [String]
117
265
  attr_reader :product_id
118
266
 
267
+ # @return [Integer]
268
+ attr_reader :quantity
269
+
270
+ # active abre sessões de compra; archived saiu de circulação.
271
+ # @return [String ("active", "archived")]
272
+ attr_reader :status
273
+
274
+ # Endereço https para onde o comprador volta depois de pagar; vazio sem ele.
275
+ # @return [String]
276
+ attr_reader :success_url
277
+
119
278
  # Endereço para onde o comprador é enviado.
120
279
  # @return [String]
121
280
  attr_reader :url
122
281
 
123
- def initialize(id:, price_id:, product_id:, url:)
282
+ def initialize(cancel_url:, created_at:, expires_at:, id:, label:, price_id:, product_id:, quantity:, status:, success_url:, url:)
283
+ @cancel_url = cancel_url
284
+ @created_at = created_at
285
+ @expires_at = expires_at
124
286
  @id = id
287
+ @label = label
125
288
  @price_id = price_id
126
289
  @product_id = product_id
290
+ @quantity = quantity
291
+ @status = status
292
+ @success_url = success_url
127
293
  @url = url
128
294
  freeze
129
295
  end
@@ -131,14 +297,180 @@ module Perata
131
297
  # Builds a Checkout from the API's JSON.
132
298
  def self.from_hash(data)
133
299
  new(
300
+ cancel_url: data.fetch("cancel_url"),
301
+ created_at: data.fetch("created_at"),
302
+ expires_at: data["expires_at"],
303
+ id: data.fetch("id"),
304
+ label: data.fetch("label"),
305
+ price_id: data.fetch("price_id"),
306
+ product_id: data.fetch("product_id"),
307
+ quantity: data.fetch("quantity"),
308
+ status: data.fetch("status"),
309
+ success_url: data.fetch("success_url"),
310
+ url: data.fetch("url")
311
+ )
312
+ end
313
+ end
314
+
315
+ # CheckoutLink is a resource of Peráta's API.
316
+ class CheckoutLink < Model
317
+ MEMBERS = %i[allow_discount_codes cancel_url capture_mode created_at discount_id expires_at id label max_installments metadata modified_at price_id product_id products quantity require_billing_address status success_url trial_interval trial_interval_count url].freeze
318
+
319
+ # Se o comprador pode digitar um código de desconto.
320
+ # @return [Boolean]
321
+ attr_reader :allow_discount_codes
322
+
323
+ # Endereço https para onde o comprador volta se desistir; vazio sem ele.
324
+ # @return [String]
325
+ attr_reader :cancel_url
326
+
327
+ # manual segura a venda no cartão para o lojista capturar depois.
328
+ # @return [String ("automatic", "manual")]
329
+ attr_reader :capture_mode
330
+
331
+ # @return [String]
332
+ attr_reader :created_at
333
+
334
+ # O desconto fixado no link; nulo sem ele.
335
+ # @return [String, nil]
336
+ attr_reader :discount_id
337
+
338
+ # Quando o link deixa de abrir checkouts; nulo sem prazo.
339
+ # @return [String, nil]
340
+ attr_reader :expires_at
341
+
342
+ # @return [String]
343
+ attr_reader :id
344
+
345
+ # Como o lojista chama o link nas próprias telas; o comprador não vê.
346
+ # @return [String]
347
+ attr_reader :label
348
+
349
+ # O máximo de parcelas no cartão de crédito; 0 segue o que a organização definiu.
350
+ # @return [Integer]
351
+ attr_reader :max_installments
352
+
353
+ # Metadados do lojista: pares chave e valor (texto, número ou booleano); objeto vazio quando não há.
354
+ # @return [Hash{String => Object}]
355
+ attr_reader :metadata
356
+
357
+ # @return [String]
358
+ attr_reader :modified_at
359
+
360
+ # O preço do primeiro produto.
361
+ # @return [String]
362
+ attr_reader :price_id
363
+
364
+ # O primeiro produto do link.
365
+ # @return [String]
366
+ attr_reader :product_id
367
+
368
+ # Os produtos que o link vende, na ordem em que o comprador os vê.
369
+ # @return [Array<CheckoutLinkProduct>]
370
+ attr_reader :products
371
+
372
+ # @return [Integer]
373
+ attr_reader :quantity
374
+
375
+ # @return [Boolean]
376
+ attr_reader :require_billing_address
377
+
378
+ # @return [String ("active", "archived")]
379
+ attr_reader :status
380
+
381
+ # Endereço https para onde o comprador volta depois de pagar; vazio sem ele.
382
+ # @return [String]
383
+ attr_reader :success_url
384
+
385
+ # O período de teste gratuito do link, no lugar do produto; nulo mantém o do produto.
386
+ # @return [String ("day", "week", "month", "year"), nil]
387
+ attr_reader :trial_interval
388
+
389
+ # @return [Integer, nil]
390
+ attr_reader :trial_interval_count
391
+
392
+ # Endereço para onde o comprador é enviado.
393
+ # @return [String]
394
+ attr_reader :url
395
+
396
+ def initialize(allow_discount_codes:, cancel_url:, capture_mode:, created_at:, discount_id:, expires_at:, id:, label:, max_installments:, metadata:, modified_at:, price_id:, product_id:, products:, quantity:, require_billing_address:, status:, success_url:, trial_interval:, trial_interval_count:, url:)
397
+ @allow_discount_codes = allow_discount_codes
398
+ @cancel_url = cancel_url
399
+ @capture_mode = capture_mode
400
+ @created_at = created_at
401
+ @discount_id = discount_id
402
+ @expires_at = expires_at
403
+ @id = id
404
+ @label = label
405
+ @max_installments = max_installments
406
+ @metadata = metadata
407
+ @modified_at = modified_at
408
+ @price_id = price_id
409
+ @product_id = product_id
410
+ @products = products
411
+ @quantity = quantity
412
+ @require_billing_address = require_billing_address
413
+ @status = status
414
+ @success_url = success_url
415
+ @trial_interval = trial_interval
416
+ @trial_interval_count = trial_interval_count
417
+ @url = url
418
+ freeze
419
+ end
420
+
421
+ # Builds a CheckoutLink from the API's JSON.
422
+ def self.from_hash(data)
423
+ new(
424
+ allow_discount_codes: data.fetch("allow_discount_codes"),
425
+ cancel_url: data.fetch("cancel_url"),
426
+ capture_mode: data.fetch("capture_mode"),
427
+ created_at: data.fetch("created_at"),
428
+ discount_id: data["discount_id"],
429
+ expires_at: data["expires_at"],
134
430
  id: data.fetch("id"),
431
+ label: data.fetch("label"),
432
+ max_installments: data.fetch("max_installments"),
433
+ metadata: data.fetch("metadata"),
434
+ modified_at: data.fetch("modified_at"),
135
435
  price_id: data.fetch("price_id"),
136
436
  product_id: data.fetch("product_id"),
437
+ products: data.fetch("products").map { |item| CheckoutLinkProduct.from_hash(item) },
438
+ quantity: data.fetch("quantity"),
439
+ require_billing_address: data.fetch("require_billing_address"),
440
+ status: data.fetch("status"),
441
+ success_url: data.fetch("success_url"),
442
+ trial_interval: data["trial_interval"],
443
+ trial_interval_count: data["trial_interval_count"],
137
444
  url: data.fetch("url")
138
445
  )
139
446
  end
140
447
  end
141
448
 
449
+ # CheckoutLinkProduct is a resource of Peráta's API.
450
+ class CheckoutLinkProduct < Model
451
+ MEMBERS = %i[price_id product_id].freeze
452
+
453
+ # @return [String]
454
+ attr_reader :price_id
455
+
456
+ # @return [String]
457
+ attr_reader :product_id
458
+
459
+ def initialize(price_id:, product_id:)
460
+ @price_id = price_id
461
+ @product_id = product_id
462
+ freeze
463
+ end
464
+
465
+ # Builds a CheckoutLinkProduct from the API's JSON.
466
+ def self.from_hash(data)
467
+ new(
468
+ price_id: data.fetch("price_id"),
469
+ product_id: data.fetch("product_id")
470
+ )
471
+ end
472
+ end
473
+
142
474
  # Customer is a resource of Peráta's API.
143
475
  class Customer < Model
144
476
  MEMBERS = %i[created_at email external_id id name status].freeze
@@ -216,92 +548,785 @@ module Perata
216
548
  end
217
549
  end
218
550
 
219
- # Order is a resource of Peráta's API.
220
- class Order < Model
221
- MEMBERS = %i[amount_cents currency customer_id id installment_interest_cents installments paid_at price_id product_id status].freeze
222
-
223
- # @return [Integer]
224
- attr_reader :amount_cents
551
+ # CustomerState is a resource of Peráta's API.
552
+ class CustomerState < Model
553
+ MEMBERS = %i[active_subscriptions created_at email external_id granted_benefits id name status].freeze
225
554
 
226
- # @return [String ("BRL")]
227
- attr_reader :currency
555
+ # As assinaturas ativas ou em teste do cliente.
556
+ # @return [Array<Subscription>]
557
+ attr_reader :active_subscriptions
228
558
 
229
559
  # @return [String]
230
- attr_reader :customer_id
560
+ attr_reader :created_at
231
561
 
232
562
  # @return [String]
233
- attr_reader :id
234
-
235
- # Juros do parcelamento pagos pelo comprador, cobrados além de amount_cents.
236
- # @return [Integer]
237
- attr_reader :installment_interest_cents
563
+ attr_reader :email
238
564
 
239
- # Em quantas parcelas o cartão de crédito foi cobrado; 1 à vista.
240
- # @return [Integer]
241
- attr_reader :installments
565
+ # @return [String]
566
+ attr_reader :external_id
242
567
 
243
- # @return [String, nil]
244
- attr_reader :paid_at
568
+ # Os benefícios que o cliente tem agora.
569
+ # @return [Array<CustomerStateBenefitGrant>]
570
+ attr_reader :granted_benefits
245
571
 
246
572
  # @return [String]
247
- attr_reader :price_id
573
+ attr_reader :id
248
574
 
249
575
  # @return [String]
250
- attr_reader :product_id
576
+ attr_reader :name
251
577
 
252
- # @return [String ("open", "confirmed", "succeeded", "failed", "expired")]
578
+ # @return [String ("active", "archived")]
253
579
  attr_reader :status
254
580
 
255
- def initialize(amount_cents:, currency:, customer_id:, id:, installment_interest_cents:, installments:, paid_at:, price_id:, product_id:, status:)
256
- @amount_cents = amount_cents
257
- @currency = currency
258
- @customer_id = customer_id
581
+ def initialize(active_subscriptions:, created_at:, email:, external_id:, granted_benefits:, id:, name:, status:)
582
+ @active_subscriptions = active_subscriptions
583
+ @created_at = created_at
584
+ @email = email
585
+ @external_id = external_id
586
+ @granted_benefits = granted_benefits
259
587
  @id = id
260
- @installment_interest_cents = installment_interest_cents
261
- @installments = installments
262
- @paid_at = paid_at
263
- @price_id = price_id
264
- @product_id = product_id
588
+ @name = name
265
589
  @status = status
266
590
  freeze
267
591
  end
268
592
 
269
- # Builds a Order from the API's JSON.
593
+ # Builds a CustomerState from the API's JSON.
270
594
  def self.from_hash(data)
271
595
  new(
272
- amount_cents: data.fetch("amount_cents"),
273
- currency: data.fetch("currency"),
274
- customer_id: data.fetch("customer_id"),
596
+ active_subscriptions: data.fetch("active_subscriptions").map { |item| Subscription.from_hash(item) },
597
+ created_at: data.fetch("created_at"),
598
+ email: data.fetch("email"),
599
+ external_id: data.fetch("external_id"),
600
+ granted_benefits: data.fetch("granted_benefits").map { |item| CustomerStateBenefitGrant.from_hash(item) },
275
601
  id: data.fetch("id"),
276
- installment_interest_cents: data.fetch("installment_interest_cents"),
277
- installments: data.fetch("installments"),
278
- paid_at: data["paid_at"],
279
- price_id: data.fetch("price_id"),
280
- product_id: data.fetch("product_id"),
602
+ name: data.fetch("name"),
281
603
  status: data.fetch("status")
282
604
  )
283
605
  end
284
606
  end
285
607
 
286
- # Pagination is a resource of Peráta's API.
287
- class Pagination < Model
288
- MEMBERS = %i[max_page total_count].freeze
608
+ # CustomerStateBenefitGrant is a resource of Peráta's API.
609
+ class CustomerStateBenefitGrant < Model
610
+ MEMBERS = %i[benefit_id benefit_metadata benefit_type granted_at id properties].freeze
289
611
 
290
- # @return [Integer]
291
- attr_reader :max_page
612
+ # @return [String]
613
+ attr_reader :benefit_id
292
614
 
293
- # @return [Integer]
294
- attr_reader :total_count
615
+ # Os metadados do benefício: os valores de uma feature flag.
616
+ # @return [Hash{String => Object}]
617
+ attr_reader :benefit_metadata
295
618
 
296
- def initialize(max_page:, total_count:)
297
- @max_page = max_page
298
- @total_count = total_count
299
- freeze
300
- end
619
+ # @return [String ("custom", "license_key", "downloadable", "feature_flag", "meter_credit", "discord", "github_repository")]
620
+ attr_reader :benefit_type
301
621
 
302
- # Builds a Pagination from the API's JSON.
303
- def self.from_hash(data)
304
- new(
622
+ # @return [String]
623
+ attr_reader :granted_at
624
+
625
+ # A concessão.
626
+ # @return [String]
627
+ attr_reader :id
628
+
629
+ # O que a concessão informa, conforme o tipo.
630
+ # @return [Hash{String => Object}]
631
+ attr_reader :properties
632
+
633
+ def initialize(benefit_id:, benefit_metadata:, benefit_type:, granted_at:, id:, properties:)
634
+ @benefit_id = benefit_id
635
+ @benefit_metadata = benefit_metadata
636
+ @benefit_type = benefit_type
637
+ @granted_at = granted_at
638
+ @id = id
639
+ @properties = properties
640
+ freeze
641
+ end
642
+
643
+ # Builds a CustomerStateBenefitGrant from the API's JSON.
644
+ def self.from_hash(data)
645
+ new(
646
+ benefit_id: data.fetch("benefit_id"),
647
+ benefit_metadata: data.fetch("benefit_metadata"),
648
+ benefit_type: data.fetch("benefit_type"),
649
+ granted_at: data.fetch("granted_at"),
650
+ id: data.fetch("id"),
651
+ properties: data.fetch("properties")
652
+ )
653
+ end
654
+ end
655
+
656
+ # Discount is a resource of Peráta's API.
657
+ class Discount < Model
658
+ MEMBERS = %i[amount_cents basis_points code created_at currency duration duration_in_months ends_at id max_redemptions max_redemptions_per_customer modified_at name product_ids redemptions_count starts_at status type].freeze
659
+
660
+ # O valor fixo em centavos; 0 em um desconto percentual.
661
+ # @return [Integer]
662
+ attr_reader :amount_cents
663
+
664
+ # O percentual em centésimos de ponto percentual, 10000 é 100%; 0 em um desconto fixo.
665
+ # @return [Integer]
666
+ attr_reader :basis_points
667
+
668
+ # O código que o cliente digita no checkout; nulo quando o desconto só se aplica por um link de checkout ou pela API.
669
+ # @return [String, nil]
670
+ attr_reader :code
671
+
672
+ # @return [String]
673
+ attr_reader :created_at
674
+
675
+ # @return [String ("BRL")]
676
+ attr_reader :currency
677
+
678
+ # Em uma assinatura: só na primeira fatura, por duration_in_months meses ou para sempre.
679
+ # @return [String ("once", "repeating", "forever")]
680
+ attr_reader :duration
681
+
682
+ # Os meses de um desconto repeating; 0 nos outros.
683
+ # @return [Integer]
684
+ attr_reader :duration_in_months
685
+
686
+ # Depois de quando deixa de valer; nulo sem fim.
687
+ # @return [String, nil]
688
+ attr_reader :ends_at
689
+
690
+ # @return [String]
691
+ attr_reader :id
692
+
693
+ # Quantas vezes o desconto pode ser usado no total; nulo sem limite.
694
+ # @return [Integer, nil]
695
+ attr_reader :max_redemptions
696
+
697
+ # Quantas vezes um mesmo cliente pode usá-lo, de 1 a 100; nulo sem limite.
698
+ # @return [Integer, nil]
699
+ attr_reader :max_redemptions_per_customer
700
+
701
+ # @return [String]
702
+ attr_reader :modified_at
703
+
704
+ # Mostrado ao cliente quando o desconto é aplicado.
705
+ # @return [String]
706
+ attr_reader :name
707
+
708
+ # Os produtos a que o desconto se aplica; vazio, todos os do catálogo.
709
+ # @return [Array<String>]
710
+ attr_reader :product_ids
711
+
712
+ # @return [Integer]
713
+ attr_reader :redemptions_count
714
+
715
+ # A partir de quando o desconto vale.
716
+ # @return [String]
717
+ attr_reader :starts_at
718
+
719
+ # @return [String ("active", "expired", "exhausted")]
720
+ attr_reader :status
721
+
722
+ # @return [String ("percentage", "fixed")]
723
+ attr_reader :type
724
+
725
+ def initialize(amount_cents:, basis_points:, code:, created_at:, currency:, duration:, duration_in_months:, ends_at:, id:, max_redemptions:, max_redemptions_per_customer:, modified_at:, name:, product_ids:, redemptions_count:, starts_at:, status:, type:)
726
+ @amount_cents = amount_cents
727
+ @basis_points = basis_points
728
+ @code = code
729
+ @created_at = created_at
730
+ @currency = currency
731
+ @duration = duration
732
+ @duration_in_months = duration_in_months
733
+ @ends_at = ends_at
734
+ @id = id
735
+ @max_redemptions = max_redemptions
736
+ @max_redemptions_per_customer = max_redemptions_per_customer
737
+ @modified_at = modified_at
738
+ @name = name
739
+ @product_ids = product_ids
740
+ @redemptions_count = redemptions_count
741
+ @starts_at = starts_at
742
+ @status = status
743
+ @type = type
744
+ freeze
745
+ end
746
+
747
+ # Builds a Discount from the API's JSON.
748
+ def self.from_hash(data)
749
+ new(
750
+ amount_cents: data.fetch("amount_cents"),
751
+ basis_points: data.fetch("basis_points"),
752
+ code: data["code"],
753
+ created_at: data.fetch("created_at"),
754
+ currency: data.fetch("currency"),
755
+ duration: data.fetch("duration"),
756
+ duration_in_months: data.fetch("duration_in_months"),
757
+ ends_at: data["ends_at"],
758
+ id: data.fetch("id"),
759
+ max_redemptions: data["max_redemptions"],
760
+ max_redemptions_per_customer: data["max_redemptions_per_customer"],
761
+ modified_at: data.fetch("modified_at"),
762
+ name: data.fetch("name"),
763
+ product_ids: data.fetch("product_ids"),
764
+ redemptions_count: data.fetch("redemptions_count"),
765
+ starts_at: data.fetch("starts_at"),
766
+ status: data.fetch("status"),
767
+ type: data.fetch("type")
768
+ )
769
+ end
770
+ end
771
+
772
+ # Dispute is a resource of Peráta's API.
773
+ class Dispute < Model
774
+ MEMBERS = %i[amount_cents currency customer_id decided_at due_by id invoice_id opened_at order_id payment_id provider_dispute_id provider_reason reason source status].freeze
775
+
776
+ # Valor contestado, em centavos.
777
+ # @return [Integer]
778
+ attr_reader :amount_cents
779
+
780
+ # @return [String ("BRL")]
781
+ attr_reader :currency
782
+
783
+ # @return [String, nil]
784
+ attr_reader :customer_id
785
+
786
+ # @return [String, nil]
787
+ attr_reader :decided_at
788
+
789
+ # Prazo da defesa.
790
+ # @return [String, nil]
791
+ attr_reader :due_by
792
+
793
+ # @return [String]
794
+ attr_reader :id
795
+
796
+ # @return [String, nil]
797
+ attr_reader :invoice_id
798
+
799
+ # @return [String]
800
+ attr_reader :opened_at
801
+
802
+ # O pedido que a venda contestada pagou; nulo quando não é de um checkout.
803
+ # @return [String, nil]
804
+ attr_reader :order_id
805
+
806
+ # O PaymentId da venda contestada na Cielo.
807
+ # @return [String]
808
+ attr_reader :payment_id
809
+
810
+ # O número do caso na Cielo.
811
+ # @return [String]
812
+ attr_reader :provider_dispute_id
813
+
814
+ # O motivo nas palavras da Cielo.
815
+ # @return [String]
816
+ attr_reader :provider_reason
817
+
818
+ # Motivo, do conjunto fechado; unknown quando a adquirente não informou.
819
+ # @return [String]
820
+ attr_reader :reason
821
+
822
+ # @return [String ("operator", "cielo_chargeback")]
823
+ attr_reader :source
824
+
825
+ # @return [String ("opened", "needs_evidence", "submitted", "under_review", "won", "lost", "closed")]
826
+ attr_reader :status
827
+
828
+ def initialize(amount_cents:, currency:, customer_id:, decided_at:, due_by:, id:, invoice_id:, opened_at:, order_id:, payment_id:, provider_dispute_id:, provider_reason:, reason:, source:, status:)
829
+ @amount_cents = amount_cents
830
+ @currency = currency
831
+ @customer_id = customer_id
832
+ @decided_at = decided_at
833
+ @due_by = due_by
834
+ @id = id
835
+ @invoice_id = invoice_id
836
+ @opened_at = opened_at
837
+ @order_id = order_id
838
+ @payment_id = payment_id
839
+ @provider_dispute_id = provider_dispute_id
840
+ @provider_reason = provider_reason
841
+ @reason = reason
842
+ @source = source
843
+ @status = status
844
+ freeze
845
+ end
846
+
847
+ # Builds a Dispute from the API's JSON.
848
+ def self.from_hash(data)
849
+ new(
850
+ amount_cents: data.fetch("amount_cents"),
851
+ currency: data.fetch("currency"),
852
+ customer_id: data["customer_id"],
853
+ decided_at: data["decided_at"],
854
+ due_by: data["due_by"],
855
+ id: data.fetch("id"),
856
+ invoice_id: data["invoice_id"],
857
+ opened_at: data.fetch("opened_at"),
858
+ order_id: data["order_id"],
859
+ payment_id: data.fetch("payment_id"),
860
+ provider_dispute_id: data.fetch("provider_dispute_id"),
861
+ provider_reason: data.fetch("provider_reason"),
862
+ reason: data.fetch("reason"),
863
+ source: data.fetch("source"),
864
+ status: data.fetch("status")
865
+ )
866
+ end
867
+ end
868
+
869
+ # Event is a resource of Peráta's API.
870
+ class Event < Model
871
+ MEMBERS = %i[cached_tokens cost_currency cost_micro_cents customer_id external_id id input_tokens llm_model llm_vendor name output_tokens parent_id received_at source_id timestamp].freeze
872
+
873
+ # @return [Integer]
874
+ attr_reader :cached_tokens
875
+
876
+ # @return [String]
877
+ attr_reader :cost_currency
878
+
879
+ # O custo da chamada em milionésimos de centavo.
880
+ # @return [Integer]
881
+ attr_reader :cost_micro_cents
882
+
883
+ # @return [String]
884
+ attr_reader :customer_id
885
+
886
+ # O identificador do evento no sistema da origem.
887
+ # @return [String]
888
+ attr_reader :external_id
889
+
890
+ # @return [String]
891
+ attr_reader :id
892
+
893
+ # @return [Integer]
894
+ attr_reader :input_tokens
895
+
896
+ # @return [String]
897
+ attr_reader :llm_model
898
+
899
+ # @return [String]
900
+ attr_reader :llm_vendor
901
+
902
+ # @return [String ("token_usage")]
903
+ attr_reader :name
904
+
905
+ # @return [Integer]
906
+ attr_reader :output_tokens
907
+
908
+ # O evento de que este é filho; nulo na raiz.
909
+ # @return [String, nil]
910
+ attr_reader :parent_id
911
+
912
+ # @return [String]
913
+ attr_reader :received_at
914
+
915
+ # A origem que enviou o evento.
916
+ # @return [String]
917
+ attr_reader :source_id
918
+
919
+ # Quando o evento aconteceu.
920
+ # @return [String]
921
+ attr_reader :timestamp
922
+
923
+ def initialize(cached_tokens:, cost_currency:, cost_micro_cents:, customer_id:, external_id:, id:, input_tokens:, llm_model:, llm_vendor:, name:, output_tokens:, parent_id:, received_at:, source_id:, timestamp:)
924
+ @cached_tokens = cached_tokens
925
+ @cost_currency = cost_currency
926
+ @cost_micro_cents = cost_micro_cents
927
+ @customer_id = customer_id
928
+ @external_id = external_id
929
+ @id = id
930
+ @input_tokens = input_tokens
931
+ @llm_model = llm_model
932
+ @llm_vendor = llm_vendor
933
+ @name = name
934
+ @output_tokens = output_tokens
935
+ @parent_id = parent_id
936
+ @received_at = received_at
937
+ @source_id = source_id
938
+ @timestamp = timestamp
939
+ freeze
940
+ end
941
+
942
+ # Builds a Event from the API's JSON.
943
+ def self.from_hash(data)
944
+ new(
945
+ cached_tokens: data.fetch("cached_tokens"),
946
+ cost_currency: data.fetch("cost_currency"),
947
+ cost_micro_cents: data.fetch("cost_micro_cents"),
948
+ customer_id: data.fetch("customer_id"),
949
+ external_id: data.fetch("external_id"),
950
+ id: data.fetch("id"),
951
+ input_tokens: data.fetch("input_tokens"),
952
+ llm_model: data.fetch("llm_model"),
953
+ llm_vendor: data.fetch("llm_vendor"),
954
+ name: data.fetch("name"),
955
+ output_tokens: data.fetch("output_tokens"),
956
+ parent_id: data["parent_id"],
957
+ received_at: data.fetch("received_at"),
958
+ source_id: data.fetch("source_id"),
959
+ timestamp: data.fetch("timestamp")
960
+ )
961
+ end
962
+ end
963
+
964
+ # Meter is a resource of Peráta's API.
965
+ class Meter < Model
966
+ MEMBERS = %i[aggregation archived_at created_at filter id modified_at name unit].freeze
967
+
968
+ # @return [MeterAggregation]
969
+ attr_reader :aggregation
970
+
971
+ # Quando o medidor foi arquivado; nulo se está ativo.
972
+ # @return [String, nil]
973
+ attr_reader :archived_at
974
+
975
+ # @return [String]
976
+ attr_reader :created_at
977
+
978
+ # Os eventos que o medidor conta: grupos de condições, em conjunction and ou or, sobre name, timestamp ou metadata.<chave>.
979
+ # @return [Hash{String => Object}]
980
+ attr_reader :filter
981
+
982
+ # @return [String]
983
+ attr_reader :id
984
+
985
+ # @return [String]
986
+ attr_reader :modified_at
987
+
988
+ # @return [String]
989
+ attr_reader :name
990
+
991
+ # @return [MeterUnit]
992
+ attr_reader :unit
993
+
994
+ def initialize(aggregation:, archived_at:, created_at:, filter:, id:, modified_at:, name:, unit:)
995
+ @aggregation = aggregation
996
+ @archived_at = archived_at
997
+ @created_at = created_at
998
+ @filter = filter
999
+ @id = id
1000
+ @modified_at = modified_at
1001
+ @name = name
1002
+ @unit = unit
1003
+ freeze
1004
+ end
1005
+
1006
+ # Builds a Meter from the API's JSON.
1007
+ def self.from_hash(data)
1008
+ new(
1009
+ aggregation: MeterAggregation.from_hash(data.fetch("aggregation")),
1010
+ archived_at: data["archived_at"],
1011
+ created_at: data.fetch("created_at"),
1012
+ filter: data.fetch("filter"),
1013
+ id: data.fetch("id"),
1014
+ modified_at: data.fetch("modified_at"),
1015
+ name: data.fetch("name"),
1016
+ unit: MeterUnit.from_hash(data.fetch("unit"))
1017
+ )
1018
+ end
1019
+ end
1020
+
1021
+ # MeterAggregation is a resource of Peráta's API.
1022
+ class MeterAggregation < Model
1023
+ MEMBERS = %i[func property].freeze
1024
+
1025
+ # @return [String ("count", "sum", "avg", "min", "max", "unique")]
1026
+ attr_reader :func
1027
+
1028
+ # A propriedade do evento que as funções, menos count, leem; vazia no count.
1029
+ # @return [String]
1030
+ attr_reader :property
1031
+
1032
+ def initialize(func:, property:)
1033
+ @func = func
1034
+ @property = property
1035
+ freeze
1036
+ end
1037
+
1038
+ # Builds a MeterAggregation from the API's JSON.
1039
+ def self.from_hash(data)
1040
+ new(
1041
+ func: data.fetch("func"),
1042
+ property: data.fetch("property")
1043
+ )
1044
+ end
1045
+ end
1046
+
1047
+ # MeterUnit is a resource of Peráta's API.
1048
+ class MeterUnit < Model
1049
+ MEMBERS = %i[label multiplier type].freeze
1050
+
1051
+ # @return [String]
1052
+ attr_reader :label
1053
+
1054
+ # Por quantas unidades o preço é mostrado.
1055
+ # @return [Integer]
1056
+ attr_reader :multiplier
1057
+
1058
+ # @return [String ("scalar", "token", "custom")]
1059
+ attr_reader :type
1060
+
1061
+ def initialize(label:, multiplier:, type:)
1062
+ @label = label
1063
+ @multiplier = multiplier
1064
+ @type = type
1065
+ freeze
1066
+ end
1067
+
1068
+ # Builds a MeterUnit from the API's JSON.
1069
+ def self.from_hash(data)
1070
+ new(
1071
+ label: data.fetch("label"),
1072
+ multiplier: data.fetch("multiplier"),
1073
+ type: data.fetch("type")
1074
+ )
1075
+ end
1076
+ end
1077
+
1078
+ # Order is a resource of Peráta's API.
1079
+ class Order < Model
1080
+ MEMBERS = %i[amount_cents currency customer_id id installment_interest_cents installments paid_at price_id product_id status].freeze
1081
+
1082
+ # @return [Integer]
1083
+ attr_reader :amount_cents
1084
+
1085
+ # @return [String ("BRL")]
1086
+ attr_reader :currency
1087
+
1088
+ # @return [String]
1089
+ attr_reader :customer_id
1090
+
1091
+ # @return [String]
1092
+ attr_reader :id
1093
+
1094
+ # Juros do parcelamento pagos pelo comprador, cobrados além de amount_cents.
1095
+ # @return [Integer]
1096
+ attr_reader :installment_interest_cents
1097
+
1098
+ # Em quantas parcelas o cartão de crédito foi cobrado; 1 à vista.
1099
+ # @return [Integer]
1100
+ attr_reader :installments
1101
+
1102
+ # @return [String, nil]
1103
+ attr_reader :paid_at
1104
+
1105
+ # @return [String]
1106
+ attr_reader :price_id
1107
+
1108
+ # @return [String]
1109
+ attr_reader :product_id
1110
+
1111
+ # @return [String ("open", "confirmed", "succeeded", "failed", "expired")]
1112
+ attr_reader :status
1113
+
1114
+ def initialize(amount_cents:, currency:, customer_id:, id:, installment_interest_cents:, installments:, paid_at:, price_id:, product_id:, status:)
1115
+ @amount_cents = amount_cents
1116
+ @currency = currency
1117
+ @customer_id = customer_id
1118
+ @id = id
1119
+ @installment_interest_cents = installment_interest_cents
1120
+ @installments = installments
1121
+ @paid_at = paid_at
1122
+ @price_id = price_id
1123
+ @product_id = product_id
1124
+ @status = status
1125
+ freeze
1126
+ end
1127
+
1128
+ # Builds a Order from the API's JSON.
1129
+ def self.from_hash(data)
1130
+ new(
1131
+ amount_cents: data.fetch("amount_cents"),
1132
+ currency: data.fetch("currency"),
1133
+ customer_id: data.fetch("customer_id"),
1134
+ id: data.fetch("id"),
1135
+ installment_interest_cents: data.fetch("installment_interest_cents"),
1136
+ installments: data.fetch("installments"),
1137
+ paid_at: data["paid_at"],
1138
+ price_id: data.fetch("price_id"),
1139
+ product_id: data.fetch("product_id"),
1140
+ status: data.fetch("status")
1141
+ )
1142
+ end
1143
+ end
1144
+
1145
+ # OrderInvoice is a resource of Peráta's API.
1146
+ class OrderInvoice < Model
1147
+ MEMBERS = %i[address amount_cents billing_name currency discount_cents generated_at number order_id product_name tax_id tax_id_kind total_cents].freeze
1148
+
1149
+ # @return [BillingAddress]
1150
+ attr_reader :address
1151
+
1152
+ # @return [Integer]
1153
+ attr_reader :amount_cents
1154
+
1155
+ # @return [String]
1156
+ attr_reader :billing_name
1157
+
1158
+ # @return [String ("BRL")]
1159
+ attr_reader :currency
1160
+
1161
+ # @return [Integer]
1162
+ attr_reader :discount_cents
1163
+
1164
+ # @return [String]
1165
+ attr_reader :generated_at
1166
+
1167
+ # Número da fatura, na série da organização (PREFIXO-0001).
1168
+ # @return [String]
1169
+ attr_reader :number
1170
+
1171
+ # @return [String]
1172
+ attr_reader :order_id
1173
+
1174
+ # @return [String]
1175
+ attr_reader :product_name
1176
+
1177
+ # CPF ou CNPJ, só dígitos.
1178
+ # @return [String]
1179
+ attr_reader :tax_id
1180
+
1181
+ # cpf ou cnpj; vazio sem documento.
1182
+ # @return [String]
1183
+ attr_reader :tax_id_kind
1184
+
1185
+ # @return [Integer]
1186
+ attr_reader :total_cents
1187
+
1188
+ def initialize(address:, amount_cents:, billing_name:, currency:, discount_cents:, generated_at:, number:, order_id:, product_name:, tax_id:, tax_id_kind:, total_cents:)
1189
+ @address = address
1190
+ @amount_cents = amount_cents
1191
+ @billing_name = billing_name
1192
+ @currency = currency
1193
+ @discount_cents = discount_cents
1194
+ @generated_at = generated_at
1195
+ @number = number
1196
+ @order_id = order_id
1197
+ @product_name = product_name
1198
+ @tax_id = tax_id
1199
+ @tax_id_kind = tax_id_kind
1200
+ @total_cents = total_cents
1201
+ freeze
1202
+ end
1203
+
1204
+ # Builds a OrderInvoice from the API's JSON.
1205
+ def self.from_hash(data)
1206
+ new(
1207
+ address: BillingAddress.from_hash(data.fetch("address")),
1208
+ amount_cents: data.fetch("amount_cents"),
1209
+ billing_name: data.fetch("billing_name"),
1210
+ currency: data.fetch("currency"),
1211
+ discount_cents: data.fetch("discount_cents"),
1212
+ generated_at: data.fetch("generated_at"),
1213
+ number: data.fetch("number"),
1214
+ order_id: data.fetch("order_id"),
1215
+ product_name: data.fetch("product_name"),
1216
+ tax_id: data.fetch("tax_id"),
1217
+ tax_id_kind: data.fetch("tax_id_kind"),
1218
+ total_cents: data.fetch("total_cents")
1219
+ )
1220
+ end
1221
+ end
1222
+
1223
+ # OrderReceipt is a resource of Peráta's API.
1224
+ class OrderReceipt < Model
1225
+ MEMBERS = %i[amount_cents currency customer_email customer_name discount_cents installment_interest_cents installments number order_id paid_at payment_method product_name refunded_cents total_cents].freeze
1226
+
1227
+ # @return [Integer]
1228
+ attr_reader :amount_cents
1229
+
1230
+ # @return [String ("BRL")]
1231
+ attr_reader :currency
1232
+
1233
+ # @return [String]
1234
+ attr_reader :customer_email
1235
+
1236
+ # @return [String]
1237
+ attr_reader :customer_name
1238
+
1239
+ # @return [Integer]
1240
+ attr_reader :discount_cents
1241
+
1242
+ # @return [Integer]
1243
+ attr_reader :installment_interest_cents
1244
+
1245
+ # Em quantas parcelas o cartão de crédito foi cobrado; 1 à vista.
1246
+ # @return [Integer]
1247
+ attr_reader :installments
1248
+
1249
+ # Número do pedido na série da organização; vazio antes de ter um.
1250
+ # @return [String]
1251
+ attr_reader :number
1252
+
1253
+ # @return [String]
1254
+ attr_reader :order_id
1255
+
1256
+ # @return [String, nil]
1257
+ attr_reader :paid_at
1258
+
1259
+ # card, pix ou boleto; vazio quando o pagamento não foi achado.
1260
+ # @return [String]
1261
+ attr_reader :payment_method
1262
+
1263
+ # @return [String]
1264
+ attr_reader :product_name
1265
+
1266
+ # @return [Integer]
1267
+ attr_reader :refunded_cents
1268
+
1269
+ # @return [Integer]
1270
+ attr_reader :total_cents
1271
+
1272
+ def initialize(amount_cents:, currency:, customer_email:, customer_name:, discount_cents:, installment_interest_cents:, installments:, number:, order_id:, paid_at:, payment_method:, product_name:, refunded_cents:, total_cents:)
1273
+ @amount_cents = amount_cents
1274
+ @currency = currency
1275
+ @customer_email = customer_email
1276
+ @customer_name = customer_name
1277
+ @discount_cents = discount_cents
1278
+ @installment_interest_cents = installment_interest_cents
1279
+ @installments = installments
1280
+ @number = number
1281
+ @order_id = order_id
1282
+ @paid_at = paid_at
1283
+ @payment_method = payment_method
1284
+ @product_name = product_name
1285
+ @refunded_cents = refunded_cents
1286
+ @total_cents = total_cents
1287
+ freeze
1288
+ end
1289
+
1290
+ # Builds a OrderReceipt from the API's JSON.
1291
+ def self.from_hash(data)
1292
+ new(
1293
+ amount_cents: data.fetch("amount_cents"),
1294
+ currency: data.fetch("currency"),
1295
+ customer_email: data.fetch("customer_email"),
1296
+ customer_name: data.fetch("customer_name"),
1297
+ discount_cents: data.fetch("discount_cents"),
1298
+ installment_interest_cents: data.fetch("installment_interest_cents"),
1299
+ installments: data.fetch("installments"),
1300
+ number: data.fetch("number"),
1301
+ order_id: data.fetch("order_id"),
1302
+ paid_at: data["paid_at"],
1303
+ payment_method: data.fetch("payment_method"),
1304
+ product_name: data.fetch("product_name"),
1305
+ refunded_cents: data.fetch("refunded_cents"),
1306
+ total_cents: data.fetch("total_cents")
1307
+ )
1308
+ end
1309
+ end
1310
+
1311
+ # Pagination is a resource of Peráta's API.
1312
+ class Pagination < Model
1313
+ MEMBERS = %i[max_page total_count].freeze
1314
+
1315
+ # @return [Integer]
1316
+ attr_reader :max_page
1317
+
1318
+ # @return [Integer]
1319
+ attr_reader :total_count
1320
+
1321
+ def initialize(max_page:, total_count:)
1322
+ @max_page = max_page
1323
+ @total_count = total_count
1324
+ freeze
1325
+ end
1326
+
1327
+ # Builds a Pagination from the API's JSON.
1328
+ def self.from_hash(data)
1329
+ new(
305
1330
  max_page: data.fetch("max_page"),
306
1331
  total_count: data.fetch("total_count")
307
1332
  )
@@ -526,204 +1551,488 @@ module Perata
526
1551
  # @return [String ("active", "archived")]
527
1552
  attr_reader :status
528
1553
 
529
- def initialize(created_at:, description:, id:, name:, status:)
1554
+ def initialize(created_at:, description:, id:, name:, status:)
1555
+ @created_at = created_at
1556
+ @description = description
1557
+ @id = id
1558
+ @name = name
1559
+ @status = status
1560
+ freeze
1561
+ end
1562
+
1563
+ # Builds a Product from the API's JSON.
1564
+ def self.from_hash(data)
1565
+ new(
1566
+ created_at: data.fetch("created_at"),
1567
+ description: data.fetch("description"),
1568
+ id: data.fetch("id"),
1569
+ name: data.fetch("name"),
1570
+ status: data.fetch("status")
1571
+ )
1572
+ end
1573
+ end
1574
+
1575
+ # Refund is a resource of Peráta's API.
1576
+ class Refund < Model
1577
+ MEMBERS = %i[amount_cents id payment_id status].freeze
1578
+
1579
+ # @return [Integer]
1580
+ attr_reader :amount_cents
1581
+
1582
+ # @return [String]
1583
+ attr_reader :id
1584
+
1585
+ # @return [String]
1586
+ attr_reader :payment_id
1587
+
1588
+ # @return [String ("requested", "pending", "unknown", "succeeded", "failed", "canceled")]
1589
+ attr_reader :status
1590
+
1591
+ def initialize(amount_cents:, id:, payment_id:, status:)
1592
+ @amount_cents = amount_cents
1593
+ @id = id
1594
+ @payment_id = payment_id
1595
+ @status = status
1596
+ freeze
1597
+ end
1598
+
1599
+ # Builds a Refund from the API's JSON.
1600
+ def self.from_hash(data)
1601
+ new(
1602
+ amount_cents: data.fetch("amount_cents"),
1603
+ id: data.fetch("id"),
1604
+ payment_id: data.fetch("payment_id"),
1605
+ status: data.fetch("status")
1606
+ )
1607
+ end
1608
+ end
1609
+
1610
+ # Subscription is a resource of Peráta's API.
1611
+ class Subscription < Model
1612
+ MEMBERS = %i[amount_cents cancel_at_period_end currency current_period_end current_period_start customer_id id interval metadata price_id product_id status trial_end trial_start].freeze
1613
+
1614
+ # @return [Integer]
1615
+ attr_reader :amount_cents
1616
+
1617
+ # @return [Boolean]
1618
+ attr_reader :cancel_at_period_end
1619
+
1620
+ # @return [String ("BRL")]
1621
+ attr_reader :currency
1622
+
1623
+ # @return [String]
1624
+ attr_reader :current_period_end
1625
+
1626
+ # @return [String]
1627
+ attr_reader :current_period_start
1628
+
1629
+ # @return [String]
1630
+ attr_reader :customer_id
1631
+
1632
+ # @return [String]
1633
+ attr_reader :id
1634
+
1635
+ # @return [String]
1636
+ attr_reader :interval
1637
+
1638
+ # Metadados do lojista: pares chave e valor (texto, número ou booleano); objeto vazio quando não há.
1639
+ # @return [Hash{String => Object}]
1640
+ attr_reader :metadata
1641
+
1642
+ # @return [String]
1643
+ attr_reader :price_id
1644
+
1645
+ # @return [String]
1646
+ attr_reader :product_id
1647
+
1648
+ # @return [String ("trialing", "active", "past_due", "paused", "canceled")]
1649
+ attr_reader :status
1650
+
1651
+ # @return [String, nil]
1652
+ attr_reader :trial_end
1653
+
1654
+ # @return [String, nil]
1655
+ attr_reader :trial_start
1656
+
1657
+ def initialize(amount_cents:, cancel_at_period_end:, currency:, current_period_end:, current_period_start:, customer_id:, id:, interval:, metadata:, price_id:, product_id:, status:, trial_end:, trial_start:)
1658
+ @amount_cents = amount_cents
1659
+ @cancel_at_period_end = cancel_at_period_end
1660
+ @currency = currency
1661
+ @current_period_end = current_period_end
1662
+ @current_period_start = current_period_start
1663
+ @customer_id = customer_id
1664
+ @id = id
1665
+ @interval = interval
1666
+ @metadata = metadata
1667
+ @price_id = price_id
1668
+ @product_id = product_id
1669
+ @status = status
1670
+ @trial_end = trial_end
1671
+ @trial_start = trial_start
1672
+ freeze
1673
+ end
1674
+
1675
+ # Builds a Subscription from the API's JSON.
1676
+ def self.from_hash(data)
1677
+ new(
1678
+ amount_cents: data.fetch("amount_cents"),
1679
+ cancel_at_period_end: data.fetch("cancel_at_period_end"),
1680
+ currency: data.fetch("currency"),
1681
+ current_period_end: data.fetch("current_period_end"),
1682
+ current_period_start: data.fetch("current_period_start"),
1683
+ customer_id: data.fetch("customer_id"),
1684
+ id: data.fetch("id"),
1685
+ interval: data.fetch("interval"),
1686
+ metadata: data.fetch("metadata"),
1687
+ price_id: data.fetch("price_id"),
1688
+ product_id: data.fetch("product_id"),
1689
+ status: data.fetch("status"),
1690
+ trial_end: data["trial_end"],
1691
+ trial_start: data["trial_start"]
1692
+ )
1693
+ end
1694
+ end
1695
+
1696
+ # UsageError is a resource of Peráta's API.
1697
+ class UsageError < Model
1698
+ MEMBERS = %i[error fields message record].freeze
1699
+
1700
+ # Código do erro: invalid_credential, invalid_request, conflict, unsupported_media_type, body_too_large, rate_limited ou unavailable.
1701
+ # @return [String]
1702
+ attr_reader :error
1703
+
1704
+ # Em invalid_request, o que há de errado em cada campo do evento.
1705
+ # @return [Hash{String => Array<String>}, nil]
1706
+ attr_reader :fields
1707
+
1708
+ # O que explica a recusa, em inglês.
1709
+ # @return [String, nil]
1710
+ attr_reader :message
1711
+
1712
+ # Posição, a partir de 1, do evento do lote que causou a recusa (invalid_request e conflict); o lote inteiro foi revertido.
1713
+ # @return [Integer, nil]
1714
+ attr_reader :record
1715
+
1716
+ def initialize(error:, fields: nil, message: nil, record: nil)
1717
+ @error = error
1718
+ @fields = fields
1719
+ @message = message
1720
+ @record = record
1721
+ freeze
1722
+ end
1723
+
1724
+ # Builds a UsageError from the API's JSON.
1725
+ def self.from_hash(data)
1726
+ new(
1727
+ error: data.fetch("error"),
1728
+ fields: data["fields"],
1729
+ message: data["message"],
1730
+ record: data["record"]
1731
+ )
1732
+ end
1733
+ end
1734
+
1735
+ # WebhookBenefit is a resource of Peráta's API.
1736
+ class WebhookBenefit < Model
1737
+ MEMBERS = %i[created_at description id modified_at name status type visibility].freeze
1738
+
1739
+ # @return [String]
1740
+ attr_reader :created_at
1741
+
1742
+ # @return [String]
1743
+ attr_reader :description
1744
+
1745
+ # @return [String]
1746
+ attr_reader :id
1747
+
1748
+ # @return [String]
1749
+ attr_reader :modified_at
1750
+
1751
+ # @return [String]
1752
+ attr_reader :name
1753
+
1754
+ # @return [String ("active", "archived")]
1755
+ attr_reader :status
1756
+
1757
+ # @return [String]
1758
+ attr_reader :type
1759
+
1760
+ # @return [String ("public", "private")]
1761
+ attr_reader :visibility
1762
+
1763
+ def initialize(created_at:, description:, id:, modified_at:, name:, status:, type:, visibility:)
530
1764
  @created_at = created_at
531
1765
  @description = description
532
1766
  @id = id
1767
+ @modified_at = modified_at
533
1768
  @name = name
534
1769
  @status = status
1770
+ @type = type
1771
+ @visibility = visibility
535
1772
  freeze
536
1773
  end
537
1774
 
538
- # Builds a Product from the API's JSON.
1775
+ # Builds a WebhookBenefit from the API's JSON.
539
1776
  def self.from_hash(data)
540
1777
  new(
541
1778
  created_at: data.fetch("created_at"),
542
1779
  description: data.fetch("description"),
543
1780
  id: data.fetch("id"),
1781
+ modified_at: data.fetch("modified_at"),
544
1782
  name: data.fetch("name"),
545
- status: data.fetch("status")
1783
+ status: data.fetch("status"),
1784
+ type: data.fetch("type"),
1785
+ visibility: data.fetch("visibility")
546
1786
  )
547
1787
  end
548
1788
  end
549
1789
 
550
- # Refund is a resource of Peráta's API.
551
- class Refund < Model
552
- MEMBERS = %i[amount_cents id payment_id status].freeze
1790
+ # WebhookCheckout is a resource of Peráta's API.
1791
+ class WebhookCheckout < Model
1792
+ MEMBERS = %i[amount_cents checkout_link_id created_at currency customer_id discount_cents expires_at id price_id product_id status total_cents].freeze
553
1793
 
554
1794
  # @return [Integer]
555
1795
  attr_reader :amount_cents
556
1796
 
1797
+ # @return [String, nil]
1798
+ attr_reader :checkout_link_id
1799
+
1800
+ # @return [String]
1801
+ attr_reader :created_at
1802
+
1803
+ # @return [String ("BRL")]
1804
+ attr_reader :currency
1805
+
1806
+ # Nulo até o comprador confirmar.
1807
+ # @return [String, nil]
1808
+ attr_reader :customer_id
1809
+
1810
+ # @return [Integer]
1811
+ attr_reader :discount_cents
1812
+
1813
+ # @return [String]
1814
+ attr_reader :expires_at
1815
+
557
1816
  # @return [String]
558
1817
  attr_reader :id
559
1818
 
560
1819
  # @return [String]
561
- attr_reader :payment_id
1820
+ attr_reader :price_id
562
1821
 
563
- # @return [String ("requested", "pending", "unknown", "succeeded", "failed", "canceled")]
1822
+ # @return [String]
1823
+ attr_reader :product_id
1824
+
1825
+ # @return [String ("open", "confirmed", "succeeded", "failed", "expired")]
564
1826
  attr_reader :status
565
1827
 
566
- def initialize(amount_cents:, id:, payment_id:, status:)
1828
+ # @return [Integer]
1829
+ attr_reader :total_cents
1830
+
1831
+ def initialize(amount_cents:, checkout_link_id:, created_at:, currency:, customer_id:, discount_cents:, expires_at:, id:, price_id:, product_id:, status:, total_cents:)
567
1832
  @amount_cents = amount_cents
1833
+ @checkout_link_id = checkout_link_id
1834
+ @created_at = created_at
1835
+ @currency = currency
1836
+ @customer_id = customer_id
1837
+ @discount_cents = discount_cents
1838
+ @expires_at = expires_at
568
1839
  @id = id
569
- @payment_id = payment_id
1840
+ @price_id = price_id
1841
+ @product_id = product_id
570
1842
  @status = status
1843
+ @total_cents = total_cents
571
1844
  freeze
572
1845
  end
573
1846
 
574
- # Builds a Refund from the API's JSON.
1847
+ # Builds a WebhookCheckout from the API's JSON.
575
1848
  def self.from_hash(data)
576
1849
  new(
577
1850
  amount_cents: data.fetch("amount_cents"),
1851
+ checkout_link_id: data["checkout_link_id"],
1852
+ created_at: data.fetch("created_at"),
1853
+ currency: data.fetch("currency"),
1854
+ customer_id: data["customer_id"],
1855
+ discount_cents: data.fetch("discount_cents"),
1856
+ expires_at: data.fetch("expires_at"),
578
1857
  id: data.fetch("id"),
579
- payment_id: data.fetch("payment_id"),
580
- status: data.fetch("status")
1858
+ price_id: data.fetch("price_id"),
1859
+ product_id: data.fetch("product_id"),
1860
+ status: data.fetch("status"),
1861
+ total_cents: data.fetch("total_cents")
581
1862
  )
582
1863
  end
583
1864
  end
584
1865
 
585
- # Subscription is a resource of Peráta's API.
586
- class Subscription < Model
587
- MEMBERS = %i[amount_cents cancel_at_period_end currency current_period_end current_period_start customer_id id interval price_id product_id status].freeze
1866
+ # WebhookDelivery is a resource of Peráta's API.
1867
+ class WebhookDelivery < Model
1868
+ MEMBERS = %i[attempts created_at endpoint_id event_id event_type id last_attempt_at last_error max_attempts next_attempt_at response_status status].freeze
588
1869
 
589
1870
  # @return [Integer]
590
- attr_reader :amount_cents
591
-
592
- # @return [Boolean]
593
- attr_reader :cancel_at_period_end
1871
+ attr_reader :attempts
594
1872
 
595
- # @return [String ("BRL")]
596
- attr_reader :currency
1873
+ # @return [String]
1874
+ attr_reader :created_at
597
1875
 
598
1876
  # @return [String]
599
- attr_reader :current_period_end
1877
+ attr_reader :endpoint_id
600
1878
 
601
1879
  # @return [String]
602
- attr_reader :current_period_start
1880
+ attr_reader :event_id
603
1881
 
604
1882
  # @return [String]
605
- attr_reader :customer_id
1883
+ attr_reader :event_type
606
1884
 
607
1885
  # @return [String]
608
1886
  attr_reader :id
609
1887
 
610
- # @return [String]
611
- attr_reader :interval
1888
+ # @return [String, nil]
1889
+ attr_reader :last_attempt_at
612
1890
 
613
1891
  # @return [String]
614
- attr_reader :price_id
1892
+ attr_reader :last_error
615
1893
 
616
- # @return [String]
617
- attr_reader :product_id
1894
+ # @return [Integer]
1895
+ attr_reader :max_attempts
618
1896
 
619
- # @return [String ("trialing", "active", "past_due", "paused", "canceled")]
1897
+ # @return [String, nil]
1898
+ attr_reader :next_attempt_at
1899
+
1900
+ # O status HTTP da última resposta; nulo quando não houve.
1901
+ # @return [Integer, nil]
1902
+ attr_reader :response_status
1903
+
1904
+ # pending enquanto é repetida; exhausted quando todas as tentativas falharam.
1905
+ # @return [String ("pending", "succeeded", "exhausted")]
620
1906
  attr_reader :status
621
1907
 
622
- def initialize(amount_cents:, cancel_at_period_end:, currency:, current_period_end:, current_period_start:, customer_id:, id:, interval:, price_id:, product_id:, status:)
623
- @amount_cents = amount_cents
624
- @cancel_at_period_end = cancel_at_period_end
625
- @currency = currency
626
- @current_period_end = current_period_end
627
- @current_period_start = current_period_start
628
- @customer_id = customer_id
1908
+ def initialize(attempts:, created_at:, endpoint_id:, event_id:, event_type:, id:, last_attempt_at:, last_error:, max_attempts:, next_attempt_at:, response_status:, status:)
1909
+ @attempts = attempts
1910
+ @created_at = created_at
1911
+ @endpoint_id = endpoint_id
1912
+ @event_id = event_id
1913
+ @event_type = event_type
629
1914
  @id = id
630
- @interval = interval
631
- @price_id = price_id
632
- @product_id = product_id
1915
+ @last_attempt_at = last_attempt_at
1916
+ @last_error = last_error
1917
+ @max_attempts = max_attempts
1918
+ @next_attempt_at = next_attempt_at
1919
+ @response_status = response_status
633
1920
  @status = status
634
1921
  freeze
635
1922
  end
636
1923
 
637
- # Builds a Subscription from the API's JSON.
1924
+ # Builds a WebhookDelivery from the API's JSON.
638
1925
  def self.from_hash(data)
639
1926
  new(
640
- amount_cents: data.fetch("amount_cents"),
641
- cancel_at_period_end: data.fetch("cancel_at_period_end"),
642
- currency: data.fetch("currency"),
643
- current_period_end: data.fetch("current_period_end"),
644
- current_period_start: data.fetch("current_period_start"),
645
- customer_id: data.fetch("customer_id"),
1927
+ attempts: data.fetch("attempts"),
1928
+ created_at: data.fetch("created_at"),
1929
+ endpoint_id: data.fetch("endpoint_id"),
1930
+ event_id: data.fetch("event_id"),
1931
+ event_type: data.fetch("event_type"),
646
1932
  id: data.fetch("id"),
647
- interval: data.fetch("interval"),
648
- price_id: data.fetch("price_id"),
649
- product_id: data.fetch("product_id"),
1933
+ last_attempt_at: data["last_attempt_at"],
1934
+ last_error: data.fetch("last_error"),
1935
+ max_attempts: data.fetch("max_attempts"),
1936
+ next_attempt_at: data["next_attempt_at"],
1937
+ response_status: data["response_status"],
650
1938
  status: data.fetch("status")
651
1939
  )
652
1940
  end
653
1941
  end
654
1942
 
655
- # WebhookCheckout is a resource of Peráta's API.
656
- class WebhookCheckout < Model
657
- MEMBERS = %i[amount_cents checkout_link_id created_at currency customer_id discount_cents expires_at id price_id product_id status total_cents].freeze
1943
+ # WebhookDiscount is a resource of Peráta's API.
1944
+ class WebhookDiscount < Model
1945
+ MEMBERS = %i[amount_cents basis_points code created_at currency duration duration_in_months ends_at id max_redemptions modified_at name redemptions_count starts_at status type].freeze
658
1946
 
1947
+ # Valor fixo em centavos, quando o tipo é fixed.
659
1948
  # @return [Integer]
660
1949
  attr_reader :amount_cents
661
1950
 
1951
+ # Percentual em pontos-base, quando o tipo é percentage.
1952
+ # @return [Integer]
1953
+ attr_reader :basis_points
1954
+
662
1955
  # @return [String, nil]
663
- attr_reader :checkout_link_id
1956
+ attr_reader :code
664
1957
 
665
1958
  # @return [String]
666
1959
  attr_reader :created_at
667
1960
 
668
- # @return [String ("BRL")]
1961
+ # @return [String]
669
1962
  attr_reader :currency
670
1963
 
671
- # Nulo até o comprador confirmar.
672
- # @return [String, nil]
673
- attr_reader :customer_id
1964
+ # @return [String ("once", "forever", "repeating")]
1965
+ attr_reader :duration
674
1966
 
675
1967
  # @return [Integer]
676
- attr_reader :discount_cents
1968
+ attr_reader :duration_in_months
677
1969
 
678
- # @return [String]
679
- attr_reader :expires_at
1970
+ # @return [String, nil]
1971
+ attr_reader :ends_at
680
1972
 
681
1973
  # @return [String]
682
1974
  attr_reader :id
683
1975
 
1976
+ # @return [Integer, nil]
1977
+ attr_reader :max_redemptions
1978
+
684
1979
  # @return [String]
685
- attr_reader :price_id
1980
+ attr_reader :modified_at
686
1981
 
687
1982
  # @return [String]
688
- attr_reader :product_id
1983
+ attr_reader :name
689
1984
 
690
- # @return [String ("open", "confirmed", "succeeded", "failed", "expired")]
1985
+ # @return [Integer]
1986
+ attr_reader :redemptions_count
1987
+
1988
+ # @return [String]
1989
+ attr_reader :starts_at
1990
+
1991
+ # @return [String ("active", "expired", "exhausted", "archived")]
691
1992
  attr_reader :status
692
1993
 
693
- # @return [Integer]
694
- attr_reader :total_cents
1994
+ # @return [String ("percentage", "fixed")]
1995
+ attr_reader :type
695
1996
 
696
- def initialize(amount_cents:, checkout_link_id:, created_at:, currency:, customer_id:, discount_cents:, expires_at:, id:, price_id:, product_id:, status:, total_cents:)
1997
+ def initialize(amount_cents:, basis_points:, code:, created_at:, currency:, duration:, duration_in_months:, ends_at:, id:, max_redemptions:, modified_at:, name:, redemptions_count:, starts_at:, status:, type:)
697
1998
  @amount_cents = amount_cents
698
- @checkout_link_id = checkout_link_id
1999
+ @basis_points = basis_points
2000
+ @code = code
699
2001
  @created_at = created_at
700
2002
  @currency = currency
701
- @customer_id = customer_id
702
- @discount_cents = discount_cents
703
- @expires_at = expires_at
2003
+ @duration = duration
2004
+ @duration_in_months = duration_in_months
2005
+ @ends_at = ends_at
704
2006
  @id = id
705
- @price_id = price_id
706
- @product_id = product_id
2007
+ @max_redemptions = max_redemptions
2008
+ @modified_at = modified_at
2009
+ @name = name
2010
+ @redemptions_count = redemptions_count
2011
+ @starts_at = starts_at
707
2012
  @status = status
708
- @total_cents = total_cents
2013
+ @type = type
709
2014
  freeze
710
2015
  end
711
2016
 
712
- # Builds a WebhookCheckout from the API's JSON.
2017
+ # Builds a WebhookDiscount from the API's JSON.
713
2018
  def self.from_hash(data)
714
2019
  new(
715
2020
  amount_cents: data.fetch("amount_cents"),
716
- checkout_link_id: data["checkout_link_id"],
2021
+ basis_points: data.fetch("basis_points"),
2022
+ code: data["code"],
717
2023
  created_at: data.fetch("created_at"),
718
2024
  currency: data.fetch("currency"),
719
- customer_id: data["customer_id"],
720
- discount_cents: data.fetch("discount_cents"),
721
- expires_at: data.fetch("expires_at"),
2025
+ duration: data.fetch("duration"),
2026
+ duration_in_months: data.fetch("duration_in_months"),
2027
+ ends_at: data["ends_at"],
722
2028
  id: data.fetch("id"),
723
- price_id: data.fetch("price_id"),
724
- product_id: data.fetch("product_id"),
2029
+ max_redemptions: data["max_redemptions"],
2030
+ modified_at: data.fetch("modified_at"),
2031
+ name: data.fetch("name"),
2032
+ redemptions_count: data.fetch("redemptions_count"),
2033
+ starts_at: data.fetch("starts_at"),
725
2034
  status: data.fetch("status"),
726
- total_cents: data.fetch("total_cents")
2035
+ type: data.fetch("type")
727
2036
  )
728
2037
  end
729
2038
  end
@@ -818,4 +2127,149 @@ module Perata
818
2127
  )
819
2128
  end
820
2129
  end
2130
+
2131
+ # WebhookEndpoint is a resource of Peráta's API.
2132
+ class WebhookEndpoint < Model
2133
+ MEMBERS = %i[consecutive_failures created_at description events format id status url].freeze
2134
+
2135
+ # @return [Integer]
2136
+ attr_reader :consecutive_failures
2137
+
2138
+ # @return [String]
2139
+ attr_reader :created_at
2140
+
2141
+ # Como o lojista chama o endpoint; sem ele, o domínio do endereço.
2142
+ # @return [String]
2143
+ attr_reader :description
2144
+
2145
+ # Os eventos de que o endpoint é avisado, em ordem alfabética.
2146
+ # @return [Array<String>]
2147
+ attr_reader :events
2148
+
2149
+ # O corpo da mensagem; o que o endereço indica quando não é dito.
2150
+ # @return [String ("raw", "discord", "slack")]
2151
+ attr_reader :format
2152
+
2153
+ # @return [String]
2154
+ attr_reader :id
2155
+
2156
+ # @return [String ("active", "disabled")]
2157
+ attr_reader :status
2158
+
2159
+ # Endereço https para onde as mensagens são enviadas.
2160
+ # @return [String]
2161
+ attr_reader :url
2162
+
2163
+ def initialize(consecutive_failures:, created_at:, description:, events:, format:, id:, status:, url:)
2164
+ @consecutive_failures = consecutive_failures
2165
+ @created_at = created_at
2166
+ @description = description
2167
+ @events = events
2168
+ @format = format
2169
+ @id = id
2170
+ @status = status
2171
+ @url = url
2172
+ freeze
2173
+ end
2174
+
2175
+ # Builds a WebhookEndpoint from the API's JSON.
2176
+ def self.from_hash(data)
2177
+ new(
2178
+ consecutive_failures: data.fetch("consecutive_failures"),
2179
+ created_at: data.fetch("created_at"),
2180
+ description: data.fetch("description"),
2181
+ events: data.fetch("events"),
2182
+ format: data.fetch("format"),
2183
+ id: data.fetch("id"),
2184
+ status: data.fetch("status"),
2185
+ url: data.fetch("url")
2186
+ )
2187
+ end
2188
+ end
2189
+
2190
+ # WebhookEndpointCreated is a resource of Peráta's API.
2191
+ class WebhookEndpointCreated < Model
2192
+ MEMBERS = %i[consecutive_failures created_at description events format id secret status url].freeze
2193
+
2194
+ # @return [Integer]
2195
+ attr_reader :consecutive_failures
2196
+
2197
+ # @return [String]
2198
+ attr_reader :created_at
2199
+
2200
+ # @return [String]
2201
+ attr_reader :description
2202
+
2203
+ # @return [Array<String>]
2204
+ attr_reader :events
2205
+
2206
+ # @return [String ("raw", "discord", "slack")]
2207
+ attr_reader :format
2208
+
2209
+ # @return [String]
2210
+ attr_reader :id
2211
+
2212
+ # O segredo (whsec_…) com que as mensagens são assinadas. Só esta resposta o traz; na repetição da criação sob a mesma Idempotency-Key vem vazio.
2213
+ # @return [String]
2214
+ attr_reader :secret
2215
+
2216
+ # @return [String ("active", "disabled")]
2217
+ attr_reader :status
2218
+
2219
+ # @return [String]
2220
+ attr_reader :url
2221
+
2222
+ def initialize(consecutive_failures:, created_at:, description:, events:, format:, id:, secret:, status:, url:)
2223
+ @consecutive_failures = consecutive_failures
2224
+ @created_at = created_at
2225
+ @description = description
2226
+ @events = events
2227
+ @format = format
2228
+ @id = id
2229
+ @secret = secret
2230
+ @status = status
2231
+ @url = url
2232
+ freeze
2233
+ end
2234
+
2235
+ # Builds a WebhookEndpointCreated from the API's JSON.
2236
+ def self.from_hash(data)
2237
+ new(
2238
+ consecutive_failures: data.fetch("consecutive_failures"),
2239
+ created_at: data.fetch("created_at"),
2240
+ description: data.fetch("description"),
2241
+ events: data.fetch("events"),
2242
+ format: data.fetch("format"),
2243
+ id: data.fetch("id"),
2244
+ secret: data.fetch("secret"),
2245
+ status: data.fetch("status"),
2246
+ url: data.fetch("url")
2247
+ )
2248
+ end
2249
+ end
2250
+
2251
+ # What usage.ingest answers.
2252
+ class UsageIngestReceipt < Model
2253
+ MEMBERS = %i[created replayed].freeze
2254
+
2255
+ # @return [Integer]
2256
+ attr_reader :created
2257
+
2258
+ # @return [Integer]
2259
+ attr_reader :replayed
2260
+
2261
+ def initialize(created:, replayed:)
2262
+ @created = created
2263
+ @replayed = replayed
2264
+ freeze
2265
+ end
2266
+
2267
+ # Builds a UsageIngestReceipt from the API's JSON.
2268
+ def self.from_hash(data)
2269
+ new(
2270
+ created: data.fetch("created"),
2271
+ replayed: data.fetch("replayed")
2272
+ )
2273
+ end
2274
+ end
821
2275
  end