affise / php-sdk
Affise API's Official SDK
Installs: 4 782
Dependents: 0
Suggesters: 0
Security: 0
Stars: 4
Watchers: 5
Forks: 2
Open Issues: 2
Requires
- php: >=7.4
- ext-json: *
- guzzlehttp/guzzle: ^6.0 || ^7.0
- psr/http-client: ^1.0
- psr/http-factory: ^1.0
Requires (Dev)
- http-interop/http-factory-guzzle: ^1.0
- phpunit/phpunit: ^9.0
- vimeo/psalm: ^4.3
This package is auto-updated.
Last update: 2024-11-15 15:39:04 UTC
README
Requirements
- PHP >=7.4
- Guzzle >=6.0
- Any PSR-17 and PSR-18 Implementation (optional)
Installation
composer require affise/php-sdk
Usage
Create api instance
use Affise\Sdk\Api; require_once __DIR__ . '/vendor/autoload.php'; $api = Api::create('https://YOUR_API_DOMAIN', 'YOUR_API_KEY');
Call endpoints
$response = $api->users->usersList(['limit' => 10]); var_dump($response->getStatus(), $response->getData());
$response = $api->statistics->byAdvertiser(['filter' => ['date_from' => '2020-12-20', 'date_to' => '2020-12-31',]]); var_dump($response->getStatus(), $response->getData());
Upload files
Use \Affise\Sdk\Transport\File
for each file.
use Affise\Sdk\Transport\File; $response = $api->offerManaging->addOffer([ ... 'creativeFiles' => File::createFromFile('path/to/file'), ... ]); var_dump($response->getStatus(), $response->getData());
List of providers
Advanced
Providers
Each provider is a set of grouped endpoints.
use Affise\Sdk\Transport\GuzzleTransport; use Affise\Sdk\Affiliate\AffiliateProvider; use Affise\Sdk\User\UserProvider; require_once __DIR__ . '/vendor/autoload.php'; $transport = new GuzzleTransport('https://YOUR_API_DOMAIN', 'YOUR_API_KEY'); $userProvider = new UserProvider($transport); $affiliateProvider = new AffiliateProvider($transport); $response = $userProvider->usersList(['limit' => 10]); var_dump($response->getStatus(), $response->getData()); $response = $affiliateProvider->affiliateList(['limit' => 10, 'page' => 5]); var_dump($response->getStatus(), $response->getData(), $response->getPagination()->getPage());
Transport layer
Transport is an abstraction layer over HTTP clients.
use Affise\Sdk\Transport\GuzzleTransport; use Affise\Sdk\Transport\PsrTransport; use GuzzleHttp\Client; require_once __DIR__ . '/vendor/autoload.php'; $transport = new GuzzleTransport('https://YOUR_API_DOMAIN', 'YOUR_API_KEY'); // Or you can use psr adapter $transport = new PsrTransport( new Http\Factory\Guzzle\RequestFactory(), new Http\Factory\Guzzle\UriFactory(), new Http\Factory\Guzzle\StreamFactory(), new Client(), 'https://YOUR_API_DOMAIN', 'YOUR_API_KEY' ); $raw = $transport->get('/3.0/admin/users', ['limit' => 10]); var_dump($raw); $raw = $transport->post('/3.0/admin/user/api_key/594927bd7e28fe1c4a8b4567'); var_dump($raw);
You can create your own transport. Just implement Affise\Sdk\Transport\TransportInterface
.
Customize api transport
use Affise\Sdk\Api; use Affise\Sdk\Transport\GuzzleTransport; require_once __DIR__ . '/vendor/autoload.php'; $api = new Api(new GuzzleTransport('https://YOUR_API_DOMAIN', 'YOUR_API_KEY'));
Test
./vendor/bin/phpunit tests
License
The MIT license. Read LICENSE file.