コード例 #1
0
    def get(cls, account_id, product_id, config=None):
        """
        Gets the specified tier config data. For example, to get Tier 1 configuration data
        for one request we can do: ::

            TierConfig.get(request.asset.tiers.tier1.id, request.asset.product.id)

        :param str account_id: Account Id of the requested Tier Config (id with TA prefix).
        :param str product_id: Id of the product.
        :param Config config: Config to use, or ``None`` to use environment config (default).
        :return: The requested Tier Config, or ``None`` if it was not found.
        :rtype: Optional[TierConfig]
        """
        from .tier_config_request import TierConfigRequest
        from connect.resources.base import ApiClient

        response, _ = ApiClient(config, base_path='tier/config-requests').get(
            params={
                'status': 'approved',
                'configuration__product__id': product_id,
                'configuration__account__id': account_id,
            }
        )
        objects = TierConfigRequest.deserialize(response)

        if isinstance(objects, list) and len(objects) > 0:
            return objects[0].configuration
        else:
            return None
コード例 #2
0
    def list_products(self):
        """ List the products. Filtering is not possible at the moment.

        :return: A list with all products.
        :rtype: list[Product]
        """
        text, code = ApiClient(self._config, 'products').get()
        return Product.deserialize(text)
コード例 #3
0
 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)
コード例 #4
0
    def get_product(self, product_id):
        """ Returns the product with the given id.

        :param str product_id: The id of the product.
        :return: The product with the given id, or ``None`` if such product does not exist.
        :rtype: Product|None
        """
        text, code = ApiClient(self._config, 'products/' + product_id).get()
        return Product.deserialize(text)
コード例 #5
0
    def get_tier_config(self, tier_config_id):
        """ Returns the tier config with the given id.

        :param str tier_config_id: The id of the tier config.
        :return: The Tier Config with the given id, or ``None`` if such Tier Config does not exist.
        :rtype: TierConfig|None
        """
        text, code = ApiClient(self._config, 'tier/configs/' + tier_config_id).get()
        return TierConfig.deserialize(text)
コード例 #6
0
    def get_asset(self, asset_id):
        """ Returns the asset with the given id.

        :param str asset_id: The id of the asset.
        :return: The asset with the given id, or ``None`` if such asset does not exist.
        :rtype: Asset|None
        """
        text, code = ApiClient(self._config, 'assets/' + asset_id).get()
        return Asset.deserialize(text)
コード例 #7
0
    def get_conversation(self, config=None):
        """
        :param Config config: Configuration, or ``None`` to use the environment config (default).
        :return: The conversation for this request, or ``None`` if there is none.
        :rtype: Conversation|None
        """
        from connect.resources.base import ApiClient

        client = ApiClient(config, base_path='conversations')
        response, _ = client.get(params={'instance_id': self.id})
        try:
            conversations = Conversation.deserialize(response)
            if conversations and conversations[0].id:
                response, _ = client.get(conversations[0].id)
                return Conversation.deserialize(response)
            else:
                return None
        except ValueError:
            return None
コード例 #8
0
    def list_tier_configs(self, filters=None):
        """ List the tier configs.

        :param (dict[str, Any] filters: Filters to pass to the request.
        :return: A list with the tier configs that match the given filters.
        :rtype: list[TierConfig]
        """
        query = self._get_filters_query(filters, True)
        text, code = ApiClient(self._config, 'tier/configs' + query.compile()).get()
        return TierConfig.deserialize(text)
コード例 #9
0
    def list_products(self, filters=None):
        """ List the products.

        :param dict|Query filters: Filters to pass to the request.
        :return: A list with all products.
        :rtype: list[Product]
        """
        query = self._get_filters_query(filters, False)
        text, code = ApiClient(self._config, 'products' + query.compile()).get()
        return Product.deserialize(text)
コード例 #10
0
    def list_assets(self, filters=None):
        """ List the assets.

        :param dict|Query filters: Filters to pass to the request.
        :return: A list with the assets that match the given filters.
        :rtype: list[Asset]
        """
        query = self._get_filters_query(filters, True)
        text, code = ApiClient(self._config, 'assets' + query.compile()).get()
        return Asset.deserialize(text)
コード例 #11
0
ファイル: asset.py プロジェクト: unipolar/connect-python-sdk
    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
0
    def add_message(self, message, config=None):
        """ Adds a message to the conversation.

        :param str message: Message to add.
        :param Config config: Configuration, or ``None`` to use the environment config (default).
        :return: The added message.
        :rtype: ConversationMessage
        :raises TypeError: Raised if the message cannot be deserialized.
        """

        from connect.resources.base import ApiClient
        response, _ = ApiClient(config, base_path='conversations/' + self.id + '/messages')\
            .post(json={'text': message})
        return ConversationMessage.deserialize(response)
コード例 #13
0
    def list_tier_configs(self, filters=None):
        """ List the tier configs.

        :param (dict[str, Any] filters: Filters to pass to the request.
        :return: A list with the tier configs that match the given filters.
        :rtype: list[TierConfig]
        """
        filters = filters or {}
        products_key = 'product.id'
        if products_key not in filters and self._config.products:
            filters[products_key] = ','.join(self._config.products)
        text, code = ApiClient(self._config,
                               'tier/configs').get(params=filters)
        return TierConfig.deserialize(text)
コード例 #14
0
    def list_assets(self, filters=None):
        """ List the assets.

        :param (dict[str, Any] filters: Filters to pass to the request.
        :return: A list with the assets that match the given filters.
        :rtype: list[Asset]
        """
        products = ','.join(
            self._config.products) if self._config.products else None
        url = self._config.api_url + 'assets?in(product.id,(' + products + '))' \
            if products \
            else 'assets'
        text, code = ApiClient(self._config, url).get(params=filters)
        return Asset.deserialize(text)
コード例 #15
0
 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)
コード例 #16
0
 def get_product_configurations(self, filters=None, config=None):
     """
     :param dict|Query 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]
     """
     query = copy(filters) if isinstance(filters, Query) else Query(filters)
     text, _ = ApiClient(
         config or Config.get_instance(),
         'products/' + self.id + '/configurations' + query.compile()).get()
     return ProductConfigurationParameter.deserialize(text)