66from typing import List , Optional
77
88from .base import BaseModel
9+ from .configuration import Configuration
910from .connection import Connection
11+ from .contract import Contract
1012from .item import Item
13+ from .marketplace import Marketplace
1114from .param import Param
1215from .product import Product
1316from .tier_accounts import TierAccounts
@@ -58,32 +61,57 @@ class Asset(BaseModel):
5861 """ (str) Identification for asset object on eCommerce. """
5962
6063 external_uid = None # type: Optional[str]
61- """ (str|None) Id of asset in eCommerce system """
64+ """ (str|None) Id of asset in eCommerce system. """
65+
66+ external_name = None # type: Optional[str]
67+ """ (str|None) Name of asset. """
6268
6369 product = None # type: Product
6470 """ (:py:class:`.Product`) Product object reference. """
6571
6672 connection = None # type: Connection
6773 """ (:py:class:`.Connection`) Connection object. """
6874
69- items = None # type: List[Item]
70- """ (List[:py:class:`.Item`]) List of asset product items. """
75+ contract = None # type: Contract
76+ """ (:py:class:`.Contract`) Contract Object reference. """
77+
78+ marketplace = None # type: Marketplace
79+ """ (:py:class:`.Marketplace`) Marketplace Object reference. """
7180
7281 params = None # type: List[Param]
7382 """ (List[:py:class:`.Param`]) List of product parameter objects. """
7483
7584 tiers = None # type: TierAccounts
7685 """ (:py:class:`.TierAccounts`) Supply chain accounts. """
7786
78- def get_param_by_id (self , id_ ):
87+ items = None # type: List[Item]
88+ """ (List[:py:class:`.Item`]) List of asset product items. """
89+
90+ configuration = None # type: Configuration
91+ """ (:py:class:`.Configuration`) List of Product and Marketplace Configuration Phase Parameter
92+ Context-Bound Object. """
93+
94+ def get_param_by_id (self , param_id ):
7995 """ Get a parameter of the asset.
8096
81- :param str id_ : Id of the the parameter to get.
97+ :param str param_id : Id of the the parameter to get.
8298 :return: The parameter with the given id, or ``None`` if it was not found.
8399 :rtype: :py:class:`.Param` | None
84100 """
85101 try :
86- return list (filter (lambda param : param .id == id_ , self .params ))[0 ]
102+ return list (filter (lambda param : param .id == param_id , self .params ))[0 ]
103+ except IndexError :
104+ return None
105+
106+ def get_item_by_id (self , item_id ):
107+ """ Get an item of the asset.
108+
109+ :param str item_id: Id of the item to get.
110+ :return: The item with the given id, or ``None`` if it was not found.
111+ :rtype: :py:class:`.Item` | None
112+ """
113+ try :
114+ return list (filter (lambda item : item .id == item_id , self .items ))[0 ]
87115 except IndexError :
88116 return None
89117
@@ -98,3 +126,30 @@ def get_item_by_mpn(self, mpn):
98126 return list (filter (lambda item : item .mpn == mpn , self .items ))[0 ]
99127 except IndexError :
100128 return None
129+
130+ def get_item_by_global_id (self , global_id ):
131+ """ Get an item of the asset.
132+
133+ :param str global_id: Global id of the item to get.
134+ :return: The item with the given global id, or ``None`` if it was not found.
135+ :rtype: :py:class:`.Item` | None
136+ """
137+ try :
138+ return list (filter (lambda item : item .global_id == global_id , self .items ))[0 ]
139+ except IndexError :
140+ return None
141+
142+ def get_requests (self , config = None ):
143+ """ Get the requests for this asset.
144+
145+ :param Config config: Config object or ``None`` to use environment config (default).
146+ :return: The requests for this asset.
147+ :rtype: List[Fulfillment]
148+ """
149+ from connect .config import Config
150+ from connect .resources .base import ApiClient
151+ from .fulfillment import Fulfillment
152+ text , _ = ApiClient (
153+ config or Config .get_instance (),
154+ 'assets/' + self .id + '/requests' ).get ()
155+ return Fulfillment .deserialize (text )
0 commit comments