Download the PHP package baileyherbert/envato without Composer
On this page you can find all versions of the php package baileyherbert/envato. It is possible to download/install these versions without Composer. Possible dependencies are resolved automatically.
Download baileyherbert/envato
More information about baileyherbert/envato
Files in baileyherbert/envato
Package envato
Short Description Client library for the Envato API that supports Personal Tokens and OAuth.
License MIT
Homepage https://bailey.sh/
Informations about the package envato
Envato.php
An API client for Envato in PHP, with simplified OAuth, token storage, and request sending.
- Notes
- Installation
- Authentication
- Personal Token
- OAuth
- Sending Requests
- Getting Request Time
- Rate Limiting
- Custom Requests
- Catalog
- Look up a public collection
- Look up a single item
- Look up a single WordPress theme/plugin version
- Search for items
- Search for comments
- Popular items by site
- Categories by site
- Prices for a particular item
- New items by site and category
- Find featured items
- Random new items
- Profile
- List all of current user's collections
- Look up a collection by ID
- Get a user's profile details
- List a user's badges
- Get a user's items by site
- Get a user's newest items
- User
- List an author's sales
- Look up a sale by purchase code
- List a buyer's purchases
- Look up a buyer's purchase by code
- Download a buyer's purchase
- Get private account details
- Get the current user's username
- Get the current user's email
- Get the user's earnings by month
- Get the user's statement
- Market
- Get total number of users
- Get total number of items
- Get total number of items by site
- Other Endpoints
- Get the client's identity
- Handling Errors \& Exceptions
- Authorization Errors
- Request Errors
- Examples
- Verifying Purchase Codes
- Breaking changes in v3
- Contributors
Notes
This API client is fully working though not necessarily completed. Of course, any updates that aren't backwards-compatible will be bumped up a major version. Other than that, here's some info you'll probably want to know.
- This client does not disable SSL. It ships with a Certificate Authority bundle and uses this bundle to verify the Envato API's SSL certificate, instead of relying on the system's often-unavailable certificate.
Installation
Include this into your project using Composer. It will be autoloaded.
Authentication
Personal Token
Start a new client with a personal token (create one at build.envato.com).
OAuth
With OAuth, you must redirect your users to Envato's authentication screen, where they will approve your requested permissions. Then, they will be redirected back to your application
with a code
query parameter that can be used to obtain an API token.
The following example demonstrates a complete OAuth guard that redirects the user and creates a client when they return. It also persists their credentials to a PHP session, so the client can be recreated and the token can be renewed in future requests.
To make this example work, create a new app at the build.envato.com website. The redirect_uri
should point directly to the file where the above
code is hosted and must be exactly the same both in the code and on the registered Envato App.
Tokens generated in this manner will expire after one hour. However, by using the store
callback and load()
method as shown above, the client can automatically renew them in the
background. When that happens, the store
callback will be invoked again with the new credentials.
Sending Requests
Here's an example request to get the current user's username. Currently, it returns a ResultSet
object; this object exposes a results
property which is an array of the raw API response.
For an endpoint which has variables, you can pass them as an array. This works for all endpoint versions, including legacy v1 and the new v3.
Getting Request Time
To determine how long a request took to execute (in seconds), you can reference the $response->time
property.
Rate Limiting
If you're being rate limited, the client will throw a TooManyRequestsException
exception. The exception instance has
methods to help work with the rate limit.
Custom Requests
If there is a new endpoint which is not yet available in this package, you may use the $request
property on the
client to manually send the request until it is added.
There are methods available for each request type (get
, post
, etc). Pass the path as the first parameter. Pass your
POST body variables as the second parameter, these will also replace variables in the path denoted by {}
.
Catalog
Look up a public collection
Look up a single item
Look up a single WordPress theme/plugin version
Search for items
Search for comments
Popular items by site
Categories by site
Prices for a particular item
New items by site and category
Find featured items
Random new items
Profile
The profile
category represents a public Envato user.
List all of current user's collections
Look up a collection by ID
Get a user's profile details
List a user's badges
Get a user's items by site
Get a user's newest items
User
The user
category represents the currently-authenticated user.
List an author's sales
Look up a sale by purchase code
List a buyer's purchases
Look up a buyer's purchase by code
Download a buyer's purchase
Get private account details
Get the current user's username
Get the current user's email
Get the user's earnings by month
Get the user's statement
Market
Get total number of users
Get total number of items
Get total number of items by site
Other Endpoints
Get the client's identity
The identity will be an object that looks like this:
If you only care about the userId
property, you can retrieve it more easily:
Handling Errors & Exceptions
All exceptions in this libary are under the Herbert\Envato\Exceptions
namespace.
Authorization Errors
When performing OAuth authorization, you may encounter one of these exceptions:
InvalidTokenException
if the token provided is not a string.MissingPropertyException
if OAuth is missing one of the constructor parameters (client_id, client_secret, redirect_uri).NotAuthenticatedException
if you try to construct anEnvatoClient
before being authenticated.
Request Errors
When performing a request, there are four possible exceptions that can be thrown.
BadRequestException
if required arguments are missing or are invalid.UnauthorizedException
if the current authorization is invalid.TooManyRequestsException
if requests are being throttled for high activity.EndpointException
if there was a major error (API down, no internet connection, etc).
Otherwise, if an error occurs in the request, it will be accessible in detail using the $response->error
property (which is null
when successful or a string
with error details otherwise).
Examples
Verifying Purchase Codes
If you're an author and want to check a purchase code provided to you from a buyer, this is an example for you. To make this work, you'll want to use Personal Token authentication.
Breaking changes in v3
If upgrading the package to v3
from an earlier version, there is a single breaking change. The user->sales()
method
was pointing to the wrong endpoint.
- The previous
$client->user->sales()
endpoint has been renamed to$client->user->earnings()
- The new
$client->user->earnings()
endpoint lists your earnings by month - The new
$client->user->sales()
endpoint lists your individual sales
Contributors
Special thanks to the following contributors for their help in maintaining this package: