Skip to content

Commit

Permalink
Include the ListingTrailer in Azure Models
Browse files Browse the repository at this point in the history
This commit includes the missing Azure Resource `ListingTrailer` into
the models.

It also include the schema for the missing element and update the docs.
  • Loading branch information
JAVGan committed Mar 3, 2023
1 parent 31dfcfa commit fa2f60d
Show file tree
Hide file tree
Showing 7 changed files with 399 additions and 2 deletions.
78 changes: 76 additions & 2 deletions cloudpub/models/ms_azure.py
Original file line number Diff line number Diff line change
Expand Up @@ -737,6 +737,36 @@ class Contact(AttrsJSONDecodeMixin):
"""The contact phone."""


@define
class ThumbnailURL(AttrsJSONDecodeMixin):
"""
Define a video thumbnail URL.
It's part of :class:`~cloudpub.models.ms_azure.VideoThumbnails`.
"""

url: str
"""URL of the thumbnail."""


@define
class VideoThumbnails(AttrsJSONDecodeMixin):
"""
Define a group of thumbnails.
It's part of :class:`~cloudpub.models.ms_azure.ListingTrailer`.
"""

title: str
"""The thumbnail title."""

image_list: List[ThumbnailURL] = field(
metadata={"alias": "imageList"},
converter=lambda x: [ThumbnailURL.from_json(a) for a in x] if x else [], # type: ignore
on_setattr=NO_OP,
)


@define
class Listing(AzureProductLinkedResource):
"""
Expand Down Expand Up @@ -897,10 +927,53 @@ def listing_id(self):
.. _durable ID: https://learn.microsoft.com/en-us/azure/marketplace/product-ingestion-api#method-2-durable-id
""" # noqa E501
# durable ID format example:
# product/62c171e9-a2e1-45ab-9af0-d17e769da954
# listing/62c171e9-a2e1-45ab-9af0-d17e769da954/.../...
# what do we want:
# 62c171e9-a2e1-45ab-9af0-d17e769da954
return self.product_durable_id.split("/")[-1]
return self.listing_durable_id.split("/")[1]


@define
class ListingTrailer(AzureProductLinkedResource):
"""Represent a video "trailer" asset for the given product.
`Schema definition for ListingTrailer <https://product-ingestion.azureedge.net/schema/listing-trailer/2022-03-01-preview3>`_
""" # noqa E501

kind: str
"""Expected to be ``azure``."""

listing_durable_id: str = field(metadata={"alias": "listing"})
"""
The listing-trailer `durable ID`_.
"""

streaming_url: str = field(metadata={"alias": "streamingUrl"})
"""
The URL for the video streaming.
E.g: https://www.youtube.com/watch?v=XXXXX
"""

assets: Dict[Literal["en-us"], VideoThumbnails]
"""
Assets for the related video trailer.
At the moment only content in English is supported.
"""

@property
def listing_id(self):
"""
Resolve the listing-trailer ID from its `durable ID`_.
.. _durable ID: https://learn.microsoft.com/en-us/azure/marketplace/product-ingestion-api#method-2-durable-id
""" # noqa E501
# durable ID format example:
# listing-trailer/62c171e9-a2e1-45ab-9af0-d17e769da954/.../...
# what do we want:
# 62c171e9-a2e1-45ab-9af0-d17e769da954
return self.listing_durable_id.split("/")[1]


@define
Expand Down Expand Up @@ -1587,6 +1660,7 @@ def base_plan_id(self) -> Optional[str]:
"plan-listing": PlanListing,
"listing": Listing,
"listing-asset": ListingAsset,
"listing-trailer": ListingTrailer,
"price-and-availability-offer": PriceAndAvailabilityOffer,
"price-and-availability-plan": PriceAndAvailabilityPlan,
"virtual-machine-plan-technical-configuration": VMIPlanTechConfig,
Expand Down
2 changes: 2 additions & 0 deletions cloudpub/ms_azure/service.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
DiskVersion,
Listing,
ListingAsset,
ListingTrailer,
OSDiskURI,
PlanListing,
PlanSummary,
Expand Down Expand Up @@ -52,6 +53,7 @@
CustomerLeads,
Listing,
ListingAsset,
ListingTrailer,
PlanListing,
PlanSummary,
PriceAndAvailabilityOffer,
Expand Down
9 changes: 9 additions & 0 deletions docs/cloud_providers/models/azure.rst.incl
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,9 @@ The following models are elements of :class:`~cloudpub.models.ms_azure.Product`'
.. autoclass:: cloudpub.models.ms_azure.ListingAsset()
:members:

.. autoclass:: cloudpub.models.ms_azure.ListingTrailer()
:members:

.. autoclass:: cloudpub.models.ms_azure.PlanSummary()
:members:

Expand Down Expand Up @@ -153,6 +156,12 @@ The following models are inner elements of some subclasses of :class:`~cloudpub.
.. autoclass:: cloudpub.models.ms_azure.TableLeadConfiguration()
:members:

.. autoclass:: cloudpub.models.ms_azure.ThumbnailURL()
:members:

.. autoclass:: cloudpub.models.ms_azure.VideoThumbnails()
:members:

.. autoclass:: cloudpub.models.ms_azure.VMImageDefinition()
:members:

Expand Down
Loading

0 comments on commit fa2f60d

Please sign in to comment.