3scale-api 0.6.0 → 1.4.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 81f6650cb30804268729027455963486ade4f7009cd7067481e0aa898174edad
4
- data.tar.gz: 865ca95ae08a08d6558460256abe123e895cbb0dc291f5ff2035bae2722ae251
3
+ metadata.gz: 6acc1c28076fb874303586e42676f43af59d189a848e6dbb9beea439397c099d
4
+ data.tar.gz: 2901c2493c186e4649a54193f86da93e1a09e928fdfe05dde717148b37aabcfe
5
5
  SHA512:
6
- metadata.gz: 5a9e0a4b84571fab32f61f9db8e332924fdf86c219bf976fa82fef39ca3d4b82a896becd7c4f6079d3f45c400a8142f71ee94ad045d4a7ba577a7d2e26914fcf
7
- data.tar.gz: c4676676ba01ef337764202ebe0da7ef824e0b573c9e05a5095600b58266c9af60f6365a3f51355f3154ed162f675bc6d55a41dd61a29581a463660da2be8fec
6
+ metadata.gz: ad1b19c06a705bc370c2fa0362ab894f89e666f1fce9d24d42bccf7538640962fc8be201c1c65c1b70bf61c7c2d4f25550e93c22cd9f1bf3256f8989200cacb7
7
+ data.tar.gz: 100e91d761590d54b6ff9c96884586e96cc027f9e497f462ff9c00d244bba2febe78162d3f2dce0f1341efb777e379abc1dbc8e2d170017daa53bfbfd81a80ac
@@ -1,4 +1,5 @@
1
1
  require '3scale/api/version'
2
+ require '3scale/api/errors'
2
3
 
3
4
  module ThreeScale
4
5
  module API
@@ -1,5 +1,8 @@
1
1
  module ThreeScale
2
2
  module API
3
+ MAX_BACKENDS_PER_PAGE = 500
4
+ MAX_SERVICES_PER_PAGE = 500
5
+
3
6
  class Client
4
7
  attr_reader :http_client
5
8
 
@@ -19,8 +22,8 @@ module ThreeScale
19
22
 
20
23
  # @api public
21
24
  # @return [Array<Hash>]
22
- def list_services
23
- response = http_client.get('/admin/api/services')
25
+ def list_services(params = nil)
26
+ response = http_client.get('/admin/api/services', params: params)
24
27
  extract(collection: 'services', entity: 'service', from: response)
25
28
  end
26
29
 
@@ -173,7 +176,7 @@ module ThreeScale
173
176
  # @return [Hash]
174
177
  # @param [Fixnum] service_id Service ID
175
178
  # @param [String] environment. Must be 'sandbox' or 'production'
176
- # @param [Fixnum] proxy configuration version
179
+ # @param [Fixnum] version Proxy configuration version
177
180
  def show_proxy_config(service_id, environment, version)
178
181
  response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}")
179
182
  extract(entity: 'proxy_config', from: response)
@@ -182,9 +185,9 @@ module ThreeScale
182
185
  # @api public
183
186
  # @return [Hash]
184
187
  # @param [Fixnum] service_id Service ID
185
- # @param [String] environment. Must be 'sandbox' or 'production'
186
- # @param [Fixnum] proxy configuration version to promote
187
- # @param [Fixnum] proxy configuration to which the specified proxy configuration will be promoted to
188
+ # @param [String] environment Must be 'sandbox' or 'production'
189
+ # @param [Fixnum] version Version to promote
190
+ # @param [Fixnum] to To which the specified proxy configuration will be promoted to
188
191
  def promote_proxy_config(service_id, environment, version, to)
189
192
  response = http_client.post("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}/promote",
190
193
  body: { to: to })
@@ -200,6 +203,15 @@ module ThreeScale
200
203
  extract(entity: 'proxy', from: response)
201
204
  end
202
205
 
206
+ # @api public
207
+ # @return [Hash]
208
+ # @param [Fixnum] service_id Service ID
209
+ def proxy_deploy(service_id)
210
+ response = http_client.post("/admin/api/services/#{service_id}/proxy/deploy",
211
+ body: nil)
212
+ extract(entity: 'proxy', from: response)
213
+ end
214
+
203
215
  # @api public
204
216
  # @return [Array<Hash>]
205
217
  # @param [Fixnum] service_id Service ID
@@ -307,7 +319,7 @@ module ThreeScale
307
319
 
308
320
  # @api public
309
321
  # @param [Fixnum] service_id Service ID
310
- # @param [Fixnum] id Parent metric ID
322
+ # @param [Fixnum] parent_id Parent metric ID
311
323
  # @param [Fixnum] id Method ID
312
324
  # @return [Hash]
313
325
  def show_method(service_id, parent_id, id)
@@ -352,7 +364,7 @@ module ThreeScale
352
364
  # @return [Bool]
353
365
  # @param [Fixnum] service_id Service ID
354
366
  # @param [Fixnum] parent_id Parent metric ID
355
- # @param [Fixnum] metric_id Metric ID
367
+ # @param [Fixnum] id Metric ID
356
368
  def delete_method(service_id, parent_id, id)
357
369
  http_client.delete("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
358
370
  true
@@ -388,7 +400,7 @@ module ThreeScale
388
400
  end
389
401
 
390
402
  # @api public
391
- # @param [Fixnum] id Service ID
403
+ # @param [Fixnum] service_id Service ID
392
404
  # @param [Fixnum] id Application Plan ID
393
405
  # @return [Hash]
394
406
  def show_application_plan(service_id, id)
@@ -466,7 +478,7 @@ module ThreeScale
466
478
  end
467
479
 
468
480
  # @api public
469
- # @param [Hash] account criteria
481
+ # @param [Hash] criteria Search parameters
470
482
  # @return [Hash]
471
483
  def find_account(criteria)
472
484
  response = http_client.get('/admin/api/accounts/find', params: criteria)
@@ -522,6 +534,16 @@ module ThreeScale
522
534
  extract(entity: 'pricing_rule', from: response)
523
535
  end
524
536
 
537
+ # @api public
538
+ # @param [Fixnum] application_plan_id Application Plan ID
539
+ # @param [Fixnum] metric_id Metric ID
540
+ # @param [Fixnum] id Rule ID
541
+ # @return [Bool]
542
+ def delete_application_plan_pricingrule(application_plan_id, metric_id, id)
543
+ http_client.delete("/admin/api/application_plans/#{application_plan_id}/metrics/#{metric_id}/pricing_rules/#{id}")
544
+ true
545
+ end
546
+
525
547
  # @api public
526
548
  # @return [Array<Hash>]
527
549
  def list_activedocs
@@ -561,7 +583,7 @@ module ThreeScale
561
583
  end
562
584
 
563
585
  # @api public
564
- # @param [Fixnum] account_id Account ID
586
+ # @param [Fixnum] id Account ID
565
587
  # @return [Bool]
566
588
  def delete_account(id)
567
589
  http_client.delete("/admin/api/accounts/#{id}")
@@ -570,7 +592,7 @@ module ThreeScale
570
592
 
571
593
  # @api public
572
594
  # @param [Fixnum] account_id Account ID
573
- # @param [Fixnum] application_id Application ID
595
+ # @param [Fixnum] id Application ID
574
596
  # @return [Bool]
575
597
  def delete_application(account_id, id)
576
598
  http_client.delete("/admin/api/accounts/#{account_id}/applications/#{id}")
@@ -578,7 +600,7 @@ module ThreeScale
578
600
  end
579
601
 
580
602
  # @api public
581
- # @param [Fixnum] id Service ID
603
+ # @param [Fixnum] service_id Service ID
582
604
  # @return [Array<Hash>]
583
605
  def show_oidc(service_id)
584
606
  response = http_client.get("/admin/api/services/#{service_id}/proxy/oidc_configuration")
@@ -586,7 +608,7 @@ module ThreeScale
586
608
  end
587
609
 
588
610
  # @api public
589
- # @param [Fixnum] id Service ID
611
+ # @param [Fixnum] service_id Service ID
590
612
  # @return [Hash]
591
613
  def update_oidc(service_id, attributes)
592
614
  response = http_client.patch("/admin/api/services/#{service_id}/proxy/oidc_configuration",
@@ -717,7 +739,7 @@ module ThreeScale
717
739
  extract(collection: 'applications', entity: 'application', from: response)
718
740
  end
719
741
 
720
- # @api public
742
+ # @api public
721
743
  # @return [Array<Hash]
722
744
  def list_application_plans
723
745
  response = http_client.get("/admin/api/application_plans")
@@ -760,7 +782,7 @@ module ThreeScale
760
782
  response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/suspend")
761
783
  extract(entity: 'application', from: response)
762
784
  end
763
-
785
+
764
786
  # @api public
765
787
  # @param [String] account_id Account ID
766
788
  # @param [String] application_id Application ID
@@ -816,6 +838,232 @@ module ThreeScale
816
838
  extract(entity: 'account', from: response)
817
839
  end
818
840
 
841
+ # @api public
842
+ # @return [List]
843
+ def list_backends(params = nil)
844
+ response = http_client.get('/admin/api/backend_apis', params: params)
845
+ extract(collection: 'backend_apis', entity: 'backend_api', from: response)
846
+ end
847
+
848
+ # @api public
849
+ # @param [Hash] attributes Backend attributes
850
+ # @return [Hash]
851
+ def create_backend(attributes)
852
+ response = http_client.post('/admin/api/backend_apis', body: attributes)
853
+ extract(entity: 'backend_api', from: response)
854
+ end
855
+
856
+ # @api public
857
+ # @param [Fixnum] id Backend ID
858
+ def delete_backend(id)
859
+ http_client.delete("/admin/api/backend_apis/#{id}")
860
+ true
861
+ end
862
+
863
+ # @api public
864
+ # @param [Fixnum] id Backend ID
865
+ # @return [Hash]
866
+ def backend(id)
867
+ response = http_client.get("/admin/api/backend_apis/#{id}")
868
+ extract(entity: 'backend_api', from: response)
869
+ end
870
+
871
+ # @api public
872
+ # @param [Fixnum] id Backend ID
873
+ # @param [Hash] attributes Backend attributes
874
+ # @return [Hash]
875
+ def update_backend(id, attributes)
876
+ response = http_client.put("/admin/api/backend_apis/#{id}", body: attributes)
877
+ extract(entity: 'backend_api', from: response)
878
+ end
879
+
880
+ # @api public
881
+ # @param [Fixnum] id Backend ID
882
+ # @return [List]
883
+ def list_backend_metrics(id)
884
+ response = http_client.get("/admin/api/backend_apis/#{id}/metrics")
885
+ extract(collection: 'metrics', entity: 'metric', from: response)
886
+ end
887
+
888
+ # @api public
889
+ # @param [Fixnum] id Backend ID
890
+ # @param [Hash] attributes Metric attributes
891
+ # @return [Hash]
892
+ def create_backend_metric(id, attrs)
893
+ response = http_client.post("/admin/api/backend_apis/#{id}/metrics", body: attrs)
894
+ extract(entity: 'metric', from: response)
895
+ end
896
+
897
+ # @api public
898
+ # @param [Fixnum] backend_id Backend ID
899
+ # @param [Fixnum] metric_id Backend Metric ID
900
+ def delete_backend_metric(backend_id, metric_id)
901
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
902
+ true
903
+ end
904
+
905
+ # @api public
906
+ # @param [Fixnum] backend_id Backend ID
907
+ # @param [Fixnum] metric_id Backend Metric ID
908
+ # @return [Hash]
909
+ def backend_metric(backend_id, metric_id)
910
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
911
+ extract(entity: 'metric', from: response)
912
+ end
913
+
914
+ # @api public
915
+ # @param [Fixnum] backend_id Backend ID
916
+ # @param [Fixnum] metric_id Backend Metric ID
917
+ # @param [Hash] attributes Backend attributes
918
+ # @return [Hash]
919
+ def update_backend_metric(backend_id, metric_id, attributes)
920
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}", body: attributes)
921
+ extract(entity: 'metric', from: response)
922
+ end
923
+
924
+ # @api public
925
+ # @param [Fixnum] backend_id Backend ID
926
+ # @param [Fixnum] metric_id Backend Metric ID
927
+ # @return [List]
928
+ def list_backend_methods(backend_id, metric_id)
929
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods")
930
+ extract(collection: 'methods', entity: 'method', from: response)
931
+ end
932
+
933
+ # @api public
934
+ # @param [Fixnum] backend_id Backend ID
935
+ # @param [Fixnum] metric_id Backend Metric ID
936
+ # @param [Hash] attributes Metric attributes
937
+ # @return [Hash]
938
+ def create_backend_method(backend_id, metric_id, attrs)
939
+ response = http_client.post("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods",
940
+ body: attrs)
941
+ extract(entity: 'method', from: response)
942
+ end
943
+
944
+ # @api public
945
+ # @param [Fixnum] backend_id Backend ID
946
+ # @param [Fixnum] metric_id Backend Metric ID
947
+ # @param [Fixnum] method_id Backend Method ID
948
+ def delete_backend_method(backend_id, metric_id, method_id)
949
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
950
+ true
951
+ end
952
+
953
+ # @api public
954
+ # @param [Fixnum] backend_id Backend ID
955
+ # @param [Fixnum] metric_id Backend Metric ID
956
+ # @param [Fixnum] method_id Backend Method ID
957
+ # @return [Hash]
958
+ def backend_method(backend_id, metric_id, method_id)
959
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
960
+ extract(entity: 'method', from: response)
961
+ end
962
+
963
+ # @api public
964
+ # @param [Fixnum] backend_id Backend ID
965
+ # @param [Fixnum] metric_id Backend Metric ID
966
+ # @param [Fixnum] method_id Backend Method ID
967
+ # @param [Hash] attributes Backend attributes
968
+ # @return [Hash]
969
+ def update_backend_method(backend_id, metric_id, method_id, attributes)
970
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}",
971
+ body: attributes)
972
+ extract(entity: 'method', from: response)
973
+ end
974
+
975
+ # @api public
976
+ # @param [Fixnum] backend_id Backend ID
977
+ # @return [List]
978
+ def list_backend_mapping_rules(backend_id)
979
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules")
980
+ extract(collection: 'mapping_rules', entity: 'mapping_rule', from: response)
981
+ end
982
+
983
+ # @api public
984
+ # @param [Fixnum] backend_id Backend ID
985
+ # @param [Hash] attrs Metric attributes
986
+ # @return [Hash]
987
+ def create_backend_mapping_rule(backend_id, attrs)
988
+ response = http_client.post("/admin/api/backend_apis/#{backend_id}/mapping_rules",
989
+ body: attrs)
990
+ extract(entity: 'mapping_rule', from: response)
991
+ end
992
+
993
+ # @api public
994
+ # @param [Fixnum] backend_id Backend ID
995
+ # @param [Fixnum] mapping_rule_id MappingRule ID
996
+ def delete_backend_mapping_rule(backend_id, mapping_rule_id)
997
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
998
+ true
999
+ end
1000
+
1001
+ # @api public
1002
+ # @param [Fixnum] backend_id Backend ID
1003
+ # @param [Fixnum] mapping_rule_id MappingRule ID
1004
+ # @return [Hash]
1005
+ def backend_mapping_rule(backend_id, mapping_rule_id)
1006
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
1007
+ extract(entity: 'mapping_rule', from: response)
1008
+ end
1009
+
1010
+ # @api public
1011
+ # @param [Fixnum] backend_id Backend ID
1012
+ # @param [Fixnum] mapping_rule_id MappingRule ID
1013
+ # @param [Hash] attributes Backend attributes
1014
+ # @return [Hash]
1015
+ def update_backend_mapping_rule(backend_id, mapping_rule_id, attributes)
1016
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}",
1017
+ body: attributes)
1018
+ extract(entity: 'mapping_rule', from: response)
1019
+ end
1020
+
1021
+ # @api public
1022
+ # @param [Fixnum] product_id Product ID
1023
+ # @return [List]
1024
+ def list_backend_usages(product_id)
1025
+ response = http_client.get("/admin/api/services/#{product_id}/backend_usages")
1026
+ extract(entity: 'backend_usage', from: response)
1027
+ end
1028
+
1029
+ # @api public
1030
+ # @param [Fixnum] product_id Product ID
1031
+ # @param [Hash] attrs Backend Usage attributes
1032
+ # @return [Hash]
1033
+ def create_backend_usage(product_id, attrs)
1034
+ response = http_client.post("/admin/api/services/#{product_id}/backend_usages",
1035
+ body: attrs)
1036
+ extract(entity: 'backend_usage', from: response)
1037
+ end
1038
+
1039
+ # @api public
1040
+ # @param [Fixnum] product_id Product ID
1041
+ # @param [Fixnum] id Backend Usage ID
1042
+ def delete_backend_usage(product_id, id)
1043
+ http_client.delete("/admin/api/services/#{product_id}/backend_usages/#{id}")
1044
+ true
1045
+ end
1046
+
1047
+ # @api public
1048
+ # @param [Fixnum] product_id Product ID
1049
+ # @param [Fixnum] id Backend Usage ID
1050
+ # @return [Hash]
1051
+ def backend_usage(product_id, id)
1052
+ response = http_client.get("/admin/api/services/#{product_id}/backend_usages/#{id}")
1053
+ extract(entity: 'backend_usage', from: response)
1054
+ end
1055
+
1056
+ # @api public
1057
+ # @param [Fixnum] product_id Product ID
1058
+ # @param [Fixnum] id Backend Usage ID
1059
+ # @param [Hash] attrs Backend Usage attributes
1060
+ # @return [Hash]
1061
+ def update_backend_usage(product_id, id, attrs)
1062
+ response = http_client.put("/admin/api/services/#{product_id}/backend_usages/#{id}",
1063
+ body: attrs)
1064
+ extract(entity: 'backend_usage', from: response)
1065
+ end
1066
+
819
1067
  protected
820
1068
 
821
1069
  def extract(collection: nil, entity:, from:)
@@ -0,0 +1,12 @@
1
+ module ThreeScale
2
+ module API
3
+ class ResponseError < StandardError
4
+ attr_reader :response
5
+
6
+ def initialize(response, message = response.to_s)
7
+ super(message)
8
+ @response = response
9
+ end
10
+ end
11
+ end
12
+ end
@@ -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.inspect)
61
+ else unexpected!(response)
62
62
  end
63
63
  end
64
64
 
65
- class ForbiddenError < StandardError; end
65
+ class ForbiddenError < ResponseError; end
66
66
 
67
- class UnexpectedResponseError < StandardError; end
67
+ class UnexpectedResponseError < ResponseError; end
68
68
 
69
- class NotFoundError < StandardError; end
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 "unknown format #{format}"
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
 
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module API
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '1.4.0'.freeze
4
4
  end
5
5
  end
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: 0.6.0
4
+ version: 1.4.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: 2019-06-27 00:00:00.000000000 Z
12
+ date: 2021-01-25 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: '10.0'
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: '10.0'
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
- rubyforge_project:
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