3scale-api 0.6.0 → 1.0.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: be3beb90baf28a00d7d45d780bea0f406a275b8163aec1a7eceade2db378d3e1
4
+ data.tar.gz: ae228c7f369e201517de850bd0c952496172083ecc1f6615bb26400d72b0d25a
5
5
  SHA512:
6
- metadata.gz: 5a9e0a4b84571fab32f61f9db8e332924fdf86c219bf976fa82fef39ca3d4b82a896becd7c4f6079d3f45c400a8142f71ee94ad045d4a7ba577a7d2e26914fcf
7
- data.tar.gz: c4676676ba01ef337764202ebe0da7ef824e0b573c9e05a5095600b58266c9af60f6365a3f51355f3154ed162f675bc6d55a41dd61a29581a463660da2be8fec
6
+ metadata.gz: aa359d57c8c639612236799e52688013a823f84f7668aeeef585e65ebf886c17755264e1b7fab851c98a72e9ab4dcd9c34492f3801c2ddcb1b83d21c2376a575
7
+ data.tar.gz: e9ecd33300d1e7bf86d1c0d061e7d884483858d2e3756176885424c157a9f99c21f2230e30f0d941403372fdb0e921b15e268384d0d04f981905920646b79cd8
data/lib/3scale/api.rb CHANGED
@@ -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
@@ -173,7 +173,7 @@ module ThreeScale
173
173
  # @return [Hash]
174
174
  # @param [Fixnum] service_id Service ID
175
175
  # @param [String] environment. Must be 'sandbox' or 'production'
176
- # @param [Fixnum] proxy configuration version
176
+ # @param [Fixnum] version Proxy configuration version
177
177
  def show_proxy_config(service_id, environment, version)
178
178
  response = http_client.get("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}")
179
179
  extract(entity: 'proxy_config', from: response)
@@ -182,9 +182,9 @@ module ThreeScale
182
182
  # @api public
183
183
  # @return [Hash]
184
184
  # @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
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
188
  def promote_proxy_config(service_id, environment, version, to)
189
189
  response = http_client.post("/admin/api/services/#{service_id}/proxy/configs/#{environment}/#{version}/promote",
190
190
  body: { to: to })
@@ -307,7 +307,7 @@ module ThreeScale
307
307
 
308
308
  # @api public
309
309
  # @param [Fixnum] service_id Service ID
310
- # @param [Fixnum] id Parent metric ID
310
+ # @param [Fixnum] parent_id Parent metric ID
311
311
  # @param [Fixnum] id Method ID
312
312
  # @return [Hash]
313
313
  def show_method(service_id, parent_id, id)
@@ -352,7 +352,7 @@ module ThreeScale
352
352
  # @return [Bool]
353
353
  # @param [Fixnum] service_id Service ID
354
354
  # @param [Fixnum] parent_id Parent metric ID
355
- # @param [Fixnum] metric_id Metric ID
355
+ # @param [Fixnum] id Metric ID
356
356
  def delete_method(service_id, parent_id, id)
357
357
  http_client.delete("/admin/api/services/#{service_id}/metrics/#{parent_id}/methods/#{id}")
358
358
  true
@@ -388,7 +388,7 @@ module ThreeScale
388
388
  end
389
389
 
390
390
  # @api public
391
- # @param [Fixnum] id Service ID
391
+ # @param [Fixnum] service_id Service ID
392
392
  # @param [Fixnum] id Application Plan ID
393
393
  # @return [Hash]
394
394
  def show_application_plan(service_id, id)
@@ -466,7 +466,7 @@ module ThreeScale
466
466
  end
467
467
 
468
468
  # @api public
469
- # @param [Hash] account criteria
469
+ # @param [Hash] criteria Search parameters
470
470
  # @return [Hash]
471
471
  def find_account(criteria)
472
472
  response = http_client.get('/admin/api/accounts/find', params: criteria)
@@ -561,7 +561,7 @@ module ThreeScale
561
561
  end
562
562
 
563
563
  # @api public
564
- # @param [Fixnum] account_id Account ID
564
+ # @param [Fixnum] id Account ID
565
565
  # @return [Bool]
566
566
  def delete_account(id)
567
567
  http_client.delete("/admin/api/accounts/#{id}")
@@ -570,7 +570,7 @@ module ThreeScale
570
570
 
571
571
  # @api public
572
572
  # @param [Fixnum] account_id Account ID
573
- # @param [Fixnum] application_id Application ID
573
+ # @param [Fixnum] id Application ID
574
574
  # @return [Bool]
575
575
  def delete_application(account_id, id)
576
576
  http_client.delete("/admin/api/accounts/#{account_id}/applications/#{id}")
@@ -578,7 +578,7 @@ module ThreeScale
578
578
  end
579
579
 
580
580
  # @api public
581
- # @param [Fixnum] id Service ID
581
+ # @param [Fixnum] service_id Service ID
582
582
  # @return [Array<Hash>]
583
583
  def show_oidc(service_id)
584
584
  response = http_client.get("/admin/api/services/#{service_id}/proxy/oidc_configuration")
@@ -586,7 +586,7 @@ module ThreeScale
586
586
  end
587
587
 
588
588
  # @api public
589
- # @param [Fixnum] id Service ID
589
+ # @param [Fixnum] service_id Service ID
590
590
  # @return [Hash]
591
591
  def update_oidc(service_id, attributes)
592
592
  response = http_client.patch("/admin/api/services/#{service_id}/proxy/oidc_configuration",
@@ -717,7 +717,7 @@ module ThreeScale
717
717
  extract(collection: 'applications', entity: 'application', from: response)
718
718
  end
719
719
 
720
- # @api public
720
+ # @api public
721
721
  # @return [Array<Hash]
722
722
  def list_application_plans
723
723
  response = http_client.get("/admin/api/application_plans")
@@ -760,7 +760,7 @@ module ThreeScale
760
760
  response = http_client.put("/admin/api/accounts/#{account_id}/applications/#{application_id}/suspend")
761
761
  extract(entity: 'application', from: response)
762
762
  end
763
-
763
+
764
764
  # @api public
765
765
  # @param [String] account_id Account ID
766
766
  # @param [String] application_id Application ID
@@ -816,6 +816,232 @@ module ThreeScale
816
816
  extract(entity: 'account', from: response)
817
817
  end
818
818
 
819
+ # @api public
820
+ # @return [List]
821
+ def list_backends
822
+ response = http_client.get('/admin/api/backend_apis')
823
+ extract(collection: 'backend_apis', entity: 'backend_api', from: response)
824
+ end
825
+
826
+ # @api public
827
+ # @param [Hash] attributes Backend attributes
828
+ # @return [Hash]
829
+ def create_backend(attributes)
830
+ response = http_client.post('/admin/api/backend_apis', body: attributes)
831
+ extract(entity: 'backend_api', from: response)
832
+ end
833
+
834
+ # @api public
835
+ # @param [Fixnum] id Backend ID
836
+ def delete_backend(id)
837
+ http_client.delete("/admin/api/backend_apis/#{id}")
838
+ true
839
+ end
840
+
841
+ # @api public
842
+ # @param [Fixnum] id Backend ID
843
+ # @return [Hash]
844
+ def backend(id)
845
+ response = http_client.get("/admin/api/backend_apis/#{id}")
846
+ extract(entity: 'backend_api', from: response)
847
+ end
848
+
849
+ # @api public
850
+ # @param [Fixnum] id Backend ID
851
+ # @param [Hash] attributes Backend attributes
852
+ # @return [Hash]
853
+ def update_backend(id, attributes)
854
+ response = http_client.put("/admin/api/backend_apis/#{id}", body: attributes)
855
+ extract(entity: 'backend_api', from: response)
856
+ end
857
+
858
+ # @api public
859
+ # @param [Fixnum] id Backend ID
860
+ # @return [List]
861
+ def list_backend_metrics(id)
862
+ response = http_client.get("/admin/api/backend_apis/#{id}/metrics")
863
+ extract(collection: 'metrics', entity: 'metric', from: response)
864
+ end
865
+
866
+ # @api public
867
+ # @param [Fixnum] id Backend ID
868
+ # @param [Hash] attributes Metric attributes
869
+ # @return [Hash]
870
+ def create_backend_metric(id, attrs)
871
+ response = http_client.post("/admin/api/backend_apis/#{id}/metrics", body: attrs)
872
+ extract(entity: 'metric', from: response)
873
+ end
874
+
875
+ # @api public
876
+ # @param [Fixnum] backend_id Backend ID
877
+ # @param [Fixnum] metric_id Backend Metric ID
878
+ def delete_backend_metric(backend_id, metric_id)
879
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
880
+ true
881
+ end
882
+
883
+ # @api public
884
+ # @param [Fixnum] backend_id Backend ID
885
+ # @param [Fixnum] metric_id Backend Metric ID
886
+ # @return [Hash]
887
+ def backend_metric(backend_id, metric_id)
888
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}")
889
+ extract(entity: 'metric', from: response)
890
+ end
891
+
892
+ # @api public
893
+ # @param [Fixnum] backend_id Backend ID
894
+ # @param [Fixnum] metric_id Backend Metric ID
895
+ # @param [Hash] attributes Backend attributes
896
+ # @return [Hash]
897
+ def update_backend_metric(backend_id, metric_id, attributes)
898
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}", body: attributes)
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
+ # @return [List]
906
+ def list_backend_methods(backend_id, metric_id)
907
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods")
908
+ extract(collection: 'methods', entity: 'method', from: response)
909
+ end
910
+
911
+ # @api public
912
+ # @param [Fixnum] backend_id Backend ID
913
+ # @param [Fixnum] metric_id Backend Metric ID
914
+ # @param [Hash] attributes Metric attributes
915
+ # @return [Hash]
916
+ def create_backend_method(backend_id, metric_id, attrs)
917
+ response = http_client.post("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods",
918
+ body: attrs)
919
+ extract(entity: 'method', from: response)
920
+ end
921
+
922
+ # @api public
923
+ # @param [Fixnum] backend_id Backend ID
924
+ # @param [Fixnum] metric_id Backend Metric ID
925
+ # @param [Fixnum] method_id Backend Method ID
926
+ def delete_backend_method(backend_id, metric_id, method_id)
927
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
928
+ true
929
+ end
930
+
931
+ # @api public
932
+ # @param [Fixnum] backend_id Backend ID
933
+ # @param [Fixnum] metric_id Backend Metric ID
934
+ # @param [Fixnum] method_id Backend Method ID
935
+ # @return [Hash]
936
+ def backend_method(backend_id, metric_id, method_id)
937
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}")
938
+ extract(entity: 'method', from: response)
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
+ # @param [Hash] attributes Backend attributes
946
+ # @return [Hash]
947
+ def update_backend_method(backend_id, metric_id, method_id, attributes)
948
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/metrics/#{metric_id}/methods/#{method_id}",
949
+ body: attributes)
950
+ extract(entity: 'method', from: response)
951
+ end
952
+
953
+ # @api public
954
+ # @param [Fixnum] backend_id Backend ID
955
+ # @return [List]
956
+ def list_backend_mapping_rules(backend_id)
957
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules")
958
+ extract(collection: 'mapping_rules', entity: 'mapping_rule', from: response)
959
+ end
960
+
961
+ # @api public
962
+ # @param [Fixnum] backend_id Backend ID
963
+ # @param [Hash] attrs Metric attributes
964
+ # @return [Hash]
965
+ def create_backend_mapping_rule(backend_id, attrs)
966
+ response = http_client.post("/admin/api/backend_apis/#{backend_id}/mapping_rules",
967
+ body: attrs)
968
+ extract(entity: 'mapping_rule', from: response)
969
+ end
970
+
971
+ # @api public
972
+ # @param [Fixnum] backend_id Backend ID
973
+ # @param [Fixnum] mapping_rule_id MappingRule ID
974
+ def delete_backend_mapping_rule(backend_id, mapping_rule_id)
975
+ http_client.delete("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
976
+ true
977
+ end
978
+
979
+ # @api public
980
+ # @param [Fixnum] backend_id Backend ID
981
+ # @param [Fixnum] mapping_rule_id MappingRule ID
982
+ # @return [Hash]
983
+ def backend_mapping_rule(backend_id, mapping_rule_id)
984
+ response = http_client.get("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}")
985
+ extract(entity: 'mapping_rule', from: response)
986
+ end
987
+
988
+ # @api public
989
+ # @param [Fixnum] backend_id Backend ID
990
+ # @param [Fixnum] mapping_rule_id MappingRule ID
991
+ # @param [Hash] attributes Backend attributes
992
+ # @return [Hash]
993
+ def update_backend_mapping_rule(backend_id, mapping_rule_id, attributes)
994
+ response = http_client.put("/admin/api/backend_apis/#{backend_id}/mapping_rules/#{mapping_rule_id}",
995
+ body: attributes)
996
+ extract(entity: 'mapping_rule', from: response)
997
+ end
998
+
999
+ # @api public
1000
+ # @param [Fixnum] product_id Product ID
1001
+ # @return [List]
1002
+ def list_backend_usages(product_id)
1003
+ response = http_client.get("/admin/api/services/#{product_id}/backend_usages")
1004
+ extract(entity: 'backend_usage', from: response)
1005
+ end
1006
+
1007
+ # @api public
1008
+ # @param [Fixnum] product_id Product ID
1009
+ # @param [Hash] attrs Backend Usage attributes
1010
+ # @return [Hash]
1011
+ def create_backend_usage(product_id, attrs)
1012
+ response = http_client.post("/admin/api/services/#{product_id}/backend_usages",
1013
+ body: attrs)
1014
+ extract(entity: 'backend_usage', from: response)
1015
+ end
1016
+
1017
+ # @api public
1018
+ # @param [Fixnum] product_id Product ID
1019
+ # @param [Fixnum] id Backend Usage ID
1020
+ def delete_backend_usage(product_id, id)
1021
+ http_client.delete("/admin/api/services/#{product_id}/backend_usages/#{id}")
1022
+ true
1023
+ end
1024
+
1025
+ # @api public
1026
+ # @param [Fixnum] product_id Product ID
1027
+ # @param [Fixnum] id Backend Usage ID
1028
+ # @return [Hash]
1029
+ def backend_usage(product_id, id)
1030
+ response = http_client.get("/admin/api/services/#{product_id}/backend_usages/#{id}")
1031
+ extract(entity: 'backend_usage', from: response)
1032
+ end
1033
+
1034
+ # @api public
1035
+ # @param [Fixnum] product_id Product ID
1036
+ # @param [Fixnum] id Backend Usage ID
1037
+ # @param [Hash] attrs Backend Usage attributes
1038
+ # @return [Hash]
1039
+ def update_backend_usage(product_id, id, attrs)
1040
+ response = http_client.put("/admin/api/services/#{product_id}/backend_usages/#{id}",
1041
+ body: attrs)
1042
+ extract(entity: 'backend_usage', from: response)
1043
+ end
1044
+
819
1045
  protected
820
1046
 
821
1047
  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,26 @@ 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
70
 
71
71
  def forbidden!(response)
72
- raise ForbiddenError, response
72
+ raise ForbiddenError.new(response)
73
73
  end
74
74
 
75
75
  def notfound!(response)
76
- raise NotFoundError, response
76
+ raise NotFoundError.new(response)
77
77
  end
78
78
 
79
79
  def unexpected!(response)
80
- raise UnexpectedResponseError, response
80
+ raise UnexpectedResponseError.new(response, response.inspect)
81
81
  end
82
82
 
83
83
  def serialize(body)
@@ -1,5 +1,5 @@
1
1
  module ThreeScale
2
2
  module API
3
- VERSION = '0.6.0'.freeze
3
+ VERSION = '1.0.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.0.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: 2020-01-23 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: bundler
@@ -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