setono/kraken-io-php-sdk

A PHP SDK for the kraken.io API

v1.1.1 2020-11-26 11:49 UTC

This package is auto-updated.

Last update: 2021-11-15 15:03:54 UTC


README

Latest Version Latest Unstable Version Software License Build Status

A PHP SDK for the Kraken.io API.

Installation

Download

Open a command console, enter your project directory and execute the following command to download the latest stable version of this library:

$ composer require setono/kraken-io-php-sdk

This command requires you to have Composer installed globally, as explained in the installation chapter of the Composer documentation.

Install HTTP client

This library is HTTP client agnostic so you need to provide your own PSR18 HTTP client implementation. If you don't want to bother with this, you can just do this:

$ composer require kriswallsmith/buzz nyholm/psr7

This will install the PSR18 HTTP client, Buzz and HTTP message factories used to create requests, responses, and streams.

Usage

Upload file via URL and wait for a response

<?php
use Setono\Kraken\Client\Client;
use Setono\Kraken\Client\Response\WaitResponse;

$client = new Client('Your API key', 'Your API secret');

/** @var WaitResponse $response */
$response = $client->url('https://www.your-domain.com/your/image.jpg', true);

/** @var SplFileInfo $optimizedImageFile */
$optimizedImageFile = $response->getFile();

Get user status

<?php
use Setono\Kraken\Client\Client;
use Setono\Kraken\Client\Response\UserStatusResponse;

$client = new Client('Your API key', 'Your API secret');

/** @var UserStatusResponse $response */
$response = $client->status();

echo sprintf('Quota total: %s', $response->getQuotaTotal());
echo sprintf('Quota used: %s', $response->getQuotaUsed());
echo sprintf('Quota remaining: %s', $response->getQuotaRemaining());

I want to use my own HTTP client implementation and message factories

You can inject your own implementations when instantiating the client:

<?php
use Setono\Kraken\Client\Client;

$client = new Client('Your API key', 'Your API secret', $httpClient, $httpRequestFactory, $httpStreamFactory);