metronome_api 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/metronome_api.rb +1545 -0
  3. metadata +57 -0
@@ -0,0 +1,1545 @@
1
+ # Generated by Sideko (sideko.dev)
2
+ # frozen_string_literal: true
3
+ require 'json'
4
+ require 'http'
5
+
6
+ class RequestError < StandardError
7
+ attr_reader :status_code, :method, :url, :data, :response
8
+
9
+ def initialize(method, url, response)
10
+ @status_code = response.status
11
+ @method = method
12
+ @url = url
13
+ begin
14
+ @data = response.parse
15
+ rescue
16
+ @data = nil
17
+ end
18
+ @response = response
19
+
20
+ super("received #{status_code} from #{method} #{url} with #{message}")
21
+ end
22
+ end
23
+
24
+ module AuthProvider
25
+ def add_auth(http_client, req_kwargs)
26
+ raise NotImplementedError, "You must implement the 'add_auth' method"
27
+ end
28
+ end
29
+
30
+ class AuthBasic
31
+ include AuthProvider
32
+
33
+ attr_accessor :username, :password
34
+
35
+ def initialize(username: nil, password: nil)
36
+ @username = username
37
+ @password = password
38
+ end
39
+
40
+ def add_auth(http_client, req_kwargs)
41
+ if !@username.nil? && !@password.nil?
42
+ http_client = http_client.basic_auth(user: @username, pass: @password)
43
+ end
44
+
45
+ return http_client, req_kwargs
46
+ end
47
+ end
48
+
49
+ class AuthBearer
50
+ include AuthProvider
51
+
52
+ attr_accessor :val
53
+
54
+ def initialize(val: nil)
55
+ @val = val
56
+ end
57
+
58
+ def add_auth(http_client, req_kwargs)
59
+ if !@val.nil?
60
+ headers = req_kwargs.fetch(:headers, {})
61
+ headers["Authorization"] = "Bearer " + @val
62
+ req_kwargs[:headers] = headers
63
+ end
64
+
65
+ return http_client, req_kwargs
66
+ end
67
+ end
68
+
69
+ class AuthKeyQuery
70
+ include AuthProvider
71
+
72
+ attr_accessor :query_name, :val
73
+
74
+ def initialize(query_name: nil, val: nil)
75
+ @query_name = query_name
76
+ @val = val
77
+ end
78
+
79
+ def add_auth(http_client, req_kwargs)
80
+ if !val.nil?
81
+ params = req_kwargs.fetch(:params, {})
82
+ params[query_name] = val
83
+ req_kwargs[:params] = params
84
+ end
85
+
86
+ return http_client, req_kwargs
87
+ end
88
+ end
89
+
90
+ class AuthKeyHeader
91
+ include AuthProvider
92
+
93
+ attr_accessor :header_name, :val
94
+
95
+ def initialize(header_name: nil, val: nil)
96
+ @header_name = header_name
97
+ @val = val
98
+ end
99
+
100
+ def add_auth(http_client, req_kwargs)
101
+ if !@val.nil?
102
+ headers = req_kwargs.fetch(:headers, {})
103
+ headers[@header_name] = @val
104
+ req_kwargs[:headers] = headers
105
+ end
106
+
107
+ return http_client, req_kwargs
108
+ end
109
+ end
110
+
111
+ class AuthKeyCookie
112
+ include AuthProvider
113
+
114
+ attr_accessor :cookie_name, :val
115
+
116
+ def initialize(cookie_name: nil, val: nil)
117
+ @cookie_name = cookie_name
118
+ @val = val
119
+ end
120
+
121
+ def add_auth(http_client, req_kwargs)
122
+ if !@val.nil?
123
+ http_client = http_client.cookies(@cookie_name => @val)
124
+ end
125
+
126
+ return http_client, req_kwargs
127
+ end
128
+ end
129
+
130
+ class Client
131
+ def initialize(bearer_auth: nil, base_url: 'https://api.metronome.com/v1')
132
+ @_base_url = base_url
133
+ # register auth providers
134
+ @_auth = {}
135
+ @_auth[:"bearerAuth"] = AuthBearer.new(val: bearer_auth)
136
+ end
137
+
138
+ def _client_with_auth(auth_names, **req_kwargs)
139
+ http_client = HTTP
140
+ auth_names.each do |auth_name|
141
+ provider = @_auth[auth_name]
142
+ http_client, req_kwargs = provider.add_auth(http_client, req_kwargs) if provider
143
+ end
144
+
145
+ return http_client, req_kwargs
146
+ end
147
+
148
+
149
+ # Delete the billing configuration for a given customer. Note: this is unsupported for Azure and AWS Marketplace customers.
150
+ #
151
+ def delete_billing_config_for_customer(customer_id, billing_provider_type)
152
+ _url = @_base_url + "/customers/#{customer_id}/billing-config/#{billing_provider_type}"
153
+ _kwargs = {
154
+ params: {}
155
+ }
156
+ _http_client, _req_kwargs = self._client_with_auth(
157
+ [:"bearerAuth", ],
158
+ **_kwargs
159
+ )
160
+
161
+
162
+ _response = _http_client.delete(
163
+ _url,
164
+
165
+ **_req_kwargs
166
+ )
167
+
168
+ # Raise if not expected success code
169
+ if _response.status != 200
170
+ raise RequestError.new(
171
+ method="delete",
172
+ url=_url,
173
+ response=_response
174
+ )
175
+ end
176
+
177
+ return _response.body.empty? ? '' : _response.parse
178
+ end
179
+
180
+ # Retrieves a range of audit logs. If no further audit logs are currently available, the data array will be empty. As new audit logs are created, subsequent requests using the same next_page value will be in the returned data array, ensuring a continuous and uninterrupted reading of audit logs.
181
+ #
182
+ def get_audit_logs(limit: nil, next_page: nil, starting_on: nil)
183
+ _url = @_base_url + "/auditLogs"
184
+ _kwargs = {
185
+ params: {}
186
+ }
187
+ if limit != nil
188
+ _kwargs[:params][:"limit"] = limit
189
+ end
190
+ if next_page != nil
191
+ _kwargs[:params][:"next_page"] = next_page
192
+ end
193
+ if starting_on != nil
194
+ _kwargs[:params][:"starting_on"] = starting_on
195
+ end
196
+ _http_client, _req_kwargs = self._client_with_auth(
197
+ [:"bearerAuth", ],
198
+ **_kwargs
199
+ )
200
+
201
+
202
+ _response = _http_client.get(
203
+ _url,
204
+
205
+ **_req_kwargs
206
+ )
207
+
208
+ # Raise if not expected success code
209
+ if _response.status != 200
210
+ raise RequestError.new(
211
+ method="get",
212
+ url=_url,
213
+ response=_response
214
+ )
215
+ end
216
+
217
+ return _response.body.empty? ? '' : _response.parse
218
+ end
219
+
220
+ # List all pricing units (known in the API by the legacy term "credit types").
221
+ def list_credit_types(limit: nil, next_page: nil)
222
+ _url = @_base_url + "/credit-types/list"
223
+ _kwargs = {
224
+ params: {}
225
+ }
226
+ if limit != nil
227
+ _kwargs[:params][:"limit"] = limit
228
+ end
229
+ if next_page != nil
230
+ _kwargs[:params][:"next_page"] = next_page
231
+ end
232
+ _http_client, _req_kwargs = self._client_with_auth(
233
+ [:"bearerAuth", ],
234
+ **_kwargs
235
+ )
236
+
237
+
238
+ _response = _http_client.get(
239
+ _url,
240
+
241
+ **_req_kwargs
242
+ )
243
+
244
+ # Raise if not expected success code
245
+ if _response.status != 200
246
+ raise RequestError.new(
247
+ method="get",
248
+ url=_url,
249
+ response=_response
250
+ )
251
+ end
252
+
253
+ return _response.body.empty? ? '' : _response.parse
254
+ end
255
+
256
+ # List all customers.
257
+ def list_customers(customer_ids: nil, ingest_alias: nil, limit: nil, next_page: nil, only_archived: nil, salesforce_account_ids: nil)
258
+ _url = @_base_url + "/customers"
259
+ _kwargs = {
260
+ params: {}
261
+ }
262
+ if customer_ids != nil
263
+ _kwargs[:params][:"customer_ids"] = customer_ids.join(",")
264
+ end
265
+ if ingest_alias != nil
266
+ _kwargs[:params][:"ingest_alias"] = ingest_alias
267
+ end
268
+ if limit != nil
269
+ _kwargs[:params][:"limit"] = limit
270
+ end
271
+ if next_page != nil
272
+ _kwargs[:params][:"next_page"] = next_page
273
+ end
274
+ if only_archived != nil
275
+ _kwargs[:params][:"only_archived"] = only_archived
276
+ end
277
+ if salesforce_account_ids != nil
278
+ _kwargs[:params][:"salesforce_account_ids"] = salesforce_account_ids.join(",")
279
+ end
280
+ _http_client, _req_kwargs = self._client_with_auth(
281
+ [:"bearerAuth", ],
282
+ **_kwargs
283
+ )
284
+
285
+
286
+ _response = _http_client.get(
287
+ _url,
288
+
289
+ **_req_kwargs
290
+ )
291
+
292
+ # Raise if not expected success code
293
+ if _response.status != 200
294
+ raise RequestError.new(
295
+ method="get",
296
+ url=_url,
297
+ response=_response
298
+ )
299
+ end
300
+
301
+ return _response.body.empty? ? '' : _response.parse
302
+ end
303
+
304
+ # Get a customer by Metronome ID.
305
+ def get_customer(customer_id)
306
+ _url = @_base_url + "/customers/#{customer_id}"
307
+ _kwargs = {
308
+ params: {}
309
+ }
310
+ _http_client, _req_kwargs = self._client_with_auth(
311
+ [:"bearerAuth", ],
312
+ **_kwargs
313
+ )
314
+
315
+
316
+ _response = _http_client.get(
317
+ _url,
318
+
319
+ **_req_kwargs
320
+ )
321
+
322
+ # Raise if not expected success code
323
+ if _response.status != 200
324
+ raise RequestError.new(
325
+ method="get",
326
+ url=_url,
327
+ response=_response
328
+ )
329
+ end
330
+
331
+ return _response.body.empty? ? '' : _response.parse
332
+ end
333
+
334
+ # List all billable metrics.
335
+ def list_billable_metrics(customer_id, limit: nil, next_page: nil, on_current_plan: nil)
336
+ _url = @_base_url + "/customers/#{customer_id}/billable-metrics"
337
+ _kwargs = {
338
+ params: {}
339
+ }
340
+ if limit != nil
341
+ _kwargs[:params][:"limit"] = limit
342
+ end
343
+ if next_page != nil
344
+ _kwargs[:params][:"next_page"] = next_page
345
+ end
346
+ if on_current_plan != nil
347
+ _kwargs[:params][:"on_current_plan"] = on_current_plan
348
+ end
349
+ _http_client, _req_kwargs = self._client_with_auth(
350
+ [:"bearerAuth", ],
351
+ **_kwargs
352
+ )
353
+
354
+
355
+ _response = _http_client.get(
356
+ _url,
357
+
358
+ **_req_kwargs
359
+ )
360
+
361
+ # Raise if not expected success code
362
+ if _response.status != 200
363
+ raise RequestError.new(
364
+ method="get",
365
+ url=_url,
366
+ response=_response
367
+ )
368
+ end
369
+
370
+ return _response.body.empty? ? '' : _response.parse
371
+ end
372
+
373
+ # Fetch the billing configuration for the given customer.
374
+ def get_billing_config(customer_id, billing_provider_type)
375
+ _url = @_base_url + "/customers/#{customer_id}/billing-config/#{billing_provider_type}"
376
+ _kwargs = {
377
+ params: {}
378
+ }
379
+ _http_client, _req_kwargs = self._client_with_auth(
380
+ [:"bearerAuth", ],
381
+ **_kwargs
382
+ )
383
+
384
+
385
+ _response = _http_client.get(
386
+ _url,
387
+
388
+ **_req_kwargs
389
+ )
390
+
391
+ # Raise if not expected success code
392
+ if _response.status != 200
393
+ raise RequestError.new(
394
+ method="get",
395
+ url=_url,
396
+ response=_response
397
+ )
398
+ end
399
+
400
+ return _response.body.empty? ? '' : _response.parse
401
+ end
402
+
403
+ # Fetch daily pending costs for the specified customer, broken down by credit type and line items. Note: this is not supported for customers whose plan includes a UNIQUE-type billable metric.
404
+ def get_costs(customer_id, ending_before, starting_on, limit: nil, next_page: nil)
405
+ _url = @_base_url + "/customers/#{customer_id}/costs"
406
+ _kwargs = {
407
+ params: {}
408
+ }
409
+ _kwargs[:params][:"ending_before"] = ending_before
410
+ _kwargs[:params][:"starting_on"] = starting_on
411
+ if limit != nil
412
+ _kwargs[:params][:"limit"] = limit
413
+ end
414
+ if next_page != nil
415
+ _kwargs[:params][:"next_page"] = next_page
416
+ end
417
+ _http_client, _req_kwargs = self._client_with_auth(
418
+ [:"bearerAuth", ],
419
+ **_kwargs
420
+ )
421
+
422
+
423
+ _response = _http_client.get(
424
+ _url,
425
+
426
+ **_req_kwargs
427
+ )
428
+
429
+ # Raise if not expected success code
430
+ if _response.status != 200
431
+ raise RequestError.new(
432
+ method="get",
433
+ url=_url,
434
+ response=_response
435
+ )
436
+ end
437
+
438
+ return _response.body.empty? ? '' : _response.parse
439
+ end
440
+
441
+ # List all invoices for a given customer, optionally filtered by status, date range, and/or credit type.
442
+ def list_invoices(customer_id, credit_type_id: nil, ending_before: nil, limit: nil, next_page: nil, sort: nil, starting_on: nil, status: nil)
443
+ _url = @_base_url + "/customers/#{customer_id}/invoices"
444
+ _kwargs = {
445
+ params: {}
446
+ }
447
+ if credit_type_id != nil
448
+ _kwargs[:params][:"credit_type_id"] = credit_type_id
449
+ end
450
+ if ending_before != nil
451
+ _kwargs[:params][:"ending_before"] = ending_before
452
+ end
453
+ if limit != nil
454
+ _kwargs[:params][:"limit"] = limit
455
+ end
456
+ if next_page != nil
457
+ _kwargs[:params][:"next_page"] = next_page
458
+ end
459
+ if sort != nil
460
+ _kwargs[:params][:"sort"] = sort
461
+ end
462
+ if starting_on != nil
463
+ _kwargs[:params][:"starting_on"] = starting_on
464
+ end
465
+ if status != nil
466
+ _kwargs[:params][:"status"] = status
467
+ end
468
+ _http_client, _req_kwargs = self._client_with_auth(
469
+ [:"bearerAuth", ],
470
+ **_kwargs
471
+ )
472
+
473
+
474
+ _response = _http_client.get(
475
+ _url,
476
+
477
+ **_req_kwargs
478
+ )
479
+
480
+ # Raise if not expected success code
481
+ if _response.status != 200
482
+ raise RequestError.new(
483
+ method="get",
484
+ url=_url,
485
+ response=_response
486
+ )
487
+ end
488
+
489
+ return _response.body.empty? ? '' : _response.parse
490
+ end
491
+
492
+ # Fetch a specific invoice for a given customer.
493
+ def get_invoice(customer_id, invoice_id)
494
+ _url = @_base_url + "/customers/#{customer_id}/invoices/#{invoice_id}"
495
+ _kwargs = {
496
+ params: {}
497
+ }
498
+ _http_client, _req_kwargs = self._client_with_auth(
499
+ [:"bearerAuth", ],
500
+ **_kwargs
501
+ )
502
+
503
+
504
+ _response = _http_client.get(
505
+ _url,
506
+
507
+ **_req_kwargs
508
+ )
509
+
510
+ # Raise if not expected success code
511
+ if _response.status != 200
512
+ raise RequestError.new(
513
+ method="get",
514
+ url=_url,
515
+ response=_response
516
+ )
517
+ end
518
+
519
+ return _response.body.empty? ? '' : _response.parse
520
+ end
521
+
522
+ # List the given customer's plans in reverse-chronological order.
523
+ def list_customer_plans(customer_id, limit: nil, next_page: nil)
524
+ _url = @_base_url + "/customers/#{customer_id}/plans"
525
+ _kwargs = {
526
+ params: {}
527
+ }
528
+ if limit != nil
529
+ _kwargs[:params][:"limit"] = limit
530
+ end
531
+ if next_page != nil
532
+ _kwargs[:params][:"next_page"] = next_page
533
+ end
534
+ _http_client, _req_kwargs = self._client_with_auth(
535
+ [:"bearerAuth", ],
536
+ **_kwargs
537
+ )
538
+
539
+
540
+ _response = _http_client.get(
541
+ _url,
542
+
543
+ **_req_kwargs
544
+ )
545
+
546
+ # Raise if not expected success code
547
+ if _response.status != 200
548
+ raise RequestError.new(
549
+ method="get",
550
+ url=_url,
551
+ response=_response
552
+ )
553
+ end
554
+
555
+ return _response.body.empty? ? '' : _response.parse
556
+ end
557
+
558
+ # Lists a customer plans adjustments. See the [price adjustments documentation](https://docs.metronome.com/pricing/managing-plans/#price-adjustments) for details.
559
+ def get_plan_price_adjustments(customer_id, customer_plan_id, limit: nil, next_page: nil)
560
+ _url = @_base_url + "/customers/#{customer_id}/plans/#{customer_plan_id}/priceAdjustments"
561
+ _kwargs = {
562
+ params: {}
563
+ }
564
+ if limit != nil
565
+ _kwargs[:params][:"limit"] = limit
566
+ end
567
+ if next_page != nil
568
+ _kwargs[:params][:"next_page"] = next_page
569
+ end
570
+ _http_client, _req_kwargs = self._client_with_auth(
571
+ [:"bearerAuth", ],
572
+ **_kwargs
573
+ )
574
+
575
+
576
+ _response = _http_client.get(
577
+ _url,
578
+
579
+ **_req_kwargs
580
+ )
581
+
582
+ # Raise if not expected success code
583
+ if _response.status != 200
584
+ raise RequestError.new(
585
+ method="get",
586
+ url=_url,
587
+ response=_response
588
+ )
589
+ end
590
+
591
+ return _response.body.empty? ? '' : _response.parse
592
+ end
593
+
594
+ # Fetch high level details of a specific plan.
595
+ def get_plan_details(plan_id)
596
+ _url = @_base_url + "/planDetails/#{plan_id}"
597
+ _kwargs = {
598
+ params: {}
599
+ }
600
+ _http_client, _req_kwargs = self._client_with_auth(
601
+ [:"bearerAuth", ],
602
+ **_kwargs
603
+ )
604
+
605
+
606
+ _response = _http_client.get(
607
+ _url,
608
+
609
+ **_req_kwargs
610
+ )
611
+
612
+ # Raise if not expected success code
613
+ if _response.status != 200
614
+ raise RequestError.new(
615
+ method="get",
616
+ url=_url,
617
+ response=_response
618
+ )
619
+ end
620
+
621
+ return _response.body.empty? ? '' : _response.parse
622
+ end
623
+
624
+ # Fetches a list of charges of a specific plan.
625
+ def get_plan_charges(plan_id, limit: nil, next_page: nil)
626
+ _url = @_base_url + "/planDetails/#{plan_id}/charges"
627
+ _kwargs = {
628
+ params: {}
629
+ }
630
+ if limit != nil
631
+ _kwargs[:params][:"limit"] = limit
632
+ end
633
+ if next_page != nil
634
+ _kwargs[:params][:"next_page"] = next_page
635
+ end
636
+ _http_client, _req_kwargs = self._client_with_auth(
637
+ [:"bearerAuth", ],
638
+ **_kwargs
639
+ )
640
+
641
+
642
+ _response = _http_client.get(
643
+ _url,
644
+
645
+ **_req_kwargs
646
+ )
647
+
648
+ # Raise if not expected success code
649
+ if _response.status != 200
650
+ raise RequestError.new(
651
+ method="get",
652
+ url=_url,
653
+ response=_response
654
+ )
655
+ end
656
+
657
+ return _response.body.empty? ? '' : _response.parse
658
+ end
659
+
660
+ # Fetches a list of customers on a specific plan (by default, only currently active plans are included)
661
+ def get_plan_customers(plan_id, limit: nil, next_page: nil, status: nil)
662
+ _url = @_base_url + "/planDetails/#{plan_id}/customers"
663
+ _kwargs = {
664
+ params: {}
665
+ }
666
+ if limit != nil
667
+ _kwargs[:params][:"limit"] = limit
668
+ end
669
+ if next_page != nil
670
+ _kwargs[:params][:"next_page"] = next_page
671
+ end
672
+ if status != nil
673
+ _kwargs[:params][:"status"] = status
674
+ end
675
+ _http_client, _req_kwargs = self._client_with_auth(
676
+ [:"bearerAuth", ],
677
+ **_kwargs
678
+ )
679
+
680
+
681
+ _response = _http_client.get(
682
+ _url,
683
+
684
+ **_req_kwargs
685
+ )
686
+
687
+ # Raise if not expected success code
688
+ if _response.status != 200
689
+ raise RequestError.new(
690
+ method="get",
691
+ url=_url,
692
+ response=_response
693
+ )
694
+ end
695
+
696
+ return _response.body.empty? ? '' : _response.parse
697
+ end
698
+
699
+ # List all available plans.
700
+ def list_plans(limit: nil, next_page: nil)
701
+ _url = @_base_url + "/plans"
702
+ _kwargs = {
703
+ params: {}
704
+ }
705
+ if limit != nil
706
+ _kwargs[:params][:"limit"] = limit
707
+ end
708
+ if next_page != nil
709
+ _kwargs[:params][:"next_page"] = next_page
710
+ end
711
+ _http_client, _req_kwargs = self._client_with_auth(
712
+ [:"bearerAuth", ],
713
+ **_kwargs
714
+ )
715
+
716
+
717
+ _response = _http_client.get(
718
+ _url,
719
+
720
+ **_req_kwargs
721
+ )
722
+
723
+ # Raise if not expected success code
724
+ if _response.status != 200
725
+ raise RequestError.new(
726
+ method="get",
727
+ url=_url,
728
+ response=_response
729
+ )
730
+ end
731
+
732
+ return _response.body.empty? ? '' : _response.parse
733
+ end
734
+
735
+ # Archive an existing alert
736
+ def archive_alert(data: nil)
737
+ _url = @_base_url + "/alerts/archive"
738
+ _kwargs = {
739
+ params: {}
740
+ }
741
+ _http_client, _req_kwargs = self._client_with_auth(
742
+ [:"bearerAuth", ],
743
+ **_kwargs
744
+ )
745
+
746
+
747
+ _response = _http_client.post(
748
+ _url,
749
+ json: data,
750
+ **_req_kwargs
751
+ )
752
+
753
+ # Raise if not expected success code
754
+ if _response.status != 200
755
+ raise RequestError.new(
756
+ method="post",
757
+ url=_url,
758
+ response=_response
759
+ )
760
+ end
761
+
762
+ return _response.body.empty? ? '' : _response.parse
763
+ end
764
+
765
+ # Create a new alert
766
+ def create_alert(data: nil)
767
+ _url = @_base_url + "/alerts/create"
768
+ _kwargs = {
769
+ params: {}
770
+ }
771
+ _http_client, _req_kwargs = self._client_with_auth(
772
+ [:"bearerAuth", ],
773
+ **_kwargs
774
+ )
775
+
776
+
777
+ _response = _http_client.post(
778
+ _url,
779
+ json: data,
780
+ **_req_kwargs
781
+ )
782
+
783
+ # Raise if not expected success code
784
+ if _response.status != 200
785
+ raise RequestError.new(
786
+ method="post",
787
+ url=_url,
788
+ response=_response
789
+ )
790
+ end
791
+
792
+ return _response.body.empty? ? '' : _response.parse
793
+ end
794
+
795
+ # Create a new credit grant
796
+ def create_grant(data: nil)
797
+ _url = @_base_url + "/credits/createGrant"
798
+ _kwargs = {
799
+ params: {}
800
+ }
801
+ _http_client, _req_kwargs = self._client_with_auth(
802
+ [:"bearerAuth", ],
803
+ **_kwargs
804
+ )
805
+
806
+
807
+ _response = _http_client.post(
808
+ _url,
809
+ json: data,
810
+ **_req_kwargs
811
+ )
812
+
813
+ # Raise if not expected success code
814
+ if _response.status != 200
815
+ raise RequestError.new(
816
+ method="post",
817
+ url=_url,
818
+ response=_response
819
+ )
820
+ end
821
+
822
+ return _response.body.empty? ? '' : _response.parse
823
+ end
824
+
825
+ # Edit an existing credit grant
826
+ def edit_grant(data: nil)
827
+ _url = @_base_url + "/credits/editGrant"
828
+ _kwargs = {
829
+ params: {}
830
+ }
831
+ _http_client, _req_kwargs = self._client_with_auth(
832
+ [:"bearerAuth", ],
833
+ **_kwargs
834
+ )
835
+
836
+
837
+ _response = _http_client.post(
838
+ _url,
839
+ json: data,
840
+ **_req_kwargs
841
+ )
842
+
843
+ # Raise if not expected success code
844
+ if _response.status != 200
845
+ raise RequestError.new(
846
+ method="post",
847
+ url=_url,
848
+ response=_response
849
+ )
850
+ end
851
+
852
+ return _response.body.empty? ? '' : _response.parse
853
+ end
854
+
855
+ # Fetches a list of credit ledger entries. Returns lists of ledgers per customer. Ledger entries are returned in reverse chronological order. Ledger entries associated with voided credit grants are not included.
856
+ def list_credit_ledger_entries(data: nil, next_page: nil)
857
+ _url = @_base_url + "/credits/listEntries"
858
+ _kwargs = {
859
+ params: {}
860
+ }
861
+ if next_page != nil
862
+ _kwargs[:params][:"next_page"] = next_page
863
+ end
864
+ _http_client, _req_kwargs = self._client_with_auth(
865
+ [:"bearerAuth", ],
866
+ **_kwargs
867
+ )
868
+
869
+
870
+ _response = _http_client.post(
871
+ _url,
872
+ json: data,
873
+ **_req_kwargs
874
+ )
875
+
876
+ # Raise if not expected success code
877
+ if _response.status != 200
878
+ raise RequestError.new(
879
+ method="post",
880
+ url=_url,
881
+ response=_response
882
+ )
883
+ end
884
+
885
+ return _response.body.empty? ? '' : _response.parse
886
+ end
887
+
888
+ # List credit grants. This list does not included voided grants.
889
+ def list_grants(data: nil, next_page: nil)
890
+ _url = @_base_url + "/credits/listGrants"
891
+ _kwargs = {
892
+ params: {}
893
+ }
894
+ if next_page != nil
895
+ _kwargs[:params][:"next_page"] = next_page
896
+ end
897
+ _http_client, _req_kwargs = self._client_with_auth(
898
+ [:"bearerAuth", ],
899
+ **_kwargs
900
+ )
901
+
902
+
903
+ _response = _http_client.post(
904
+ _url,
905
+ json: data,
906
+ **_req_kwargs
907
+ )
908
+
909
+ # Raise if not expected success code
910
+ if _response.status != 200
911
+ raise RequestError.new(
912
+ method="post",
913
+ url=_url,
914
+ response=_response
915
+ )
916
+ end
917
+
918
+ return _response.body.empty? ? '' : _response.parse
919
+ end
920
+
921
+ # Void a credit grant
922
+ def void_grant(data: nil)
923
+ _url = @_base_url + "/credits/voidGrant"
924
+ _kwargs = {
925
+ params: {}
926
+ }
927
+ _http_client, _req_kwargs = self._client_with_auth(
928
+ [:"bearerAuth", ],
929
+ **_kwargs
930
+ )
931
+
932
+
933
+ _response = _http_client.post(
934
+ _url,
935
+ json: data,
936
+ **_req_kwargs
937
+ )
938
+
939
+ # Raise if not expected success code
940
+ if _response.status != 200
941
+ raise RequestError.new(
942
+ method="post",
943
+ url=_url,
944
+ response=_response
945
+ )
946
+ end
947
+
948
+ return _response.body.empty? ? '' : _response.parse
949
+ end
950
+
951
+ # Add a key to the allow list for a given entity. There is a 100 character limit on custom field keys.
952
+ #
953
+ def add_custom_field_key(data: nil)
954
+ _url = @_base_url + "/customFields/addKey"
955
+ _kwargs = {
956
+ params: {}
957
+ }
958
+ _http_client, _req_kwargs = self._client_with_auth(
959
+ [:"bearerAuth", ],
960
+ **_kwargs
961
+ )
962
+
963
+
964
+ _response = _http_client.post(
965
+ _url,
966
+ json: data,
967
+ **_req_kwargs
968
+ )
969
+
970
+ # Raise if not expected success code
971
+ if _response.status != 200
972
+ raise RequestError.new(
973
+ method="post",
974
+ url=_url,
975
+ response=_response
976
+ )
977
+ end
978
+
979
+ return _response.body.empty? ? '' : _response.parse
980
+ end
981
+
982
+ # Deletes one or more custom fields on an instance of a Metronome entity.
983
+ #
984
+ def delete_custom_fields(data: nil)
985
+ _url = @_base_url + "/customFields/deleteValues"
986
+ _kwargs = {
987
+ params: {}
988
+ }
989
+ _http_client, _req_kwargs = self._client_with_auth(
990
+ [:"bearerAuth", ],
991
+ **_kwargs
992
+ )
993
+
994
+
995
+ _response = _http_client.post(
996
+ _url,
997
+ json: data,
998
+ **_req_kwargs
999
+ )
1000
+
1001
+ # Raise if not expected success code
1002
+ if _response.status != 200
1003
+ raise RequestError.new(
1004
+ method="post",
1005
+ url=_url,
1006
+ response=_response
1007
+ )
1008
+ end
1009
+
1010
+ return _response.body.empty? ? '' : _response.parse
1011
+ end
1012
+
1013
+ # List all active custom field keys, optionally filtered by entity type.
1014
+ #
1015
+ def list_custom_field_keys(data: nil, next_page: nil)
1016
+ _url = @_base_url + "/customFields/listKeys"
1017
+ _kwargs = {
1018
+ params: {}
1019
+ }
1020
+ if next_page != nil
1021
+ _kwargs[:params][:"next_page"] = next_page
1022
+ end
1023
+ _http_client, _req_kwargs = self._client_with_auth(
1024
+ [:"bearerAuth", ],
1025
+ **_kwargs
1026
+ )
1027
+
1028
+
1029
+ _response = _http_client.post(
1030
+ _url,
1031
+ json: data,
1032
+ **_req_kwargs
1033
+ )
1034
+
1035
+ # Raise if not expected success code
1036
+ if _response.status != 200
1037
+ raise RequestError.new(
1038
+ method="post",
1039
+ url=_url,
1040
+ response=_response
1041
+ )
1042
+ end
1043
+
1044
+ return _response.body.empty? ? '' : _response.parse
1045
+ end
1046
+
1047
+ # Remove a key from the allow list for a given entity.
1048
+ #
1049
+ def disable_custom_field_key(data: nil)
1050
+ _url = @_base_url + "/customFields/removeKey"
1051
+ _kwargs = {
1052
+ params: {}
1053
+ }
1054
+ _http_client, _req_kwargs = self._client_with_auth(
1055
+ [:"bearerAuth", ],
1056
+ **_kwargs
1057
+ )
1058
+
1059
+
1060
+ _response = _http_client.post(
1061
+ _url,
1062
+ json: data,
1063
+ **_req_kwargs
1064
+ )
1065
+
1066
+ # Raise if not expected success code
1067
+ if _response.status != 200
1068
+ raise RequestError.new(
1069
+ method="post",
1070
+ url=_url,
1071
+ response=_response
1072
+ )
1073
+ end
1074
+
1075
+ return _response.body.empty? ? '' : _response.parse
1076
+ end
1077
+
1078
+ # Sets one or more custom fields on an instance of a Metronome entity. If a key/value pair passed in this request matches one already set on the entity, its value will be overwritten. Any key/value pairs that exist on the entity that do not match those passed in this request will remain untouched. This endpoint is transactional and will update all key/value pairs or no key/value pairs. Partial updates are not supported. There is a 200 character limit on custom field values.
1079
+ #
1080
+ def set_custom_fields(data: nil)
1081
+ _url = @_base_url + "/customFields/setValues"
1082
+ _kwargs = {
1083
+ params: {}
1084
+ }
1085
+ _http_client, _req_kwargs = self._client_with_auth(
1086
+ [:"bearerAuth", ],
1087
+ **_kwargs
1088
+ )
1089
+
1090
+
1091
+ _response = _http_client.post(
1092
+ _url,
1093
+ json: data,
1094
+ **_req_kwargs
1095
+ )
1096
+
1097
+ # Raise if not expected success code
1098
+ if _response.status != 200
1099
+ raise RequestError.new(
1100
+ method="post",
1101
+ url=_url,
1102
+ response=_response
1103
+ )
1104
+ end
1105
+
1106
+ return _response.body.empty? ? '' : _response.parse
1107
+ end
1108
+
1109
+ # Get the customer alert status and alert information for the specified customer and alert
1110
+ def get_customer_alert(data: nil)
1111
+ _url = @_base_url + "/customer-alerts/get"
1112
+ _kwargs = {
1113
+ params: {}
1114
+ }
1115
+ _http_client, _req_kwargs = self._client_with_auth(
1116
+ [:"bearerAuth", ],
1117
+ **_kwargs
1118
+ )
1119
+
1120
+
1121
+ _response = _http_client.post(
1122
+ _url,
1123
+ json: data,
1124
+ **_req_kwargs
1125
+ )
1126
+
1127
+ # Raise if not expected success code
1128
+ if _response.status != 200
1129
+ raise RequestError.new(
1130
+ method="post",
1131
+ url=_url,
1132
+ response=_response
1133
+ )
1134
+ end
1135
+
1136
+ return _response.body.empty? ? '' : _response.parse
1137
+ end
1138
+
1139
+ # Fetch all customer alert statuses and alert information for a customer
1140
+ def list_customer_alerts(data: nil, next_page: nil)
1141
+ _url = @_base_url + "/customer-alerts/list"
1142
+ _kwargs = {
1143
+ params: {}
1144
+ }
1145
+ if next_page != nil
1146
+ _kwargs[:params][:"next_page"] = next_page
1147
+ end
1148
+ _http_client, _req_kwargs = self._client_with_auth(
1149
+ [:"bearerAuth", ],
1150
+ **_kwargs
1151
+ )
1152
+
1153
+
1154
+ _response = _http_client.post(
1155
+ _url,
1156
+ json: data,
1157
+ **_req_kwargs
1158
+ )
1159
+
1160
+ # Raise if not expected success code
1161
+ if _response.status != 200
1162
+ raise RequestError.new(
1163
+ method="post",
1164
+ url=_url,
1165
+ response=_response
1166
+ )
1167
+ end
1168
+
1169
+ return _response.body.empty? ? '' : _response.parse
1170
+ end
1171
+
1172
+ # Create a new customer
1173
+ def create_customer(data: nil)
1174
+ _url = @_base_url + "/customers"
1175
+ _kwargs = {
1176
+ params: {}
1177
+ }
1178
+ _http_client, _req_kwargs = self._client_with_auth(
1179
+ [:"bearerAuth", ],
1180
+ **_kwargs
1181
+ )
1182
+
1183
+
1184
+ _response = _http_client.post(
1185
+ _url,
1186
+ json: data,
1187
+ **_req_kwargs
1188
+ )
1189
+
1190
+ # Raise if not expected success code
1191
+ if _response.status != 200
1192
+ raise RequestError.new(
1193
+ method="post",
1194
+ url=_url,
1195
+ response=_response
1196
+ )
1197
+ end
1198
+
1199
+ return _response.body.empty? ? '' : _response.parse
1200
+ end
1201
+
1202
+ # Archive a customer
1203
+ def archive_customer(data: nil)
1204
+ _url = @_base_url + "/customers/archive"
1205
+ _kwargs = {
1206
+ params: {}
1207
+ }
1208
+ _http_client, _req_kwargs = self._client_with_auth(
1209
+ [:"bearerAuth", ],
1210
+ **_kwargs
1211
+ )
1212
+
1213
+
1214
+ _response = _http_client.post(
1215
+ _url,
1216
+ json: data,
1217
+ **_req_kwargs
1218
+ )
1219
+
1220
+ # Raise if not expected success code
1221
+ if _response.status != 200
1222
+ raise RequestError.new(
1223
+ method="post",
1224
+ url=_url,
1225
+ response=_response
1226
+ )
1227
+ end
1228
+
1229
+ return _response.body.empty? ? '' : _response.parse
1230
+ end
1231
+
1232
+ # Set the billing configuration for a given customer.
1233
+ def set_billing_config_for_customer(data: nil, customer_id, billing_provider_type)
1234
+ _url = @_base_url + "/customers/#{customer_id}/billing-config/#{billing_provider_type}"
1235
+ _kwargs = {
1236
+ params: {}
1237
+ }
1238
+ _http_client, _req_kwargs = self._client_with_auth(
1239
+ [:"bearerAuth", ],
1240
+ **_kwargs
1241
+ )
1242
+
1243
+
1244
+ _response = _http_client.post(
1245
+ _url,
1246
+ json: data,
1247
+ **_req_kwargs
1248
+ )
1249
+
1250
+ # Raise if not expected success code
1251
+ if _response.status != 200
1252
+ raise RequestError.new(
1253
+ method="post",
1254
+ url=_url,
1255
+ response=_response
1256
+ )
1257
+ end
1258
+
1259
+ return _response.body.empty? ? '' : _response.parse
1260
+ end
1261
+
1262
+ # Associate an existing customer with a plan for a specified date range. See the [price adjustments documentation](https://docs.metronome.com/pricing/managing-plans/#price-adjustments) for details on the price adjustments.
1263
+ def add_plan_to_customer(data: nil, customer_id)
1264
+ _url = @_base_url + "/customers/#{customer_id}/plans/add"
1265
+ _kwargs = {
1266
+ params: {}
1267
+ }
1268
+ _http_client, _req_kwargs = self._client_with_auth(
1269
+ [:"bearerAuth", ],
1270
+ **_kwargs
1271
+ )
1272
+
1273
+
1274
+ _response = _http_client.post(
1275
+ _url,
1276
+ json: data,
1277
+ **_req_kwargs
1278
+ )
1279
+
1280
+ # Raise if not expected success code
1281
+ if _response.status != 200
1282
+ raise RequestError.new(
1283
+ method="post",
1284
+ url=_url,
1285
+ response=_response
1286
+ )
1287
+ end
1288
+
1289
+ return _response.body.empty? ? '' : _response.parse
1290
+ end
1291
+
1292
+ # Change the end date of a customer's plan.
1293
+ def end_customer_plan(data: nil, customer_id, customer_plan_id)
1294
+ _url = @_base_url + "/customers/#{customer_id}/plans/#{customer_plan_id}/end"
1295
+ _kwargs = {
1296
+ params: {}
1297
+ }
1298
+ _http_client, _req_kwargs = self._client_with_auth(
1299
+ [:"bearerAuth", ],
1300
+ **_kwargs
1301
+ )
1302
+
1303
+
1304
+ _response = _http_client.post(
1305
+ _url,
1306
+ json: data,
1307
+ **_req_kwargs
1308
+ )
1309
+
1310
+ # Raise if not expected success code
1311
+ if _response.status != 200
1312
+ raise RequestError.new(
1313
+ method="post",
1314
+ url=_url,
1315
+ response=_response
1316
+ )
1317
+ end
1318
+
1319
+ return _response.body.empty? ? '' : _response.parse
1320
+ end
1321
+
1322
+ # Sets the ingest aliases for a customer. Ingest aliases can be used in the `customer_id` field when sending usage events to Metronome. This call is idempotent. It fully replaces the set of ingest aliases for the given customer.
1323
+ #
1324
+ def set_ingest_aliases(data: nil, customer_id)
1325
+ _url = @_base_url + "/customers/#{customer_id}/setIngestAliases"
1326
+ _kwargs = {
1327
+ params: {}
1328
+ }
1329
+ _http_client, _req_kwargs = self._client_with_auth(
1330
+ [:"bearerAuth", ],
1331
+ **_kwargs
1332
+ )
1333
+
1334
+
1335
+ _response = _http_client.post(
1336
+ _url,
1337
+ json: data,
1338
+ **_req_kwargs
1339
+ )
1340
+
1341
+ # Raise if not expected success code
1342
+ if _response.status != 200
1343
+ raise RequestError.new(
1344
+ method="post",
1345
+ url=_url,
1346
+ response=_response
1347
+ )
1348
+ end
1349
+
1350
+ return _response.body.empty? ? '' : _response.parse
1351
+ end
1352
+
1353
+ # Updates the specified customer's name.
1354
+ #
1355
+ def set_customer_name(data: nil, customer_id)
1356
+ _url = @_base_url + "/customers/#{customer_id}/setName"
1357
+ _kwargs = {
1358
+ params: {}
1359
+ }
1360
+ _http_client, _req_kwargs = self._client_with_auth(
1361
+ [:"bearerAuth", ],
1362
+ **_kwargs
1363
+ )
1364
+
1365
+
1366
+ _response = _http_client.post(
1367
+ _url,
1368
+ json: data,
1369
+ **_req_kwargs
1370
+ )
1371
+
1372
+ # Raise if not expected success code
1373
+ if _response.status != 200
1374
+ raise RequestError.new(
1375
+ method="post",
1376
+ url=_url,
1377
+ response=_response
1378
+ )
1379
+ end
1380
+
1381
+ return _response.body.empty? ? '' : _response.parse
1382
+ end
1383
+
1384
+ # Updates the specified customer's config.
1385
+ #
1386
+ def update_customer_config(data: nil, customer_id)
1387
+ _url = @_base_url + "/customers/#{customer_id}/updateConfig"
1388
+ _kwargs = {
1389
+ params: {}
1390
+ }
1391
+ _http_client, _req_kwargs = self._client_with_auth(
1392
+ [:"bearerAuth", ],
1393
+ **_kwargs
1394
+ )
1395
+
1396
+
1397
+ _response = _http_client.post(
1398
+ _url,
1399
+ json: data,
1400
+ **_req_kwargs
1401
+ )
1402
+
1403
+ # Raise if not expected success code
1404
+ if _response.status != 200
1405
+ raise RequestError.new(
1406
+ method="post",
1407
+ url=_url,
1408
+ response=_response
1409
+ )
1410
+ end
1411
+
1412
+ return _response.body.empty? ? '' : _response.parse
1413
+ end
1414
+
1415
+ # Retrieve an embeddable dashboard url for a customer. The dashboard can be embedded using an iframe in a website. This will show information such as usage data and customer invoices.
1416
+ def embeddable_dashboard(data: nil)
1417
+ _url = @_base_url + "/dashboards/getEmbeddableUrl"
1418
+ _kwargs = {
1419
+ params: {}
1420
+ }
1421
+ _http_client, _req_kwargs = self._client_with_auth(
1422
+ [:"bearerAuth", ],
1423
+ **_kwargs
1424
+ )
1425
+
1426
+
1427
+ _response = _http_client.post(
1428
+ _url,
1429
+ json: data,
1430
+ **_req_kwargs
1431
+ )
1432
+
1433
+ # Raise if not expected success code
1434
+ if _response.status != 200
1435
+ raise RequestError.new(
1436
+ method="post",
1437
+ url=_url,
1438
+ response=_response
1439
+ )
1440
+ end
1441
+
1442
+ return _response.body.empty? ? '' : _response.parse
1443
+ end
1444
+
1445
+ # Send usage events to Metronome. The body of this request is expected to be a JSON array of between 1 and 100 usage events. Compressed request bodies are supported with a `Content-Encoding: gzip` header. See [Getting usage into Metronome](https://docs.metronome.com/getting-usage-data-into-metronome/overview) to learn more about usage events.
1446
+ #
1447
+ def ingest(data: nil)
1448
+ _url = @_base_url + "/ingest"
1449
+ _kwargs = {
1450
+ params: {}
1451
+ }
1452
+ _http_client, _req_kwargs = self._client_with_auth(
1453
+ [:"bearerAuth", ],
1454
+ **_kwargs
1455
+ )
1456
+
1457
+
1458
+ _response = _http_client.post(
1459
+ _url,
1460
+ json: data,
1461
+ **_req_kwargs
1462
+ )
1463
+
1464
+ # Raise if not expected success code
1465
+ if _response.status != 200
1466
+ raise RequestError.new(
1467
+ method="post",
1468
+ url=_url,
1469
+ response=_response
1470
+ )
1471
+ end
1472
+
1473
+ return _response.body.empty? ? '' : _response.parse
1474
+ end
1475
+
1476
+ # Fetch aggregated usage data for multiple customers and billable-metrics, broken into intervals of the specified length.
1477
+ def get_usage_batch(data: nil, next_page: nil)
1478
+ _url = @_base_url + "/usage"
1479
+ _kwargs = {
1480
+ params: {}
1481
+ }
1482
+ if next_page != nil
1483
+ _kwargs[:params][:"next_page"] = next_page
1484
+ end
1485
+ _http_client, _req_kwargs = self._client_with_auth(
1486
+ [:"bearerAuth", ],
1487
+ **_kwargs
1488
+ )
1489
+
1490
+
1491
+ _response = _http_client.post(
1492
+ _url,
1493
+ json: data,
1494
+ **_req_kwargs
1495
+ )
1496
+
1497
+ # Raise if not expected success code
1498
+ if _response.status != 200
1499
+ raise RequestError.new(
1500
+ method="post",
1501
+ url=_url,
1502
+ response=_response
1503
+ )
1504
+ end
1505
+
1506
+ return _response.body.empty? ? '' : _response.parse
1507
+ end
1508
+
1509
+ # Fetch aggregated usage data for the specified customer, billable-metric, and optional group, broken into intervals of the specified length.
1510
+ def get_paged_usage(data: nil, limit: nil, next_page: nil)
1511
+ _url = @_base_url + "/usage/groups"
1512
+ _kwargs = {
1513
+ params: {}
1514
+ }
1515
+ if limit != nil
1516
+ _kwargs[:params][:"limit"] = limit
1517
+ end
1518
+ if next_page != nil
1519
+ _kwargs[:params][:"next_page"] = next_page
1520
+ end
1521
+ _http_client, _req_kwargs = self._client_with_auth(
1522
+ [:"bearerAuth", ],
1523
+ **_kwargs
1524
+ )
1525
+
1526
+
1527
+ _response = _http_client.post(
1528
+ _url,
1529
+ json: data,
1530
+ **_req_kwargs
1531
+ )
1532
+
1533
+ # Raise if not expected success code
1534
+ if _response.status != 200
1535
+ raise RequestError.new(
1536
+ method="post",
1537
+ url=_url,
1538
+ response=_response
1539
+ )
1540
+ end
1541
+
1542
+ return _response.body.empty? ? '' : _response.parse
1543
+ end
1544
+
1545
+ end