Download the PHP package astock/stock-api-libphp without Composer

On this page you can find all versions of the php package astock/stock-api-libphp. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.

FAQ

After the download, you have to make one include require_once('vendor/autoload.php');. After that you have to import the classes with use statements.

Example:
If you use only one package a project is not needed. But if you use more then one package, without a project it is not possible to import the classes with use statements.

In general, it is recommended to use always a project to download your libraries. In an application normally there is more than one library needed.
Some PHP packages are not free to download and because of that hosted in private repositories. In this case some credentials are needed to access such packages. Please use the auth.json textarea to insert credentials, if a package is coming from a private repository. You can look here for more information.

  • Some hosting areas are not accessible by a terminal or SSH. Then it is not possible to use Composer.
  • To use Composer is sometimes complicated. Especially for beginners.
  • Composer needs much resources. Sometimes they are not available on a simple webspace.
  • If you are using private repositories you don't need to share your credentials. You can set up everything on our site and then you provide a simple download link to your team member.
  • Simplify your Composer build process. Use our own command line tool to download the vendor folder as binary. This makes your build process faster and you don't need to expose your credentials for private repositories.
Please rate this library. Is it a good library?

Informations about the package stock-api-libphp

Stock API libphp

Overview

This is a PHP implementation of the various APIs provided by the Stock services. Adobe Stock APIs are available here

Getting Started

  1. Use Git to clone the entire repository in the root folder, or export a zip of the repository and extract locally.
  2. Or, you can include this repository into your project using composer by adding the following configuration into your composer.json file:

  3. Or, you can refer to AdobeStock Sample For SDK to use this SDK in your project in a very handy way.

Prerequisites

To use the SDK you need to check for the following prerequisites:

  1. The SDK requires PHP 7.1 or higher. If you do not have that version, install it now.

  2. If Composer isn't already installed, install it from here. This is required to download project dependencies for the SDK.

    * For Mac, recommend Homebrew for this:
        * Run `brew install composer`.
        * If you get a message that the lock file is out of date, run `brew update composer`.

Build Steps

Usage

AdobeStock

In order to use the Stock APIs, one must initialize AdobeStock by passing config values like ApiKey, Product, environment which in turn initializes stock Config.

Environment Description
STAGE Uses internal staging environment.Mainly used for testing purposes
PROD Used in development purposes.

Accessing SearchFiles

SearchFiles

AdobeStock class will allow you to access the Search/Files Stock Api. You can query Adobe Stock for assets that meet your specified search criteria. You can construct the SearchFilesRequest object to set filters, sort order, set search keywords etc. for the Search/Files api.

First, You have to call searchFilesInitialize to initialize search files which will gives you adobe stock object from where you can call getNextResponse, getPreviousResponse etc. to fetch the results. The AdobeStock provides paginated interface which allows you to call its methods (for e.g. getNextResponse, getPreviousResponse etc.) multiple times to retrieve the subsequent search results in order. It maintains the current state of searchFiles request and initially, the state is pointing invalid search files results. As soon as, the getNextReponse method is called, it makes Search/Files api call and returns the results with SearchFilesReponse object. The getNextResponse moves the state to next page and fetch the response for the same. Similarly, the getPreviousResponse and getResponsePage methods can be used to move one page behind and skip to a particular search page index respectively.

Instantiation

You can construct the object of this class with below arguments -

Example

Sample code to initialize the SearchFiles Api -

More examples can be found at the end of this document.

Methods

SearchFilesRequest

In order to make SearchFiles API call, you need to create a SearchFileRequest object to define the search criterion for search files results. You can set the various search parameters, locale and required result columns supported by Stock Search/Files api here.

Here is the mapping of Search/Files api query parameters with the setters methods that you can use to set the corresponding parameters in PHP Stock SDK -

API URL Query Parameter Setter Methods in SearchFilesRequest Description
locale setLocale Sets location language code. For e.g. "en-US", "fr-FR" etc.
search_parameters[*] setSearchParams Sets An object of SearchParameters where one can set all supported search_parameters
similar_image setSimilarImage Sets an image data for visual similarity search. It will only be considered if similar image in SearchParameters is set to true.
result_columns[] setResultColumns Allows to set the list of result columns required in the search results. If you are not setting result columns, it will set all default columns in result_column array at api level. For more details, read Result Columns section below.

SearchParameters

SearchParameters allows to set the various search_parameters (URL query parameters) supported by Search/Files Stock api. This is the class where you can actually set the search keywords, limit, sort order, filters, media_id etc.

Mapping of query parameter search_parameters[*] with SearchParameters class setter methods -

Search Parameter Setter Methods Description
search_parameters[words] setWords Allows to set the key words that you want to search
search_parameters[limit] setLimit Allows to set maximum number of assets to return in the call.
search_parameters[offset] setOffset Allows to set the start position in search results.
search_parameters[order] setOrder Allows to set sorting order in which it will return found assets
search_parameters[creator_id] setCreatorId Allows to search by a specific asset creator's ID
search_parameters[media_id] setMediaId Allows to search for one specific asset by its unique identifier (media_id)
search_parameters[model_id] setModelId Allows to search for assets that portray a specific person (model) using the model's ID
search_parameters[serie_id] setSerieId Allows to search for assets in the specified series using the series ID
search_parameters[gallery_id] setGalleryId Allows to search with a specific galleryId filter
search_parameters[similar] setSimilar Allows to search for assets that are similar in appearance to an asset with a specific media ID
search_parameters[similar_url] setSimilarURL Allows to search for assets that are similar in appearance to an image at a specific URL
search_parameters[category] setCategory Allows to search for assets with a specific category ID
search_parameters[thumbnail_size] setThumbnailSize Allows to set the size of thumbnail(in pixels) to return for each found asset
search_parameters[filters][area_pixels] setFilterAreaPixels Allows to set image sizes in pixels for returned assets
search_parameters[filters][3d_type_id][] setFilter3DTypeIds Allows to set array specifying which 3D types to return
search_parameters[filters][template_type_id][] setFilterTemplateTypes Allows to set array specifying which template types to return
search_parameters[filters][template_category_id][] setFilterTemplateCategoryIds Allows to set array specifying which template categories to return
search_parameters[filters][has_releases] setFilterHasReleases Allows to return only that assets which has model or property releases
search_parameters[filters][content_type:photo] setFilterContentTypePhoto Allows to include found assets that are photos
search_parameters[filters][content_type:illustration] setFilterContentTypeIllustration Allows to include found assets that are illustrations
search_parameters[filters][content_type:vector] setFilterContentTypeVector Allows to include found assets that are vectors
search_parameters[filters][content_type:video] setFilterContentTypeVideo Allows to include found assets that are videos
search_parameters[filters][content_type:3d] setFilterContentType3D Allows to include found assets that are 3D items
search_parameters[similar_image] setSimilarImage Allows to set whether to use similar_image data for visual similarity search
search_parameters[filters][content_type:all] setFilterContentTypeAll Allows to include found assets of all content_types
search_parameters[filters][offensive:2] setFilterOffensive2 Allows to return found assets only if they are flagged as including Explicit/Nudity/Violence
search_parameters[filters][isolated:on] setFilterIsolatedOn Allows to return found assets only if the subject is isolated from the background by being on a uniformly colored background
search_parameters[filters][panoramic:on] setFilterPanoromicOn Allows to return found assets only if they are panoramic
search_parameters[filters][orientation] setFilterOrientation Allows to return found assets of the specified orientation
search_parameters[filters][age] setFilterAge Allows to return found assets of the specified age
search_parameters[filters][video_duration] setFilterVideoDuration Alows to return videos whose duration is no longer than the specified duration in seconds
search_parameters[filters][Premium] setPremium Allows to return found assets with premium (pricing) level
search_parameters[filters][colors] setFilterColors Allows to return only found assets that contain the specified colors
search_parameters[filters][Editorial] setFilterEditorial Allows to return only found assets that are editorial
search_parameters[filters][content_type:template] setFilterContentTypeTemplate Allows to include found assets that are of template types

Result Columns

You can create array of ResultColumn enums to define columns that you want to include in your search results.

Example
Note

If you are not setting result columns, it will set following columns in result_column array by default.

Making a SearchFilesRequest and Calling search files api

These are the complete examples showing how a search request is created and then search api is called, which in turn returns search results in the form of serchFileRequest.

Accessing SearchCategory

SearchCategory

AdobeStock class allows you to access the Search/Category and Search/CategoryTree Stock APIs. Each stock asset is placed into a category that classifies the asset, such as "Travel" or "Hobbies and Leisure" and each category has a unique identifying number, a name, and a path that you can use to access other assets in the same category.

You can construct the SearchCategoryRequest object to set category identifier and locale information. Then you can call searchCategory method to get information about a category of stock assets in the form of SearchCategoryResponse object. You can also call searchCategoryTree method to retrieve information for zero or more category identifiers in the form of list of SearchCategoryResponse object.

Instantiation

You can construct the object of this class with below arguments -

Example

Sample code to instantiate the SearchCategory API -

Methods

SearchCategoryRequest

In order to make SearchCategory/SearchCategoryTree API call, you need to create a SearchCategoryRequest object to define the search criterion for search category results. You can set category identifier and location language code supported by Stock Search Category/Category Tree API here.

Here is the mapping of Search Category/CategoryTree API query parameters with the setters methods that you can use to set the corresponding parameters in PHP Stock SDK -

API URL Query Parameter Setter Methods in SearchCategoryRequest Description
locale setLocale Sets location language code. For e.g. "en-US", "fr-FR" etc.
category_id setCategoryId Sets unique identifier for an existing category for e.g 1043

SearchCategoryResponse

It represents the search result returned from Stock Search/Category API. The AdobeStock class methods for e.g. searchCategory returns the object of SearchCategoryResponse initialized with the results returned from the Search/Category API. SearchCategoryResponse allows you to -

Accessing Files Metadata

Files

AdobeStock class allows you to access the Files Stock APIs. The Files API is used to retrieve metadata from Adobe Stock, either one asset at a time, or in bulk.

You can construct the \AdobeStock\Api\Request\Files object to set identifiers, locale information and desired result columns. Then you can call getFiles method to get metadata about the requested file ids in the form of \AdobeStock\Api\Response\Files object.

Instantiation

You can construct the object of this class with below arguments -

Example

Sample code to instantiate the Files API -

Methods

FilesRequest

In order to make GetFiles API call, you need to create a \AdobeStock\Api\Request\Files object to define the ids of the files that you are looking for metadata. You can set files identifiers, location language code and result columns supported by Bulk metadata Files API.

Here is the mapping of Files API query parameters with the setters methods that you can use to set the corresponding parameters in PHP Stock SDK -

API URL Query Parameter Setter Methods in SearchCategoryRequest Description
ids setIds Sets an array of files identifiers e.g array(105988)
locale setLocale Sets location language code. For e.g. "en-US", "fr-FR" etc.
result_columns setResultColumns Sets an array of requested metadata e.g array('id','title',...)
Note

If you are not setting result columns, it will set following columns in result_columns array by default.

FilesResponse

It represents the result returned from Files API. The AdobeStock class methods for e.g. getFiles returns the object of \AdobeStock\Api\Response\Files initialized with the results returned from the Files API. \AdobeStock\Api\Response\Files allows you to -

Accessing License

License

License class allows you to purchase an asset, information about purchasing the asset, information about a user's licensing (entitlement) status, determine whether the user has an existing license for an asset,for notifying the system when a user abandons a licensing operation, request a license for an asset for that user if user have authorization for licensing assets and fetch the URL of the asset if it is already licensed.

Instantiation

You can construct the object of this class with below arguments -

License Request

In order to call License APIs you need to create LicenseRequest object for licensing assets, for getting licensing information about a specific asset for specific user, for notifying the system when a user abandons a licensing operation, for getting the licensing capabilities for a specific user.

Request Parameter Setter Methods Related Constants (If applicable) Description
content_id setContentId Asset's unique identifer.You can get this from a Search response's id attribute
license setLicenseState licenseStateParams Use only with Content/Info, Content/License, and Member/Profile. The Adobe Stock licensing state for the asset.
locale setLocale Use only with Member/Profile.Optional. Location language code for the API to use when returning localized messages. The API can usually get the user's default locale through the Authorization header. This value overrides that or provides a locale if not available through Authorization.
state setPurchaseState purchaseStateParams Use only with Member/Abandon.The purchase_options.state from the Member/Profile results.
license_reference setLicenseReference Array of license references of type LicenseReference. Use only with Content/License API.
License State

Adobe Stock licensing state for the asset.

Purchase States

User's purchase relationship to an asset.

License Response

After calling various APIs in License class, reponse is returned in the form of LicenseResponse. It contains following fields. All class objects used in response are defined below.

Request Parameter Getter Methods Related Class Description
available_entitlement getEntitlement LicenseEntitlement Information about licenses available for the user. See LicenseEntitlement
purchase_options getPurchaseOptions LicensePurchaseOptions Information about the user's purchasing options for the asset. See LicensePurchaseOptions
member getMemberinfo LicenseMemberInfo Information about the user. See LicenseMemberInfo
license_references getLicenseReferences LicenseReferenceResponse List of license references of the user. See LicenseReferenceResponse
contents getContents LicenseContent Mapping from Asset unique identifier to Asset Licensing information. See LicenseContent
LicenseEntitlement
LicensePurchaseOptions
LicenseMemberInfo
LicenseReferenceResponse
LicenseContent

Methods

Examples

Examples showing how all methods are called with LicenseRequest and return LicenseResponse.

getContentInfo Example

getContentLicense Example

getMemberProfile Example

abandonLicense Example

downloadAssetRequest Example

downloadAssetUrl Example

downloadAssetStream Example

Accessing LicenseHistory

LicenseHistory

AdobeStock class will allow you to access the LicenseHistory Api. You can construct the LicenseHistoryRequest object to set offset, limit, set result columns etc. for the LicenseHistory api.

First, You have to call initializeLicenseHistory to initialize license history api which will gives you adobe stock object from where you can call getNextLicenseHistory, getPreviousLicenseHistory etc. to fetch the results. The AdobeStock provides paginated interface which allows you to call its methods (for e.g. getNextLicenseHistory, getPreviousLicenseHistory etc.) multiple times to retrieve the subsequent results in order. It maintains the current state of LicenseHistory request and initially, the state is pointing invalid LicenseHistory files results. As soon as, the getNextLicenseHistory method is called, it makes LicenseHistory api call and returns the results with LicenseHistoryResponse object. The getNextLicenseHistory moves the state to next page and fetch the response for the same. Similarly, the getPreviousLicenseHistory and getLicenseHistoryPage methods can be used to move one page behind and skip to a particular LicenseHistory page index respectively.

Instantiation

You can construct the object of this class with below arguments -

Example

Sample code to initialize the LicenseHistory Api -

More examples can be found at the end of this document.

Methods

LicenseHistoryRequest

In order to make LicenseHistory API call, you need to create a LicenseHistoryRequest object to define the criterion for LicenseHistory files results. You can set the various search parameters, locale and required result columns supported by Stock LicenseHistory api here.

Here is the mapping of LicenseHistory api query parameters with the setters methods that you can use to set the corresponding parameters in PHP Stock SDK -

API URL Query Parameter Setter Methods in SearchFilesRequest Description
locale setLocale Sets location language code. For e.g. "en-US", "fr-FR" etc.
search_parameters[*] setSearchParams Sets An object of SearchParamLicenseHistory where one can set all supported search_parameters
result_columns[] setResultColumns Allows to set the list of result columns required in the search results. If you are not setting result columns, it will set all default columns in result_column array at api level. For more details, read Result Columns section below.

SearchParameters

SearchParamLicenseHistory allows to set the various search_parameters (URL query parameters) supported by LicenseHistory api. This is the class where you can actually set the limit, offset, thumbnail_size etc.

Mapping of query parameter search_parameters[*] with SearchParamLicenseHistory class setter methods -

Search Parameter Setter Methods Description
search_parameters[limit] setLimit Allows to set maximum number of assets to return in the call.
search_parameters[offset] setOffset Allows to set the start position in results.
search_parameters[thumbnail_size] setThumbnailSize Allows to set thumbnail size.Valid values - 110, 160,220,240,500, 1000

Result Columns

You can create array of ResultColumn enums to define columns that you want to include in your results.

Example
Note

If you are not setting result columns, it will set following columns in result_column array by default.

LicenseHistoryResponse

It represents the LicenseHistory results returned with Stock LicenseHistory API. The LicenseHistory class methods for e.g. getNextLicenseHistory returns the object of LicenseHistoryResponse initialized with the results returned from the LicenseHistory api. LicenseHistoryResponse allows you to -

Making a LicenseHistoryRequest and Calling LicenseHistory api

These are the complete examples showing how a request is created and then LicenseHistory api is called, which in turn returns results in the form of LicenseHistoryRequest.

Testing and Linting

Tests

Run composer run check for linting and testcases. Run composer run test-coverage for test coverage.

The above command will by default run the linting, test cases and the code coverage along with building the project. The linting results will be shown within the console output itself and if there are any issues the build will stop and fail instantly. If there are no linting issues found, the build will continue to build the project. It will also generate the detailed coverage reports for you.

Lint with PHP_CodeSniffer

This project uses PHP_CodeSniffer for linting. In addition, Adobe Stock has a custom set of rules for PHPCS that are included in this repository in the libs directory. This module will be installed when running composer install. It includes a bundled version of PHPCS which may be different from the one you have installed globally; the Composer script will run the correct version.

Linting checks are enforced with the build step itself. By default, the linting will run first and if there are any issues the build will fail.

Running Test Suites

However, the composer run check will run the tests automatically but if you need to run the tests separately, please run the below command in console -

Coverage

Just run the composer run test-coverage as mentioned above, it should generate the coverage reports along with the test results and building the project. As mentioned above coverage reports can be found at <project directory>/data/clover/index.html

Contributing

If you would like to contribute to this project, check out our contribution guidelines.


All versions of stock-api-libphp with dependencies

PHP Build Version
Package Version
Requires php Version >=7.3
guzzlehttp/guzzle Version ~7.3
Composer command for our command line client (download client) This client runs in each environment. You don't need a specific PHP version etc. The first 20 API calls are free. Standard composer command

The package astock/stock-api-libphp contains the following files

Loading the files please wait ....