Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

WIP: fix last release breaking changes #36

Draft
wants to merge 1 commit into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 2 additions & 2 deletions appnexus/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,8 +220,8 @@ def base_url(self):


services_list = ["AccountRecovery", "AdProfile", "AdQualityRule", "Adserver",
"Advertiser", "BatchSegment", "Brand", "Broker", "Browser",
"BudgetSplitter", "Campaign", "Carrier", "Category",
"Advertiser", "AugmentedLineItem", "BatchSegment", "Brand",
"Broker", "Browser", "Campaign", "Carrier", "Category",
"ChangeLog", "ChangeLogDetail", "City", "ContentCategory",
"Country", "Creative", "CreativeFormat", "Currency",
"CustomModel", "CustomModelHash", "CustomModelLogit",
Expand Down
62 changes: 50 additions & 12 deletions appnexus/model.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
from thingy import Thingy

from appnexus.client import AppNexusClient, client, services_list
from appnexus.exceptions import AppNexusException
from appnexus.utils import classproperty, normalize_service_name

logger = logging.getLogger("appnexus-client")
Expand Down Expand Up @@ -139,13 +140,6 @@ def is_ready(self):
return (status == "ready")


class BudgetSplitterMixin():

@property
def budget_splitter(self):
return BudgetSplitter.find_one(id=self.id) # noqa: F821


class ChangeLogMixin():

@property
Expand All @@ -161,16 +155,60 @@ def profile(self):
return Profile.find_one(id=self.profile_id) # noqa: F821


class LineItem(Model, ChangeLogMixin, ProfileMixin):

@classmethod
def find(cls, **kwargs):
kwargs["line_item_type"] = "standard_v1"
return super().find(**kwargs)


class AugmentedLineItem(Model, ChangeLogMixin, ProfileMixin):

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
self._splits = []

@classmethod
def find(cls, **kwargs):
kwargs["line_item_type"] = "standard_v2"
return super().find(**kwargs)

@classproperty
def service_name(cls):
return "line-item"

@property
def splits(self):
if not self._splits:
try:
self._splits = self.client.get(
"budget-splitter/{}/splits".format(self.id),
raw=True)
except AppNexusException:
pass
return self._splits

@splits.setter
def splits(self, value):
self._splits = value

def save(self, **kwargs):
splits = self.__dict__.pop("_splits", None)
super().save(**kwargs)
if splits:
self.client.modify(
"budget-splitter/{}/splits".format(self.id),
splits)


def create_models(services_list):
for service_name in services_list:
ancestors = [Model]
if service_name in ("LineItem"):
ancestors.append(BudgetSplitterMixin)
if service_name in ("Campaign", "InsertionOrder", "LineItem",
"Profile"):
if service_name in ("Campaign", "InsertionOrder", "Profile"):
ancestors.append(ChangeLogMixin)
if service_name in ("AdQualityRule", "Advertiser", "Campaign",
"Creative", "LineItem", "PaymentRule"):
"Creative", "PaymentRule"):
ancestors.append(ProfileMixin)
model = type(service_name, tuple(ancestors), {})
globals().setdefault(service_name, model)
Expand Down