33from typing import Dict , Union , List , Iterable
44from urllib .parse import quote_plus
55
6+ from dill .pointers import parent
7+
68from threescale_api import auth
79from threescale_api import utils
810from threescale_api import errors
@@ -273,6 +275,59 @@ def pending(self, entity_id, **kwargs) -> 'Account':
273275 """
274276 return self .set_state (entity_id = entity_id , state = 'make_pending' , ** kwargs )
275277
278+ class ServiceSubscriptions (DefaultClient ):
279+ def __init__ (self , * args , entity_name = 'service_subscription' , entity_collection = 'service_subscriptions' ,
280+ per_page = None , ** kwargs ):
281+ super ().__init__ (* args , entity_name = entity_name ,
282+ entity_collection = entity_collection , ** kwargs )
283+
284+ @property
285+ def url (self ) -> str :
286+ return self .parent .url + '/service_subscriptions'
287+
288+ def approve_service_subscription (self , entity_id : int , ** kwargs ):
289+ url = self .url + f"/{ entity_id } /approve.json"
290+ response = self .rest .put (url = url , ** kwargs )
291+ instance = utils .extract_response (response = response )
292+ return instance
293+
294+ def change_plan_service_subscription (self , entity_id : int , plan_id : int , ** kwargs ):
295+ params = dict (plan_id = plan_id )
296+ url = self .url + f"/{ entity_id } /change_plan.json"
297+ response = self .rest .put (url = url , json = params , ** kwargs )
298+ instance = utils .extract_response (response = response )
299+ return instance
300+
301+ class ServicePlans (DefaultClient ):
302+ def __init__ (self , * args , entity_name = 'service_plan' , entity_collection = 'service_plans' , per_page = None , ** kwargs ):
303+ super ().__init__ (* args , entity_name = entity_name ,
304+ entity_collection = entity_collection , ** kwargs )
305+
306+ def url (self ) -> str :
307+ if type (self .parent ) is Service :
308+ return self .parent .url + '/service_plans'
309+ return self .threescale_client .admin_api_url + '/service_plans'
310+
311+ def service_plans_features_list (self , entity_id : int , ** kwargs ):
312+ url = self .url + f"/{ entity_id } /features.xml"
313+ response = self .rest .get (url = url )
314+ instance = utils .extract_response (response )
315+ return instance
316+
317+ def service_plan_add_feature (self , entity_id : int , feature_id : int , ** kwargs ):
318+ params = dict (feature_id = feature_id )
319+ url = self .url + f"/{ entity_id } /features.xml"
320+ response = self .rest .post (url = url , json = params , ** kwargs )
321+ instance = utils .extract_response (response = response )
322+ return instance
323+
324+ def service_plan_delete_feature (self , entity_id : int , id : int , ** kwargs ):
325+ params = dict (id = id )
326+ url = self .url + f"/{ entity_id } /features/{ id } .xml"
327+ response = self .rest .delete (url = url , json = params , ** kwargs )
328+ instance = utils .extract_response (response = response )
329+ return instance
330+
276331
277332class Applications (DefaultStateClient ):
278333 def __init__ (self , * args , entity_name = 'application' , entity_collection = 'applications' ,
@@ -1138,6 +1193,16 @@ def service(self) -> 'Service':
11381193 def backend (self ) -> 'Backend' :
11391194 return self .metric .parent
11401195
1196+ class ServiceSubscription (DefaultResource ):
1197+ def __init__ (self , ** kwargs ):
1198+ super ().__init__ (** kwargs )
1199+
1200+ def approve_service_subscription (self , entity_id : int , ** kwargs ):
1201+ return self .client .approve_service_subscription (entity_id = self .entity_id , ** kwargs )
1202+
1203+ def change_plan_service_subscription (self , entity_id : int , ** kwargs ):
1204+ return self .client .change_plan_service_subscription (entity_id = self .entity_id , ** kwargs )
1205+
11411206
11421207class Metric (DefaultResource ):
11431208 def __init__ (self , entity_name = 'system_name' , ** kwargs ):
@@ -1249,6 +1314,10 @@ def app_plans(self) -> ApplicationPlans:
12491314 def metrics (self ) -> Metrics :
12501315 return Metrics (parent = self , instance_klass = Metric )
12511316
1317+ @property
1318+ def service_plans (self ) -> ServicePlans :
1319+ return ServicePlans (parent = self , instance_klass = ServicePlan )
1320+
12521321 @property
12531322 def proxy (self ) -> 'Proxies' :
12541323 return Proxies (parent = self , instance_klass = Proxy )
@@ -1455,6 +1524,22 @@ def test_request(self, relpath=None, verify: bool = None):
14551524
14561525 return client .get (relpath )
14571526
1527+ class ServicePlan (DefaultResource ):
1528+ def __init__ (self , ** kwargs ):
1529+ super ().__init__ (** kwargs )
1530+
1531+ def service_plan_list (self , ** kwargs ):
1532+ return self .client .service_plan_list (self , ** kwargs )
1533+
1534+ def service_plan_features_list (self , entity_id : int , ** kwargs ):
1535+ return self .client .service_plan_features_list (entity_id = self .entity_id , ** kwargs )
1536+
1537+ def service_plan_add_feature (self , entity_id : int , id : int , ** kwargs ):
1538+ return self .client .service_plan_add_feature (entity_id = id , id = id , ** kwargs )
1539+
1540+ def service_plan_delete_feature (self , entity_id : int , id : int , ** kwargs ):
1541+ return self .client .service_plan_delete_feature (entity_id = entity_id , id = id , ** kwargs )
1542+
14581543
14591544class ApplicationKey (DefaultResource ):
14601545 def __init__ (self , entity_name = '' , ** kwargs ):
@@ -1473,6 +1558,10 @@ def applications(self) -> Applications:
14731558 def users (self ) -> AccountUsers :
14741559 return AccountUsers (parent = self , instance_klass = AccountUser )
14751560
1561+ @property
1562+ def service_subscriptions (self ) -> ServiceSubscriptions :
1563+ return ServiceSubscriptions (parent = self , instance_klass = ServiceSubscription )
1564+
14761565 def credit_card_set (self , params : dict = None , ** kwargs ):
14771566 url = self .url + "/credit_card"
14781567 response = self .client .rest .put (url = url , json = params , ** kwargs )
0 commit comments