summaryrefslogtreecommitdiffstats
path: root/examples/message-events/get_message_events_with_retry_logic.php
blob: 68225cb3b6a3d8cb5d4f9eee17c935428886f10f (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
<?php

namespace Examples\Templates;

require dirname(__FILE__).'/../bootstrap.php';

use SparkPost\SparkPost;
use GuzzleHttp\Client;
use Http\Adapter\Guzzle6\Client as GuzzleAdapter;

$httpClient = new GuzzleAdapter(new Client());

$sparky = new SparkPost($httpClient, ["key" => "YOUR_API_KEY", "retries" => 3]);

$promise = $sparky->request('GET', 'message-events', [
    'campaign_ids' => 'CAMPAIGN_ID',
]);

/**
 * If this fails with a 5xx it will have failed 4 times
 */
try {
    $response = $promise->wait();
    echo $response->getStatusCode()."\n";
    print_r($response->getBody())."\n";
} catch (\Exception $e) {
    echo $e->getCode()."\n";
    echo $e->getMessage()."\n";

    if ($e->getCode() >= 500 && $e->getCode() <= 599) {
        echo "Wow, this failed epically";
    }
}