Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion connect/config.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ def __init__(self, api_url=None, api_key=None, products=None, file=None):
self._api_key = api_key
self._api_url = api_url if api_url.endswith('/') else api_url + '/'
self._products = [products] \
if isinstance(products, str) \
if isinstance(products, str) and products \
else products or []

# Store first created instance
Expand Down
5 changes: 3 additions & 2 deletions connect/logger/logger.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,9 @@
import json
import logging
import os

from logging.config import dictConfig
from connect.models import BaseModel, Fulfillment
from connect.models.base import BaseModel

with open(os.path.join(os.path.dirname(__file__), 'config.json')) as config_file:
config = json.load(config_file)
Expand All @@ -23,7 +24,7 @@ def log_request_data(args):
base = " %(levelname)-6s; %(asctime)s; %(name)-6s; %(module)s:%(funcName)s:line"\
"-%(lineno)d: %(message)s"
sformat = args[0].id + base
if isinstance(args[0], Fulfillment):
if hasattr(args[0], 'asset') and hasattr(args[0].asset, 'id'):
sformat = args[0].asset.id + " " + sformat
[handler.setFormatter(logging.Formatter(sformat, "%I:%M:%S"))
for handler in logger.handlers]
Expand Down
4 changes: 4 additions & 0 deletions connect/models/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
from .contact import Contact
from .contact_info import ContactInfo
from .contract import Contract
from .country import Country
from .conversation import Conversation
from .conversation_message import ConversationMessage
from .customer_ui_settings import CustomerUiSettings
Expand All @@ -36,6 +37,7 @@
from .product import Product
from .product_category import ProductCategory
from .product_configuration import ProductConfiguration
from .product_configuration_parameter import ProductConfigurationParameter
from .product_family import ProductFamily
from .product_stats import ProductStats
from .product_stats_info import ProductStatsInfo
Expand Down Expand Up @@ -68,6 +70,7 @@
'Contact',
'ContactInfo',
'Contract',
'Country',
'Conversation',
'ConversationMessage',
'CustomerUiSettings',
Expand All @@ -87,6 +90,7 @@
'Product',
'ProductCategory',
'ProductConfiguration',
'ProductConfigurationParameter',
'ProductFamily',
'ProductStats',
'ProductStatsInfo',
Expand Down
5 changes: 5 additions & 0 deletions connect/models/agreement.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,3 +74,8 @@ class Agreement(BaseModel):
""" (:py:class:`.Marketplace` | None) Reference to marketplace object
(for distribution agreement).
"""

# Undocumented fields (they appear in PHP SDK)

name = None # type: str
""" (str) Name of Agreement. """
67 changes: 61 additions & 6 deletions connect/models/asset.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,11 @@
from typing import List, Optional

from .base import BaseModel
from .configuration import Configuration
from .connection import Connection
from .contract import Contract
from .item import Item
from .marketplace import Marketplace
from .param import Param
from .product import Product
from .tier_accounts import TierAccounts
Expand Down Expand Up @@ -58,32 +61,57 @@ class Asset(BaseModel):
""" (str) Identification for asset object on eCommerce. """

external_uid = None # type: Optional[str]
""" (str|None) Id of asset in eCommerce system """
""" (str|None) Id of asset in eCommerce system. """

external_name = None # type: Optional[str]
""" (str|None) Name of asset. """

product = None # type: Product
""" (:py:class:`.Product`) Product object reference. """

connection = None # type: Connection
""" (:py:class:`.Connection`) Connection object. """

items = None # type: List[Item]
""" (List[:py:class:`.Item`]) List of asset product items. """
contract = None # type: Contract
""" (:py:class:`.Contract`) Contract Object reference. """

marketplace = None # type: Marketplace
""" (:py:class:`.Marketplace`) Marketplace Object reference. """

params = None # type: List[Param]
""" (List[:py:class:`.Param`]) List of product parameter objects. """

tiers = None # type: TierAccounts
""" (:py:class:`.TierAccounts`) Supply chain accounts. """

def get_param_by_id(self, id_):
items = None # type: List[Item]
""" (List[:py:class:`.Item`]) List of asset product items. """

configuration = None # type: Configuration
""" (:py:class:`.Configuration`) List of Product and Marketplace Configuration Phase Parameter
Context-Bound Object. """

def get_param_by_id(self, param_id):
""" Get a parameter of the asset.

:param str id_: Id of the the parameter to get.
:param str param_id: Id of the the parameter to get.
:return: The parameter with the given id, or ``None`` if it was not found.
:rtype: :py:class:`.Param` | None
"""
try:
return list(filter(lambda param: param.id == id_, self.params))[0]
return list(filter(lambda param: param.id == param_id, self.params))[0]
except IndexError:
return None

def get_item_by_id(self, item_id):
""" Get an item of the asset.

:param str item_id: Id of the item to get.
:return: The item with the given id, or ``None`` if it was not found.
:rtype: :py:class:`.Item` | None
"""
try:
return list(filter(lambda item: item.id == item_id, self.items))[0]
except IndexError:
return None

Expand All @@ -98,3 +126,30 @@ def get_item_by_mpn(self, mpn):
return list(filter(lambda item: item.mpn == mpn, self.items))[0]
except IndexError:
return None

def get_item_by_global_id(self, global_id):
""" Get an item of the asset.

:param str global_id: Global id of the item to get.
:return: The item with the given global id, or ``None`` if it was not found.
:rtype: :py:class:`.Item` | None
"""
try:
return list(filter(lambda item: item.global_id == global_id, self.items))[0]
except IndexError:
return None

def get_requests(self, config=None):
""" Get the requests for this asset.

:param Config config: Config object or ``None`` to use environment config (default).
:return: The requests for this asset.
:rtype: List[Fulfillment]
"""
from connect.config import Config
from connect.resources.base import ApiClient
from .fulfillment import Fulfillment
text, _ = ApiClient(
config or Config.get_instance(),
'assets/' + self.id + '/requests').get()
return Fulfillment.deserialize(text)
12 changes: 12 additions & 0 deletions connect/models/configuration.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,3 +25,15 @@ class Configuration(BaseModel):

params = None # type: List[Param]
""" (List[:py:class:`.Param`]) """

def get_param_by_id(self, param_id):
""" Get a parameter of the configuration.

:param str param_id: Id of the the parameter to get.
:return: The parameter with the given id, or ``None`` if it was not found.
:rtype: :py:class:`.Param` | None
"""
try:
return list(filter(lambda param: param.id == param_id, self.params))[0]
except IndexError:
return None
2 changes: 1 addition & 1 deletion connect/models/contact_info.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ class ContactInfo(BaseModel):
country = None # type: str
""" (str) Country code. """

state = None # type: str
state = None # type: Optional[str]
""" (str) State name. """

city = None # type: str
Expand Down
22 changes: 22 additions & 0 deletions connect/models/country.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
# -*- coding: utf-8 -*-

# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from .base import BaseModel
from .schemas import CountrySchema


class Country(BaseModel):
""" An instance of a hub. """

_schema = CountrySchema()

name = None # type: str
""" (str) Country name """

icon = None # type: str
""" (str) Icon path. """

zone = None # type: str
""" (str) Geographical zone. """
4 changes: 4 additions & 0 deletions connect/models/fulfillment.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
from .contract import Contract
from .conversation import Conversation
from .marketplace import Marketplace
from .user import User
from .schemas import FulfillmentSchema


Expand Down Expand Up @@ -72,6 +73,9 @@ class Fulfillment(BaseModel):
marketplace = None # type: Marketplace
""" (:py:class:`.Marketplace`) Marketplace object. """

assignee = None # type: User
""" (:py:class:`.User`) Details of the user assigned to the request. """

@property
def new_items(self):
"""
Expand Down
12 changes: 12 additions & 0 deletions connect/models/item.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,3 +54,15 @@ class Item(BaseModel):

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

def get_param_by_id(self, param_id):
""" Get a parameter of the item.

:param str param_id: Id of the the parameter to get.
:return: The parameter with the given id, or ``None`` if it was not found.
:rtype: :py:class:`.Param` | None
"""
try:
return list(filter(lambda param: param.id == param_id, self.params))[0]
except IndexError:
return None
7 changes: 7 additions & 0 deletions connect/models/marketplace.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@

from .base import BaseModel
from .company import Company
from .country import Country
from .ext_id_hub import ExtIdHub
from .schemas import MarketplaceSchema

Expand Down Expand Up @@ -44,3 +45,9 @@ class Marketplace(BaseModel):
zone = None # type: str
""" (str) Zone where the marketplace is located, there can be following zones:
AF, NA, OC, AS, EU, SA (It is continents). """

countries = None # type: List[Country]
""" List[:py:class:`.Country`] List of country objects associated with marketplace. """

sourcing = None # type: bool
""" (bool) Is marketplace available for sourcing. """
33 changes: 33 additions & 0 deletions connect/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,12 @@
from .customer_ui_settings import CustomerUiSettings
from .product_category import ProductCategory
from .product_configuration import ProductConfiguration
from .product_configuration_parameter import ProductConfigurationParameter
from .product_stats import ProductStats
from .schemas import ProductSchema
from .template import Template
from connect.config import Config
from connect.resources.base import ApiClient


class Product(BaseModel):
Expand Down Expand Up @@ -63,3 +67,32 @@ class Product(BaseModel):

stats = None # type: Optional[ProductStats]
""" (:py:class:``.ProductStats) Statistics of product use, depends on account of callee. """

def get_templates(self, config=None):
"""
:param Config config: Configuration to use, or None for environment config.
:return: List of all templates associated with the product.
:rtype: List[Template]
"""
text, _ = ApiClient(config or Config.get_instance(),
'products/' + self.id + '/templates').get()
return Template.deserialize(text)

def get_product_configurations(self, filters=None, config=None):
"""
:param Dict[str, Any] filters: Filters for the requests. Supported filters are:
- ``parameter.id``
- ``parameter.title``
- ``parameter.scope``
- ``marketplace.id``
- ``marketplace.name``
- ``item.id``
- ``item.name``
- ``value``
:param Config config: Configuration to use, or None for environment config.
:return: A list with the product configuration parameter data.
:rtype: List[ProductConfigurationParameter]
"""
text, _ = ApiClient(config or Config.get_instance(),
'products/' + self.id + '/configurations').get(params=filters)
return ProductConfigurationParameter.deserialize(text)
38 changes: 38 additions & 0 deletions connect/models/product_configuration_parameter.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
# -*- coding: utf-8 -*-

# This file is part of the Ingram Micro Cloud Blue Connect SDK.
# Copyright (c) 2019 Ingram Micro. All Rights Reserved.

from .base import BaseModel
from .constraints import Constraints
from .events import Events
from .item import Item
from .marketplace import Marketplace
from .param import Param
from .schemas import ProductConfigurationParameterSchema


class ProductConfigurationParameter(BaseModel):
""" Representation of Configuration Phase Parameter (CPP) Data object """

_schema = ProductConfigurationParameterSchema()

value = None # type: str
""" (str|None) Configuration parameter value. """

parameter = None # type: Param
""" (:py:class:`.Param`) Full representation of parameter. """

marketplace = None # type: Marketplace
""" (:py:class:`.Marketplace` | None) Reference to Marketplace. """

item = None # type: Item
""" (:py:class:`.Item` | None) Reference to Item. """

events = None # type: Events
""" (:py:class:`.Events`) Product events. """

# Undocumented fields (they appear in PHP SDK)

constraints = None # type: Constraints
""" (:py:class:`.Constraints`) Constraints. """
Loading