PHP code example of buzzi-io / buzzi-sdk-php

1. Go to this page and download the library: Download buzzi-io/buzzi-sdk-php library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

buzzi-io / buzzi-sdk-php example snippets




use Buzzi\Sdk;

$sdk = new Sdk([
    Sdk::CONFIG_AUTH_ID => '<your-buzzi-api-id-here>',
    Sdk::CONFIG_AUTH_SECRET => '<your-buzzi-api-secret-here>',
    
    // Optional parameters:
    //
    // Sdk::CONFIG_HOST => <buzzi-host>, if is not set will be used either production or sandbox predefined hosts depends on Sdk::CONFIG_SANDBOX
    // Sdk::CONFIG_SANDBOX => false,
    // Sdk::CONFIG_DEBUG => false,
    // Sdk::CONFIG_LOG_FILE_NAME => \Buzzi\Http::DEFAULT_LOG_FILE_NAME,
    // Sdk::CONFIG_LOG_LINE_FORMAT => \Buzzi\Http::DEFAULT_LOG_LINE_FORMAT,
    // Sdk::CONFIG_LOG_MESSAGE_FORMAT => \Buzzi\Http::DEFAULT_LOG_MESSAGE_FORMAT
]);

$supportService = $sdk->getSupportService();

try {

    $isAuthorized = $supportService->isAuthorized();

} catch (\Buzzi\Exception\HttpException $e) {

    $isAuthorized = false;
}

$publishService = $sdk->getPublishService();

try {

    $eventId = $publishService->send('buzzi.generic.test', ["message" => "Hello, World", "timestamp" => date(DATE_ATOM)]);
    
} catch (\Buzzi\Exception\HttpException $e) {

    // The exceptions is thrown if http request is not successful
    
} catch (\RuntimeException $e) {

    // The exceptions is thrown if response does not contain event ID
}

$consumeService = $sdk->getConsumeService();

try {

    $countDeliveries = $consumeService->getCount();
    
} catch (\Buzzi\Exception\HttpException $e) {

    // The exceptions is thrown if http request is not successful
    
} catch (\RuntimeException $e) {

    // The exceptions is thrown if response does not contain count value
}

$consumeService = $sdk->getConsumeService();

try {

    $delivery = $consumeService->fetch();
    
} catch (\Buzzi\Exception\HttpException $e) {

    // The exceptions is thrown if http request is not successful
}

// fetchs all deliveries but not more then 100
list($deliveries, $exceptions) = $consumeService->batchFetch(100);

try {

    $consumeService->confirmDelivery($delivery);
    // OR
    $consumeService->confirm($delivery->getReceipt());

} catch (\Buzzi\Exception\HttpException $e) {

    // The exceptions is thrown if http request is not successful
}

try {

    // $errorData could contain any information about the error
    $errorData = [
        'message' => 'reason for error'
    ];
    $consumeService->submitError($delivery->getReceipt(), $errorData);

} catch (\Buzzi\Exception\HttpException $e) {

    // The exceptions is thrown if http request is not successful
}

try {

// request

} catch (\Buzzi\Exception\HttpException $e) {
    // The exceptions is thrown if http request is not successful

    $e->getMessage();           // returns either grabbed message from response body or reason phrase
    $e->getStatusCode();        // returns http status code of the response
    $e->getResponse();          // returns \Psr\Http\Message\ResponseInterface|\GuzzleHttp\Psr7\Response
    $e->getResponseBody();      // returns decoded response body
    $e->getResponseBody(false); // returns response body as json string
}