Skip to content

Service Contracts

Stanislav Idolov edited this page May 7, 2019 · 11 revisions

Search API

The search API endpoint is the main source of Adobe Stock assets and should be configurable and extensible. We encourage the re-usage of Magento framework interfaces is such cases.

Image List Interface

interface GetImageListInterface
{
    /**
     * @param SearchCriteriaInterface $searchCriteria
     * @return SearchResultsInterface
     */
    public function execute(SearchCriteriaInterface $searchCriteria) : SearchResultsInterface;
}

The interface accepts search criteria object that implements generic framework interface: \Magento\Framework\Api\SearchCriteriaInterface. The returned object will implement \Magento\Framework\Api\SearchResultsInterface interface that also defined in Magento framework.

Save Image API

In order to persist images to the Magento gallery, we defined two interfaces that will provide the ability to save image preview and licensed the image to the filesystem.

Both interfaces are accepting Adobe Stock media id for asset identification and download to the media gallery.

Save Image Preview Interface

interface SaveImagePreviewInterface
{
    /**
     * @param int $mediaId
     * @return bool
     */
    public function execute(int $mediaId): bool;
}

Save Licensed Image Interface

interface SaveLicensedImageInterface
{
    /**
     * @param int $mediaId
     * @return bool
     */
    public function execute(int $mediaId): bool;
}

Image metadata API

It's required to save image metadata along with image file to implement functionality that's need such data for business logic.

Proposed interface is a typical repository in Magento to work with entities.

interface ImageMetadataRepositoryInterface
{
    /**
     * @param ImageMetadataInterface $entityData
     * @return int
     */
    public function save(ImageMetadataInterface $entityData) : int;

    /**
     * @param int $entityId
     * @return ImageMetadataInterface
     */
    public function get(int $entityId) : ImageMetadataInterface;

    /**
     * @param ImageMetadataInterface $entityData
     * @return void
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     * @throws \Magento\Framework\Exception\CouldNotDeleteException
     */
    public function delete(ImageMetadataInterface $entityData);

    /**
     * @param int $entityId
     * @return void
     * @throws \Magento\Framework\Exception\NoSuchEntityException
     * @throws \Magento\Framework\Exception\CouldNotDeleteException
     */
    public function deleteById(int $entityId);

    /**
     * @param SearchCriteriaInterface $searchCriteria
     * @return SearchResultsInterface
     */
    public function getList(SearchCriteriaInterface $searchCriteria) : SearchResultsInterface;
}
Clone this wiki locally