Skip to content

Commit

Permalink
Merge branch 'CPS-8-get-tier-config'
Browse files Browse the repository at this point in the history
  • Loading branch information
JaviCerveraIngram committed May 20, 2019
2 parents 655ede7 + 4810a9e commit dee160a
Show file tree
Hide file tree
Showing 24 changed files with 807 additions and 685 deletions.
79 changes: 16 additions & 63 deletions connect/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,111 +4,64 @@
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from .activation_response import ActivationTemplateResponse, ActivationTileResponse
from .asset import Asset, AssetSchema
from .base import BaseModel, BaseSchema
from .company import Company, CompanySchema
from .connection import Connection, ConnectionSchema
from .contact import Contact, ContactInfo, ContactInfoSchema, ContactSchema, \
PhoneNumber, PhoneNumberSchema
from .event import EventInfo, EventInfoSchema, Events, EventsSchema
from .fulfillment import Fulfillment, FulfillmentSchema
from .hub import Hub, HubInstance, HubInstanceSchema, ExtIdHub, HubSchema, ExtIdHubSchema, \
HubStats, HubStatsSchema
from .marketplace import Activation, ActivationSchema, Agreement, AgreementSchema, AgreementStats,\
AgreementStatsSchema, Contract, ContractSchema, Marketplace, MarketplaceSchema
from .parameters import Constraints, ConstraintsSchema, Param, ParamSchema, ValueChoice, \
ValueChoiceSchema
from .product import CustomerUiSettings, CustomerUiSettingsSchema, Document, DocumentSchema, \
DownloadLink, DownloadLinkSchema, Item, ItemSchema, Product, ProductConfiguration, \
ProductConfigurationSchema, ProductSchema, Renewal, RenewalSchema
from .server_error_response import ServerErrorResponse, ServerErrorResponseSchema
from .tier_config import Account, AccountSchema, Template, TemplateSchema, TierConfig, \
TierConfigRequest, TierConfigRequestSchema, TierConfigSchema
from .tiers import Tier, Tiers, TierSchema, TiersSchema
from .usage import UsageFile, UsageFileSchema, UsageListing, UsageListingSchema, UsageRecord, \
UsageRecords, UsageRecordSchema, UsageRecordsSchema
from .asset import Asset
from .base import BaseModel
from .company import Company
from .connection import Connection
from .contact import Contact, ContactInfo, PhoneNumber
from .event import EventInfo, Events
from .fulfillment import Fulfillment
from .hub import Hub, HubInstance, ExtIdHub, HubStats
from .marketplace import Activation, Agreement, AgreementStats, Contract, Marketplace
from .parameters import Constraints, Param, ValueChoice
from .product import CustomerUiSettings, Document, DownloadLink, Item, Product, \
ProductConfiguration, Renewal
from .server_error_response import ServerErrorResponse
from .tier_config import Account, Template, TierConfig, TierConfigRequest
from .tiers import Tier, Tiers
from .usage import UsageFile, UsageListing, UsageRecord, UsageRecords

__all__ = [
'Account',
'AccountSchema',
'Activation',
'ActivationSchema',
'ActivationTemplateResponse',
'ActivationTileResponse',
'Agreement',
'AgreementSchema',
'AgreementStats',
'AgreementStatsSchema',
'Asset',
'AssetSchema',
'BaseModel',
'BaseSchema',
'Company',
'CompanySchema',
'Connection',
'ConnectionSchema',
'Constraints',
'ConstraintsSchema',
'Contact',
'ContactInfo',
'ContactInfoSchema',
'ContactSchema',
'Contract',
'ContractSchema',
'CustomerUiSettings',
'CustomerUiSettingsSchema',
'Document',
'DocumentSchema',
'DownloadLink',
'DownloadLinkSchema',
'EventInfo',
'EventInfoSchema',
'Events',
'EventsSchema',
'ExtIdHub',
'ExtIdHubSchema',
'Fulfillment',
'FulfillmentSchema',
'Hub',
'HubInstance',
'HubInstanceSchema',
'HubSchema',
'HubStats',
'HubStatsSchema',
'Item',
'ItemSchema',
'Marketplace',
'MarketplaceSchema',
'Param',
'ParamSchema',
'PhoneNumber',
'PhoneNumberSchema',
'Product',
'ProductConfiguration',
'ProductConfigurationSchema',
'ProductSchema',
'Renewal',
'RenewalSchema',
'ServerErrorResponse',
'ServerErrorResponseSchema',
'Template',
'TemplateSchema',
'Tier',
'TierConfig',
'TierConfigRequest',
'TierConfigRequestSchema',
'TierConfigSchema',
'Tiers',
'TierSchema',
'TiersSchema',
'UsageFile',
'UsageFileSchema',
'UsageListing',
'UsageListingSchema',
'UsageRecord',
'UsageRecords',
'UsageRecordSchema',
'UsageRecordsSchema',
'ValueChoice',
'ValueChoiceSchema',
]
31 changes: 8 additions & 23 deletions connect/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,14 +3,14 @@
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from marshmallow import fields, post_load
from typing import List, Optional

from .base import BaseModel, BaseSchema
from .connection import Connection, ConnectionSchema
from .parameters import Param, ParamSchema
from .product import Item, ItemSchema, Product, ProductSchema
from .tiers import Tiers, TiersSchema
from .base import BaseModel
from .connection import Connection
from .parameters import Param
from .product import Item, Product
from .tiers import Tiers
from connect.models.schemas import AssetSchema


class Asset(BaseModel):
Expand Down Expand Up @@ -39,6 +39,8 @@ class Asset(BaseModel):
one asset from another.
"""

_schema = AssetSchema()

status = None # type: str
""" Assets may have one of the following statuses:
Expand Down Expand Up @@ -95,20 +97,3 @@ def get_item_by_mpn(self, mpn):
return list(filter(lambda item: item.mpn == mpn, self.items))[0]
except IndexError:
return None


class AssetSchema(BaseSchema):
status = fields.Str()
external_id = fields.Str()
external_uid = fields.Str(allow_none=True)
product = fields.Nested(ProductSchema, only=('id', 'name'))
connection = fields.Nested(
ConnectionSchema, only=('id', 'type', 'provider', 'vendor'),
)
items = fields.Nested(ItemSchema, many=True)
params = fields.Nested(ParamSchema, many=True)
tiers = fields.Nested(TiersSchema)

@post_load
def make_object(self, data):
return Asset(**data)
36 changes: 30 additions & 6 deletions connect/models/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

import json

from marshmallow import Schema, fields, post_load
from .schemas import BaseSchema


class BaseModel(object):
Expand All @@ -14,6 +14,8 @@ class BaseModel(object):
All the arguments provided on creation of the model are injected as attributes on the object.
"""

_schema = BaseSchema() # type: BaseSchema

id = None # type: str
""" (str) Globally unique id. """

Expand All @@ -31,10 +33,32 @@ def json(self):
dump = json.dumps(self, default=lambda o: getattr(o, '__dict__', str(o)))
return json.loads(dump)

@classmethod
def deserialize(cls, json_str):
""" Deserialize a string containing JSON data into a model.
:param str json_str: String containing the JSON data to be deserialized.
:return: An instance of the same class as the receiver of the call, or a list of instances.
:rtype: Any|list[Any]
"""
return cls.deserialize_json(json.loads(json_str))

class BaseSchema(Schema):
id = fields.Str()
@classmethod
def deserialize_json(cls, json_data):
""" Deserialize JSON data into a model.
@post_load
def make_object(self, data):
return BaseModel(**data)
:param dict|list json_data: JSON list or dictionary to be deserialized.
:return: An instance of the same class as the receiver of the call, or a list of instances.
:rtype: Any|list[Any]
"""
objects, error = cls._schema.load(json_data, many=isinstance(json_data, list))
if error:
raise TypeError(
'Invalid structure for initialization of `{type}`. \n'
'Error: {error}. \nJSON data: {data}'
.format(
type=cls.__name__,
error=error,
data=json_data),
)
return objects
15 changes: 4 additions & 11 deletions connect/models/company.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,21 +3,14 @@
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from marshmallow import fields, post_load

from .base import BaseModel, BaseSchema
from .base import BaseModel
from connect.models.schemas import CompanySchema


class Company(BaseModel):
""" Represents a company within the platform. """

_schema = CompanySchema()

name = None # type: str
""" (str) Company name. """


class CompanySchema(BaseSchema):
name = fields.Str()

@post_load
def make_object(self, data):
return Company(**data)
25 changes: 7 additions & 18 deletions connect/models/connection.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,12 +3,11 @@
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from marshmallow import fields, post_load

from .base import BaseModel, BaseSchema
from .company import Company, CompanySchema
from .hub import Hub, HubSchema
from .product import Product, ProductSchema
from .base import BaseModel
from .company import Company
from .hub import Hub
from .product import Product
from connect.models.schemas import ConnectionSchema


class Connection(BaseModel):
Expand All @@ -18,6 +17,8 @@ class Connection(BaseModel):
Standalone connection is required for each product and for each provider account.
"""

_schema = ConnectionSchema()

type = None # type: str
""" (str) Type of connection. """

Expand All @@ -32,15 +33,3 @@ class Connection(BaseModel):

hub = None # type: Hub
""" (:py:class:`.Hub`) Hub Reference. """


class ConnectionSchema(BaseSchema):
type = fields.Str()
provider = fields.Nested(CompanySchema, only=('id', 'name'))
vendor = fields.Nested(CompanySchema, only=('id', 'name'))
product = fields.Nested(ProductSchema)
hub = fields.Nested(HubSchema)

@post_load
def make_object(self, data):
return Connection(**data)
48 changes: 10 additions & 38 deletions connect/models/contact.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,17 @@
# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from marshmallow import fields, post_load
from typing import Optional

from .base import BaseModel, BaseSchema
from .base import BaseModel
from connect.models.schemas import PhoneNumberSchema, ContactSchema, ContactInfoSchema


class PhoneNumber(BaseModel):
""" Phone number. """

_schema = PhoneNumberSchema()

country_code = None # type: Optional[str]
""" (str|None) Country code. """

Expand All @@ -23,20 +27,11 @@ class PhoneNumber(BaseModel):
""" (str|None) Phone extension. """


class PhoneNumberSchema(BaseSchema):
country_code = fields.Str(allow_none=True)
area_code = fields.Str(allow_none=True)
phone_number = fields.Str(allow_none=True)
extension = fields.Str(allow_none=True)

@post_load
def make_object(self, data):
return PhoneNumber(**data)


class Contact(BaseModel):
""" Person of contact. """

_schema = ContactSchema()

first_name = None # type: Optional[str]
""" (str|None) First name. """

Expand All @@ -50,20 +45,11 @@ class Contact(BaseModel):
""" (:py:class:`.PhoneNumber`) Phone number."""


class ContactSchema(BaseSchema):
email = fields.Str()
first_name = fields.Str(allow_none=True)
last_name = fields.Str(allow_none=True)
phone_number = fields.Nested(PhoneNumberSchema)

@post_load
def make_object(self, data):
return Contact(**data)


class ContactInfo(BaseModel):
""" Represents the information of a contact. """

_schema = ContactInfoSchema()

address_line1 = None # type: str
""" (str) Street address, first line. """

Expand All @@ -84,17 +70,3 @@ class ContactInfo(BaseModel):

contact = None # type: Contact
""" (:py:class:`.Contact`) Person of contact. """


class ContactInfoSchema(BaseSchema):
address_line1 = fields.Str()
address_line2 = fields.Str(allow_none=True)
city = fields.Str()
contact = fields.Nested(ContactSchema)
country = fields.Str()
postal_code = fields.Str()
state = fields.Str()

@post_load
def make_object(self, data):
return ContactInfo(**data)

0 comments on commit dee160a

Please sign in to comment.