PHP code example of sendynl / php-sdk

1. Go to this page and download the library: Download sendynl/php-sdk 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/ */

    

sendynl / php-sdk example snippets




$connection = new \Sendy\Api\Connection();

$connection->setAccessToken('your-personal-access-token');

$connection->me->get();

$connection = new \Sendy\Api\Connection();

$connection->setOauthClient(true);

$connection->setClientId('your-client-id')
    ->setClientSecret('your-client-secret')
    ->setRedirectUrl('your-callback-url');

$connection->redirectForAuthorization();

$connection = new \Sendy\Api\Connection();

$connection->setClientId('your-client-id')
    ->setClientSecret('your-client-secret')
    ->setRedirectUrl('your-callback-url');

// Either an authorization code or a refresh token is nnection->setTokenExpires(1123581321);

$connection->me->get();

// Store the access token, refresh token en the expiration timestamp in your application to prevent unnecessary
// requesting new access tokens
$connection->getAccessToken();
$connection->getRefreshToken();
$connection->getTokenExpires();

$connection = new \Sendy\Api\Connection();

$connection->setOauthClient(true);

$connection->setClientId('your-client-id')
    ->setClientSecret('your-client-secret')
    ->setRedirectUrl('your-callback-url')
    ->setTokenUpdateCallback(function (\Sendy\Api\Connection $connection) {
        $data = [
            'access_token' => $connection->getAccessToken(),
            'refresh_token' => $connection->getRefreshToken(),
            'token_expires' => $connection->getTokenExpires(),
        ];
        
        // Use this data to store the tokens in your application
    });

use Illuminate\Foundation\Application;
use Illuminate\Support\Arr;
use Illuminate\Support\Facades\Http;
use Sendy\Api\Exceptions\TransportException;
use Sendy\Api\Http\Request;
use Sendy\Api\Http\Response;
use Sendy\Api\Http\Transport\TransportInterface

class LaravelTransport implements TransportInterface
{
    public function send(Request $request): Response
    {
        $headers = $request->getHeaders();
        $contentType = Arr::pull($headers, 'Content-Type', 'application/json');

        try {
            $response = Http::withHeaders($headers)
                ->withBody($request->getBody(), $contentType)
                ->withMethod($request->getMethod())
                ->withUrl($request->getUrl())
                ->send();
        } catch (\Throwable $e) {
            throw new TransportException($e->getMessage(), $e->getCode(), $e);
        }

        return new Response($response->status(), $response->headers(), $response->body());
    }

    public function getUserAgent() : string
    {
        return 'LaravelHttpClient/' . Application::VERSION;
    }
}

$connection = new \Sendy\Api\Connection();

$connection->setTransport(new LaravelTransport());

composer