Skip to content

Commit

Permalink
Merge pull request #10 from Roborian/Exception-refacor
Browse files Browse the repository at this point in the history
Exception refacor
savelkouls authored Apr 1, 2024

Verified

This commit was created on GitHub.com and signed with GitHub’s verified signature.
2 parents 2aab672 + 3ee81aa commit 7b0c98e
Showing 3 changed files with 19 additions and 10 deletions.
12 changes: 6 additions & 6 deletions src/outsetapy/api/billing/subscriptions.py
Original file line number Diff line number Diff line change
@@ -27,7 +27,7 @@ class Subscriptions:
def __init__(self, store: Store):
self.store = store

async def get_all(self, options: dict = {}) -> List[PlanFamily]:
async def get_all(self, options: dict = {}) -> List[Subscription]:
has_more = True
results = []
while has_more:
@@ -48,7 +48,7 @@ async def get_all(self, options: dict = {}) -> List[PlanFamily]:
json_response["metadata"]["offset"] + json_response["metadata"]["limit"]
)

return [PlanFamily(json_obj) for json_obj in results]
return [Subscription(json_obj, self.store) for json_obj in results]

async def get(self, uid: str, options: dict = {}) -> Subscription:
request = Request(
@@ -65,7 +65,7 @@ async def get(self, uid: str, options: dict = {}) -> Subscription:
if not response.ok:
raise Exception(response)
json_response = response.json()
return Subscription(json_response)
return Subscription(json_response, self.store)

async def add(
self, subscription: dict
@@ -80,7 +80,7 @@ async def add(
if response.status == 400:
raise ValidationError(response.json())
elif response.ok:
return Subscription(response.json())
return Subscription(response.json(), self.store)
else:
raise Exception(response)

@@ -117,7 +117,7 @@ async def update(
if response.status == 400:
raise ValidationError(response.json())
elif response.ok:
return Subscription(response.json())
return Subscription(response.json(), self.store)
else:
raise Exception(response)

@@ -157,7 +157,7 @@ async def set_subscription_upgrade_required(
if response.status == 400:
raise ValidationError(response.json())
elif response.ok:
return Subscription(response.json())
return Subscription(response.json(), self.store)
else:
raise Exception(response)

3 changes: 2 additions & 1 deletion src/outsetapy/api/crm/accounts.py
Original file line number Diff line number Diff line change
@@ -53,7 +53,8 @@ async def get(self, uid: str, options: dict = {}) -> Account:
.with_params(
{
"fields": options.get(
"fields", "*,PersonAccount.*,PersonAccount.Person.Uid"
# "fields", "*,PersonAccount.*,PersonAccount.Person.Uid"
"fields", "*,PersonAccount.*,BillingAddress.*,MailingAddress.*,PersonAccount.Person.Uid,CurrentSubscription.Uid,LatestSubscription.Uid, PrimarySubscription.Uid, PrimaryContact.*"
)
}
)
14 changes: 11 additions & 3 deletions src/outsetapy/models/billing/subscription.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,9 @@
import importlib
from typing import Optional
from datetime import datetime
from dataclasses import dataclass
from .billing_renewal_term import BillingRenewalTerm as _BillingRenewalTerm
from outsetapy.util.store import Store


@dataclass
@@ -20,7 +22,8 @@ class Subscription:
Created: datetime
Updated: datetime

def __init(self, data: object):
def __init__(self, data: object, store: Store):
self.__store = store
self.Uid = None
self.BillingRenewalTerm = None
self.Account_Uid = None
@@ -37,8 +40,8 @@ def __init(self, data: object):
if "_objectType" in data and data["_objectType"] == "Subscription":
self.Uid = data["Uid"]
self.BillingRenewalTerm = data["BillingRenewalTerm"]
self.Account_Uid = data["Account.Uid"]
self.Plan_Uid = data["Plan.Uid"]
self.Account_Uid = data["Account"]['Uid']
self._plan = data["Plan"]['Uid']
self.Quantity = data["Quantity"]
self.StartDate = data["StartDate"]
self.EndDate = data["EndDate"]
@@ -50,3 +53,8 @@ def __init(self, data: object):
self.Updated = data["Updated"]
else:
raise ValueError("Invalid object type")

@property
async def Plan(self):
plan_api = importlib.import_module("outsetapy.api.billing.plans").Plans(self.__store)
return await plan_api.get(self._plan)

0 comments on commit 7b0c98e

Please sign in to comment.