3scale-api 0.4.0 → 1.2.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/lib/3scale/api.rb +1 -0
- data/lib/3scale/api/client.rb +455 -26
- data/lib/3scale/api/errors.rb +12 -0
- data/lib/3scale/api/http_client.rb +24 -8
- data/lib/3scale/api/version.rb +1 -1
- metadata +6 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea3ac51993c3762a0a40625807148fdba4dbf390aa032bc97183f660220bf410
|
4
|
+
data.tar.gz: 3f5c198b2fbe44894007990f4f7e6d926400c4f89597acf9533a281c2fb77cd7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a5e4aff97c1716b24cdd5ba27385cf2babe88183dcc4894fcad0ca0df3e03df150e77fb80ff01485cca4bea47c4f6bade61a8c31aebdac8bd312aede6799af29
|
7
|
+
data.tar.gz: 2b86b756c210e5cc8270279d9f8ae258624ae6656594864d63d082b492b91b76e4c62a822ae6654243ba4585565acf6055906327303f71ec6e915b6603f22a16
|
data/lib/3scale/api.rb
CHANGED
data/lib/3scale/api/client.rb
CHANGED
@@ -32,10 +32,11 @@ module ThreeScale
|
|
32
32
|
end
|
33
33
|
|
34
34
|
# @api public
|
35
|
-
# @return [Array<Hash>]
|
36
35
|
# @param [Fixnum] service_id Service ID
|
37
|
-
|
38
|
-
|
36
|
+
# @param [Fixnum] plan_id Application Plan ID
|
37
|
+
# @return [Array<Hash>]
|
38
|
+
def list_applications(service_id: nil, plan_id: nil)
|
39
|
+
params = { service_id: service_id, plan_id: plan_id }.compact
|
39
40
|
response = http_client.get('/admin/api/applications', params: params)
|
40
41
|
extract(collection: 'applications', entity: 'application', from: response)
|
41
42
|
end
|
@@ -52,8 +53,13 @@ module ThreeScale
|
|
52
53
|
# @param [Fixnum] id Application ID
|
53
54
|
# @param [String] user_key Application User Key
|
54
55
|
# @param [String] application_id Application app_id
|
55
|
-
def find_application(id: nil, user_key: nil, application_id: nil)
|
56
|
-
params = {
|
56
|
+
def find_application(id: nil, user_key: nil, application_id: nil, service_id: nil)
|
57
|
+
params = {
|
58
|
+
application_id: id,
|
59
|
+
user_key: user_key,
|
60
|
+
app_id: application_id,
|
61
|
+
service_id: service_id,
|
62
|
+
}.compact
|
57
63
|
response = http_client.get('/admin/api/applications/find', params: params)
|
58
64
|
extract(entity: 'application', from: response)
|
59
65
|
end
|
@@ -73,6 +79,16 @@ module ThreeScale
|
|
73
79
|
extract(entity: 'application', from: response)
|
74
80
|
end
|
75
81
|
|
82
|
+
# @api public
|
83
|
+
# @param [Fixnum] account_id Account ID
|
84
|
+
# @param [Fixnum] id Application ID
|
85
|
+
# @param [Hash] attrs Application Attributes
|
86
|
+
# @return [Hash] an Application
|
87
|
+
def update_application(account_id, id, attrs)
|
88
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{id}", body: attrs)
|
89
|
+
extract(entity: 'application', from: response)
|
90
|
+
end
|
91
|
+
|
76
92
|
# @api public
|
77
93
|
# @return [Hash] a Plan
|
78
94
|
# @param [Fixnum] account_id Account ID
|
@@ -139,18 +155,40 @@ module ThreeScale
|
|
139
155
|
# @return [Hash]
|
140
156
|
# @param [Fixnum] service_id Service ID
|
141
157
|
# @param [String] environment. Must be 'sandbox' or 'production'
|
142
|
-
def proxy_config_list(service_id, environment='sandbox')
|
158
|
+
def proxy_config_list(service_id, environment = 'sandbox')
|
143
159
|
response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}")
|
144
|
-
extract(entity: '
|
160
|
+
extract(collection: 'proxy_configs', entity: 'proxy_config', from: response)
|
145
161
|
end
|
146
162
|
|
147
163
|
# @api public
|
148
164
|
# @return [Hash]
|
149
165
|
# @param [Fixnum] service_id Service ID
|
150
166
|
# @param [String] environment. Must be 'sandbox' or 'production'
|
151
|
-
def proxy_config_latest(service_id, environment='sandbox')
|
167
|
+
def proxy_config_latest(service_id, environment = 'sandbox')
|
152
168
|
response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/latest")
|
153
|
-
extract(entity: '
|
169
|
+
extract(entity: 'proxy_config', from: response)
|
170
|
+
end
|
171
|
+
|
172
|
+
# @api public
|
173
|
+
# @return [Hash]
|
174
|
+
# @param [Fixnum] service_id Service ID
|
175
|
+
# @param [String] environment. Must be 'sandbox' or 'production'
|
176
|
+
# @param [Fixnum] version Proxy configuration version
|
177
|
+
def show_proxy_config(service_id, environment, version)
|
178
|
+
response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}")
|
179
|
+
extract(entity: 'proxy_config', from: response)
|
180
|
+
end
|
181
|
+
|
182
|
+
# @api public
|
183
|
+
# @return [Hash]
|
184
|
+
# @param [Fixnum] service_id Service ID
|
185
|
+
# @param [String] environment Must be 'sandbox' or 'production'
|
186
|
+
# @param [Fixnum] version Version to promote
|
187
|
+
# @param [Fixnum] to To which the specified proxy configuration will be promoted to
|
188
|
+
def promote_proxy_config(service_id, environment, version, to)
|
189
|
+
response = http_client.post("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}/promote",
|
190
|
+
body: { to: to })
|
191
|
+
extract(entity: 'proxy_config', from: response)
|
154
192
|
end
|
155
193
|
|
156
194
|
# @api public
|
@@ -219,7 +257,7 @@ module ThreeScale
|
|
219
257
|
|
220
258
|
# @api public
|
221
259
|
# @param [Fixnum] service_id Service ID
|
222
|
-
# @param [Fixnum] id Metric ID
|
260
|
+
# @param [Fixnum] id Metric ID
|
223
261
|
# @return [Hash]
|
224
262
|
def show_metric(service_id, id)
|
225
263
|
response = http_client.get("/admin/api/services/#{service_id}/metrics/#{id}")
|
@@ -269,8 +307,8 @@ module ThreeScale
|
|
269
307
|
|
270
308
|
# @api public
|
271
309
|
# @param [Fixnum] service_id Service ID
|
272
|
-
# @param [Fixnum]
|
273
|
-
# @param [Fixnum] id Method ID
|
310
|
+
# @param [Fixnum] parent_id Parent metric ID
|
311
|
+
# @param [Fixnum] id Method ID
|
274
312
|
# @return [Hash]
|
275
313
|
def show_method(service_id, parent_id, id)
|
276
314
|
response = http_client.get("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
|
@@ -280,7 +318,7 @@ module ThreeScale
|
|
280
318
|
# @api public
|
281
319
|
# @return [Hash]
|
282
320
|
# @param [Fixnum] service_id Service ID
|
283
|
-
# @param [Fixnum] parent_id Parent metric ID
|
321
|
+
# @param [Fixnum] parent_id Parent metric ID
|
284
322
|
# @param [Fixnum] id Method ID
|
285
323
|
# @param [Hash] attributes Method Attributes
|
286
324
|
def update_method(service_id, parent_id, id, attributes)
|
@@ -313,14 +351,13 @@ module ThreeScale
|
|
313
351
|
# @api public
|
314
352
|
# @return [Bool]
|
315
353
|
# @param [Fixnum] service_id Service ID
|
316
|
-
# @param [Fixnum] parent_id Parent metric ID
|
317
|
-
# @param [Fixnum]
|
354
|
+
# @param [Fixnum] parent_id Parent metric ID
|
355
|
+
# @param [Fixnum] id Metric ID
|
318
356
|
def delete_method(service_id, parent_id, id)
|
319
357
|
http_client.delete("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
|
320
358
|
true
|
321
359
|
end
|
322
360
|
|
323
|
-
|
324
361
|
# @api public
|
325
362
|
# @param [Fixnum] application_plan_id Application Plan ID
|
326
363
|
# @param [Fixnum] metric_id Metric ID
|
@@ -351,7 +388,7 @@ module ThreeScale
|
|
351
388
|
end
|
352
389
|
|
353
390
|
# @api public
|
354
|
-
# @param [Fixnum]
|
391
|
+
# @param [Fixnum] service_id Service ID
|
355
392
|
# @param [Fixnum] id Application Plan ID
|
356
393
|
# @return [Hash]
|
357
394
|
def show_application_plan(service_id, id)
|
@@ -374,7 +411,7 @@ module ThreeScale
|
|
374
411
|
# @return [Bool]
|
375
412
|
# @param [Fixnum] service_id Service ID
|
376
413
|
# @param [Fixnum] application_plan_id Application Plan ID
|
377
|
-
def delete_application_plan(service_id,application_plan_id)
|
414
|
+
def delete_application_plan(service_id, application_plan_id)
|
378
415
|
http_client.delete("/admin/api/services/#{service_id}/application_plans/#{application_plan_id}")
|
379
416
|
true
|
380
417
|
end
|
@@ -416,7 +453,7 @@ module ThreeScale
|
|
416
453
|
# @param [Hash] attributes Limit Attributes
|
417
454
|
def update_application_plan_limit(application_plan_id, metric_id, limit_id, attributes)
|
418
455
|
response = http_client.put("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/limits/#{limit_id}",
|
419
|
-
|
456
|
+
body: { usage_limit: attributes })
|
420
457
|
extract(entity: 'limit', from: response)
|
421
458
|
end
|
422
459
|
|
@@ -429,13 +466,21 @@ module ThreeScale
|
|
429
466
|
end
|
430
467
|
|
431
468
|
# @api public
|
432
|
-
# @param [Hash]
|
469
|
+
# @param [Hash] criteria Search parameters
|
433
470
|
# @return [Hash]
|
434
471
|
def find_account(criteria)
|
435
472
|
response = http_client.get('/admin/api/accounts/find', params: criteria)
|
436
473
|
extract(entity: 'account', from: response)
|
437
474
|
end
|
438
475
|
|
476
|
+
# @api public
|
477
|
+
# @param [Fixnum] id Account Id
|
478
|
+
# @return [Hash]
|
479
|
+
def show_account(id)
|
480
|
+
response = http_client.get("/admin/api/accounts/#{id}")
|
481
|
+
extract(entity: 'account', from: response)
|
482
|
+
end
|
483
|
+
|
439
484
|
# @api public
|
440
485
|
# @return [Array]
|
441
486
|
# @param [Fixnum] id Service ID
|
@@ -477,6 +522,16 @@ module ThreeScale
|
|
477
522
|
extract(entity: 'pricing_rule', from: response)
|
478
523
|
end
|
479
524
|
|
525
|
+
# @api public
|
526
|
+
# @param [Fixnum] application_plan_id Application Plan ID
|
527
|
+
# @param [Fixnum] metric_id Metric ID
|
528
|
+
# @param [Fixnum] id Rule ID
|
529
|
+
# @return [Bool]
|
530
|
+
def delete_application_plan_pricingrule(application_plan_id, metric_id, id)
|
531
|
+
http_client.delete("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/pricing_rules/#{id}")
|
532
|
+
true
|
533
|
+
end
|
534
|
+
|
480
535
|
# @api public
|
481
536
|
# @return [Array<Hash>]
|
482
537
|
def list_activedocs
|
@@ -516,7 +571,7 @@ module ThreeScale
|
|
516
571
|
end
|
517
572
|
|
518
573
|
# @api public
|
519
|
-
# @param [Fixnum]
|
574
|
+
# @param [Fixnum] id Account ID
|
520
575
|
# @return [Bool]
|
521
576
|
def delete_account(id)
|
522
577
|
http_client.delete("/admin/api/accounts/#{id}")
|
@@ -525,15 +580,15 @@ module ThreeScale
|
|
525
580
|
|
526
581
|
# @api public
|
527
582
|
# @param [Fixnum] account_id Account ID
|
528
|
-
# @param [Fixnum]
|
583
|
+
# @param [Fixnum] id Application ID
|
529
584
|
# @return [Bool]
|
530
585
|
def delete_application(account_id, id)
|
531
586
|
http_client.delete("/admin/api/accounts/#{account_id}/applications/#{id}")
|
532
587
|
true
|
533
588
|
end
|
534
589
|
|
535
|
-
|
536
|
-
# @param [Fixnum]
|
590
|
+
# @api public
|
591
|
+
# @param [Fixnum] service_id Service ID
|
537
592
|
# @return [Array<Hash>]
|
538
593
|
def show_oidc(service_id)
|
539
594
|
response = http_client.get("/admin/api/services/#{service_id}/proxy/oidc_configuration")
|
@@ -541,7 +596,7 @@ module ThreeScale
|
|
541
596
|
end
|
542
597
|
|
543
598
|
# @api public
|
544
|
-
# @param [Fixnum]
|
599
|
+
# @param [Fixnum] service_id Service ID
|
545
600
|
# @return [Hash]
|
546
601
|
def update_oidc(service_id, attributes)
|
547
602
|
response = http_client.patch("/admin/api/services/#{service_id}/proxy/oidc_configuration",
|
@@ -590,7 +645,7 @@ module ThreeScale
|
|
590
645
|
# @return [Hash]
|
591
646
|
def create_service_feature(id, attributes)
|
592
647
|
response = http_client.post("/admin/api/services/#{id}/features",
|
593
|
-
body: { feature: attributes})
|
648
|
+
body: { feature: attributes })
|
594
649
|
extract(entity: 'feature', from: response)
|
595
650
|
end
|
596
651
|
|
@@ -623,6 +678,380 @@ module ThreeScale
|
|
623
678
|
true
|
624
679
|
end
|
625
680
|
|
681
|
+
# @api public
|
682
|
+
# @param [Fixnum] account_id Account ID
|
683
|
+
# @param [String] state State
|
684
|
+
# @param [String] role Role
|
685
|
+
# @return [Array<Hash>]
|
686
|
+
def list_users(account_id, state: nil, role: nil)
|
687
|
+
params = { state: state, role: role }.reject { |_, value| value.nil? }
|
688
|
+
response = http_client.get("/admin/api/accounts/#{account_id}/users", params: params)
|
689
|
+
extract(collection: 'users', entity: 'user', from: response)
|
690
|
+
end
|
691
|
+
|
692
|
+
# @api public
|
693
|
+
# @param [String] account_id Account ID
|
694
|
+
# @param [String] email User email
|
695
|
+
# @param [String] username User Username
|
696
|
+
# @param [String] password User password
|
697
|
+
# @param [Hash] attributes User Attributes
|
698
|
+
# @return [Hash]
|
699
|
+
def create_user(account_id:, email:, username:, password:, **rest)
|
700
|
+
body = { email: email, username: username, password: password }.merge(rest)
|
701
|
+
response = http_client.post("/admin/api/accounts/#{account_id}/users", body: body)
|
702
|
+
extract(entity: 'user', from: response)
|
703
|
+
end
|
704
|
+
|
705
|
+
# @api public
|
706
|
+
# @param [String] account_id Account ID
|
707
|
+
# @param [String] user_id User ID
|
708
|
+
# @return [Hash]
|
709
|
+
def activate_user(account_id, user_id)
|
710
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/users/#{user_id}/activate")
|
711
|
+
extract(entity: 'user', from: response)
|
712
|
+
end
|
713
|
+
|
714
|
+
# @api public
|
715
|
+
# @param [String] account_id Account ID
|
716
|
+
# @return [Hash]
|
717
|
+
def approve_account(account_id)
|
718
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/approve")
|
719
|
+
extract(entity: 'account', from: response)
|
720
|
+
end
|
721
|
+
|
722
|
+
# @api public
|
723
|
+
# @param [String] account_id Account ID
|
724
|
+
# @return [Array<Hash>]
|
725
|
+
def list_account_applications(account_id)
|
726
|
+
response = http_client.get("/admin/api/accounts/#{account_id}/applications")
|
727
|
+
extract(collection: 'applications', entity: 'application', from: response)
|
728
|
+
end
|
729
|
+
|
730
|
+
# @api public
|
731
|
+
# @return [Array<Hash]
|
732
|
+
def list_application_plans
|
733
|
+
response = http_client.get("/admin/api/application_plans")
|
734
|
+
extract(collection: 'plans', entity: 'application_plan', from: response)
|
735
|
+
end
|
736
|
+
|
737
|
+
# @api public
|
738
|
+
# @param [String] account_id Account ID
|
739
|
+
# @param [String] application_id Application ID
|
740
|
+
# @return [Array<Hash>]
|
741
|
+
def list_application_keys(account_id, application_id)
|
742
|
+
response = http_client.get("/admin/api/accounts/#{account_id}/applications/#{application_id}/keys")
|
743
|
+
extract(collection: 'keys', entity: 'key', from: response)
|
744
|
+
end
|
745
|
+
|
746
|
+
# @api public
|
747
|
+
# @param [String] account_id Account ID
|
748
|
+
# @param [String] application_id Application ID
|
749
|
+
# @param [String] key Key
|
750
|
+
# @return [Hash]
|
751
|
+
def create_application_key(account_id, application_id, key)
|
752
|
+
response = http_client.post("/admin/api/accounts/#{account_id}/applications/#{application_id}/keys", body: {key: key})
|
753
|
+
extract(entity: 'application', from: response)
|
754
|
+
end
|
755
|
+
|
756
|
+
# @api public
|
757
|
+
# @param [String] account_id Account ID
|
758
|
+
# @param [String] application_id Application ID
|
759
|
+
# @return [Hash] application Application
|
760
|
+
def accept_application(account_id, application_id)
|
761
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/accept")
|
762
|
+
extract(entity: 'application', from: response)
|
763
|
+
end
|
764
|
+
|
765
|
+
# @api public
|
766
|
+
# @param [String] account_id Account ID
|
767
|
+
# @param [String] application_id Application ID
|
768
|
+
# @return [Hash] application Application
|
769
|
+
def suspend_application(account_id, application_id)
|
770
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/suspend")
|
771
|
+
extract(entity: 'application', from: response)
|
772
|
+
end
|
773
|
+
|
774
|
+
# @api public
|
775
|
+
# @param [String] account_id Account ID
|
776
|
+
# @param [String] application_id Application ID
|
777
|
+
# @return [Hash] application Application
|
778
|
+
def resume_application(account_id, application_id)
|
779
|
+
response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/resume")
|
780
|
+
extract(entity: 'application', from: response)
|
781
|
+
end
|
782
|
+
|
783
|
+
# @api public
|
784
|
+
# @return [Array<Hash>]
|
785
|
+
def list_policy_registry
|
786
|
+
response = http_client.get('/admin/api/registry/policies')
|
787
|
+
extract(collection: 'policies', entity: 'policy', from: response)
|
788
|
+
end
|
789
|
+
|
790
|
+
# @api public
|
791
|
+
# @param [Hash] attributes Policy Registry Attributes
|
792
|
+
# @return [Hash]
|
793
|
+
def create_policy_registry(attributes)
|
794
|
+
response = http_client.post('/admin/api/registry/policies', body: attributes)
|
795
|
+
extract(entity: 'policy', from: response)
|
796
|
+
end
|
797
|
+
|
798
|
+
# @api public
|
799
|
+
# @return [Hash]
|
800
|
+
# @param [Fixnum] id Policy Registry Id
|
801
|
+
def show_policy_registry(id)
|
802
|
+
response = http_client.get("/admin/api/registry/policies/#{id}")
|
803
|
+
extract(entity: 'policy', from: response)
|
804
|
+
end
|
805
|
+
|
806
|
+
# @api public
|
807
|
+
# @return [Hash]
|
808
|
+
# @param [Fixnum] id Policy Registry Id
|
809
|
+
# @param [Hash] attributes Policy Registry Attributes
|
810
|
+
def update_policy_registry(id, attributes)
|
811
|
+
response = http_client.put("/admin/api/registry/policies/#{id}", body: attributes)
|
812
|
+
extract(entity: 'policy', from: response)
|
813
|
+
end
|
814
|
+
|
815
|
+
# @api public
|
816
|
+
# @param [Fixnum] id Policy Registry Id
|
817
|
+
def delete_policy_registry(id)
|
818
|
+
http_client.delete("/admin/api/registry/policies/#{id}")
|
819
|
+
true
|
820
|
+
end
|
821
|
+
|
822
|
+
# @api public
|
823
|
+
# @return [Hash]
|
824
|
+
def show_provider
|
825
|
+
response = http_client.get('/admin/api/provider')
|
826
|
+
extract(entity: 'account', from: response)
|
827
|
+
end
|
828
|
+
|
829
|
+
# @api public
|
830
|
+
# @return [List]
|
831
|
+
def list_backends
|
832
|
+
response = http_client.get('/admin/api/backend_apis')
|
833
|
+
extract(collection: 'backend_apis', entity: 'backend_api', from: response)
|
834
|
+
end
|
835
|
+
|
836
|
+
# @api public
|
837
|
+
# @param [Hash] attributes Backend attributes
|
838
|
+
# @return [Hash]
|
839
|
+
def create_backend(attributes)
|
840
|
+
response = http_client.post('/admin/api/backend_apis', body: attributes)
|
841
|
+
extract(entity: 'backend_api', from: response)
|
842
|
+
end
|
843
|
+
|
844
|
+
# @api public
|
845
|
+
# @param [Fixnum] id Backend ID
|
846
|
+
def delete_backend(id)
|
847
|
+
http_client.delete("/admin/api/backend_apis/#{id}")
|
848
|
+
true
|
849
|
+
end
|
850
|
+
|
851
|
+
# @api public
|
852
|
+
# @param [Fixnum] id Backend ID
|
853
|
+
# @return [Hash]
|
854
|
+
def backend(id)
|
855
|
+
response = http_client.get("/admin/api/backend_apis/#{id}")
|
856
|
+
extract(entity: 'backend_api', from: response)
|
857
|
+
end
|
858
|
+
|
859
|
+
# @api public
|
860
|
+
# @param [Fixnum] id Backend ID
|
861
|
+
# @param [Hash] attributes Backend attributes
|
862
|
+
# @return [Hash]
|
863
|
+
def update_backend(id, attributes)
|
864
|
+
response = http_client.put("/admin/api/backend_apis/#{id}", body: attributes)
|
865
|
+
extract(entity: 'backend_api', from: response)
|
866
|
+
end
|
867
|
+
|
868
|
+
# @api public
|
869
|
+
# @param [Fixnum] id Backend ID
|
870
|
+
# @return [List]
|
871
|
+
def list_backend_metrics(id)
|
872
|
+
response = http_client.get("/admin/api/backend_apis/#{id}/metrics")
|
873
|
+
extract(collection: 'metrics', entity: 'metric', from: response)
|
874
|
+
end
|
875
|
+
|
876
|
+
# @api public
|
877
|
+
# @param [Fixnum] id Backend ID
|
878
|
+
# @param [Hash] attributes Metric attributes
|
879
|
+
# @return [Hash]
|
880
|
+
def create_backend_metric(id, attrs)
|
881
|
+
response = http_client.post("/admin/api/backend_apis/#{id}/metrics", body: attrs)
|
882
|
+
extract(entity: 'metric', from: response)
|
883
|
+
end
|
884
|
+
|
885
|
+
# @api public
|
886
|
+
# @param [Fixnum] backend_id Backend ID
|
887
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
888
|
+
def delete_backend_metric(backend_id, metric_id)
|
889
|
+
http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
|
890
|
+
true
|
891
|
+
end
|
892
|
+
|
893
|
+
# @api public
|
894
|
+
# @param [Fixnum] backend_id Backend ID
|
895
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
896
|
+
# @return [Hash]
|
897
|
+
def backend_metric(backend_id, metric_id)
|
898
|
+
response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
|
899
|
+
extract(entity: 'metric', from: response)
|
900
|
+
end
|
901
|
+
|
902
|
+
# @api public
|
903
|
+
# @param [Fixnum] backend_id Backend ID
|
904
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
905
|
+
# @param [Hash] attributes Backend attributes
|
906
|
+
# @return [Hash]
|
907
|
+
def update_backend_metric(backend_id, metric_id, attributes)
|
908
|
+
response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}", body: attributes)
|
909
|
+
extract(entity: 'metric', from: response)
|
910
|
+
end
|
911
|
+
|
912
|
+
# @api public
|
913
|
+
# @param [Fixnum] backend_id Backend ID
|
914
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
915
|
+
# @return [List]
|
916
|
+
def list_backend_methods(backend_id, metric_id)
|
917
|
+
response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods")
|
918
|
+
extract(collection: 'methods', entity: 'method', from: response)
|
919
|
+
end
|
920
|
+
|
921
|
+
# @api public
|
922
|
+
# @param [Fixnum] backend_id Backend ID
|
923
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
924
|
+
# @param [Hash] attributes Metric attributes
|
925
|
+
# @return [Hash]
|
926
|
+
def create_backend_method(backend_id, metric_id, attrs)
|
927
|
+
response = http_client.post("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods",
|
928
|
+
body: attrs)
|
929
|
+
extract(entity: 'method', from: response)
|
930
|
+
end
|
931
|
+
|
932
|
+
# @api public
|
933
|
+
# @param [Fixnum] backend_id Backend ID
|
934
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
935
|
+
# @param [Fixnum] method_id Backend Method ID
|
936
|
+
def delete_backend_method(backend_id, metric_id, method_id)
|
937
|
+
http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
|
938
|
+
true
|
939
|
+
end
|
940
|
+
|
941
|
+
# @api public
|
942
|
+
# @param [Fixnum] backend_id Backend ID
|
943
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
944
|
+
# @param [Fixnum] method_id Backend Method ID
|
945
|
+
# @return [Hash]
|
946
|
+
def backend_method(backend_id, metric_id, method_id)
|
947
|
+
response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
|
948
|
+
extract(entity: 'method', from: response)
|
949
|
+
end
|
950
|
+
|
951
|
+
# @api public
|
952
|
+
# @param [Fixnum] backend_id Backend ID
|
953
|
+
# @param [Fixnum] metric_id Backend Metric ID
|
954
|
+
# @param [Fixnum] method_id Backend Method ID
|
955
|
+
# @param [Hash] attributes Backend attributes
|
956
|
+
# @return [Hash]
|
957
|
+
def update_backend_method(backend_id, metric_id, method_id, attributes)
|
958
|
+
response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}",
|
959
|
+
body: attributes)
|
960
|
+
extract(entity: 'method', from: response)
|
961
|
+
end
|
962
|
+
|
963
|
+
# @api public
|
964
|
+
# @param [Fixnum] backend_id Backend ID
|
965
|
+
# @return [List]
|
966
|
+
def list_backend_mapping_rules(backend_id)
|
967
|
+
response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules")
|
968
|
+
extract(collection: 'mapping_rules', entity: 'mapping_rule', from: response)
|
969
|
+
end
|
970
|
+
|
971
|
+
# @api public
|
972
|
+
# @param [Fixnum] backend_id Backend ID
|
973
|
+
# @param [Hash] attrs Metric attributes
|
974
|
+
# @return [Hash]
|
975
|
+
def create_backend_mapping_rule(backend_id, attrs)
|
976
|
+
response = http_client.post("/admin/api/backend_apis/#{backend_id}/mapping_rules",
|
977
|
+
body: attrs)
|
978
|
+
extract(entity: 'mapping_rule', from: response)
|
979
|
+
end
|
980
|
+
|
981
|
+
# @api public
|
982
|
+
# @param [Fixnum] backend_id Backend ID
|
983
|
+
# @param [Fixnum] mapping_rule_id MappingRule ID
|
984
|
+
def delete_backend_mapping_rule(backend_id, mapping_rule_id)
|
985
|
+
http_client.delete("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
|
986
|
+
true
|
987
|
+
end
|
988
|
+
|
989
|
+
# @api public
|
990
|
+
# @param [Fixnum] backend_id Backend ID
|
991
|
+
# @param [Fixnum] mapping_rule_id MappingRule ID
|
992
|
+
# @return [Hash]
|
993
|
+
def backend_mapping_rule(backend_id, mapping_rule_id)
|
994
|
+
response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
|
995
|
+
extract(entity: 'mapping_rule', from: response)
|
996
|
+
end
|
997
|
+
|
998
|
+
# @api public
|
999
|
+
# @param [Fixnum] backend_id Backend ID
|
1000
|
+
# @param [Fixnum] mapping_rule_id MappingRule ID
|
1001
|
+
# @param [Hash] attributes Backend attributes
|
1002
|
+
# @return [Hash]
|
1003
|
+
def update_backend_mapping_rule(backend_id, mapping_rule_id, attributes)
|
1004
|
+
response = http_client.put("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}",
|
1005
|
+
body: attributes)
|
1006
|
+
extract(entity: 'mapping_rule', from: response)
|
1007
|
+
end
|
1008
|
+
|
1009
|
+
# @api public
|
1010
|
+
# @param [Fixnum] product_id Product ID
|
1011
|
+
# @return [List]
|
1012
|
+
def list_backend_usages(product_id)
|
1013
|
+
response = http_client.get("/admin/api/services/#{product_id}/backend_usages")
|
1014
|
+
extract(entity: 'backend_usage', from: response)
|
1015
|
+
end
|
1016
|
+
|
1017
|
+
# @api public
|
1018
|
+
# @param [Fixnum] product_id Product ID
|
1019
|
+
# @param [Hash] attrs Backend Usage attributes
|
1020
|
+
# @return [Hash]
|
1021
|
+
def create_backend_usage(product_id, attrs)
|
1022
|
+
response = http_client.post("/admin/api/services/#{product_id}/backend_usages",
|
1023
|
+
body: attrs)
|
1024
|
+
extract(entity: 'backend_usage', from: response)
|
1025
|
+
end
|
1026
|
+
|
1027
|
+
# @api public
|
1028
|
+
# @param [Fixnum] product_id Product ID
|
1029
|
+
# @param [Fixnum] id Backend Usage ID
|
1030
|
+
def delete_backend_usage(product_id, id)
|
1031
|
+
http_client.delete("/admin/api/services/#{product_id}/backend_usages/#{id}")
|
1032
|
+
true
|
1033
|
+
end
|
1034
|
+
|
1035
|
+
# @api public
|
1036
|
+
# @param [Fixnum] product_id Product ID
|
1037
|
+
# @param [Fixnum] id Backend Usage ID
|
1038
|
+
# @return [Hash]
|
1039
|
+
def backend_usage(product_id, id)
|
1040
|
+
response = http_client.get("/admin/api/services/#{product_id}/backend_usages/#{id}")
|
1041
|
+
extract(entity: 'backend_usage', from: response)
|
1042
|
+
end
|
1043
|
+
|
1044
|
+
# @api public
|
1045
|
+
# @param [Fixnum] product_id Product ID
|
1046
|
+
# @param [Fixnum] id Backend Usage ID
|
1047
|
+
# @param [Hash] attrs Backend Usage attributes
|
1048
|
+
# @return [Hash]
|
1049
|
+
def update_backend_usage(product_id, id, attrs)
|
1050
|
+
response = http_client.put("/admin/api/services/#{product_id}/backend_usages/#{id}",
|
1051
|
+
body: attrs)
|
1052
|
+
extract(entity: 'backend_usage', from: response)
|
1053
|
+
end
|
1054
|
+
|
626
1055
|
protected
|
627
1056
|
|
628
1057
|
def extract(collection: nil, entity:, from:)
|
@@ -58,26 +58,32 @@ module ThreeScale
|
|
58
58
|
when Net::HTTPUnprocessableEntity, Net::HTTPSuccess then parser.decode(response.body)
|
59
59
|
when Net::HTTPForbidden then forbidden!(response)
|
60
60
|
when Net::HTTPNotFound then notfound!(response)
|
61
|
-
else unexpected!(response
|
61
|
+
else unexpected!(response)
|
62
62
|
end
|
63
63
|
end
|
64
64
|
|
65
|
-
class ForbiddenError <
|
65
|
+
class ForbiddenError < ResponseError; end
|
66
66
|
|
67
|
-
class UnexpectedResponseError <
|
67
|
+
class UnexpectedResponseError < ResponseError; end
|
68
68
|
|
69
|
-
class NotFoundError <
|
69
|
+
class NotFoundError < ResponseError; end
|
70
|
+
|
71
|
+
class UnknownFormatError < StandardError; end
|
70
72
|
|
71
73
|
def forbidden!(response)
|
72
|
-
raise ForbiddenError, response
|
74
|
+
raise ForbiddenError.new(response, format_response(response))
|
73
75
|
end
|
74
76
|
|
75
77
|
def notfound!(response)
|
76
|
-
raise NotFoundError, response
|
78
|
+
raise NotFoundError.new(response, format_response(response))
|
77
79
|
end
|
78
80
|
|
79
81
|
def unexpected!(response)
|
80
|
-
raise UnexpectedResponseError, response
|
82
|
+
raise UnexpectedResponseError.new(response, format_response(response))
|
83
|
+
end
|
84
|
+
|
85
|
+
def unknownformat!
|
86
|
+
raise UnknownFormatError, "unknown format #{format}"
|
81
87
|
end
|
82
88
|
|
83
89
|
def serialize(body)
|
@@ -91,7 +97,7 @@ module ThreeScale
|
|
91
97
|
def parser
|
92
98
|
case format
|
93
99
|
when :json then JSONParser
|
94
|
-
else
|
100
|
+
else unknownformat!
|
95
101
|
end
|
96
102
|
end
|
97
103
|
|
@@ -108,6 +114,16 @@ module ThreeScale
|
|
108
114
|
path
|
109
115
|
end
|
110
116
|
|
117
|
+
def format_response(response)
|
118
|
+
body = response.body if text_based?(response)
|
119
|
+
"#{response.inspect} body=#{body}"
|
120
|
+
end
|
121
|
+
|
122
|
+
def text_based?(response)
|
123
|
+
response.content_type =~ /^text/ ||
|
124
|
+
response.content_type =~ /^application/ && !['application/octet-stream', 'application/pdf'].include?(response.content_type)
|
125
|
+
end
|
126
|
+
|
111
127
|
module JSONParser
|
112
128
|
module_function
|
113
129
|
|
data/lib/3scale/api/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: 3scale-api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version:
|
4
|
+
version: 1.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Michal Cichra
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: exe
|
11
11
|
cert_chain: []
|
12
|
-
date:
|
12
|
+
date: 2020-11-02 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: bundler
|
@@ -31,14 +31,14 @@ dependencies:
|
|
31
31
|
requirements:
|
32
32
|
- - "~>"
|
33
33
|
- !ruby/object:Gem::Version
|
34
|
-
version: '
|
34
|
+
version: '13.0'
|
35
35
|
type: :development
|
36
36
|
prerelease: false
|
37
37
|
version_requirements: !ruby/object:Gem::Requirement
|
38
38
|
requirements:
|
39
39
|
- - "~>"
|
40
40
|
- !ruby/object:Gem::Version
|
41
|
-
version: '
|
41
|
+
version: '13.0'
|
42
42
|
- !ruby/object:Gem::Dependency
|
43
43
|
name: rspec
|
44
44
|
requirement: !ruby/object:Gem::Requirement
|
@@ -78,6 +78,7 @@ files:
|
|
78
78
|
- README.md
|
79
79
|
- lib/3scale/api.rb
|
80
80
|
- lib/3scale/api/client.rb
|
81
|
+
- lib/3scale/api/errors.rb
|
81
82
|
- lib/3scale/api/http_client.rb
|
82
83
|
- lib/3scale/api/version.rb
|
83
84
|
- lib/three_scale/api.rb
|
@@ -100,8 +101,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
100
101
|
- !ruby/object:Gem::Version
|
101
102
|
version: '0'
|
102
103
|
requirements: []
|
103
|
-
|
104
|
-
rubygems_version: 2.7.6
|
104
|
+
rubygems_version: 3.1.2
|
105
105
|
signing_key:
|
106
106
|
specification_version: 4
|
107
107
|
summary: API Client for 3scale APIs
|