-
Notifications
You must be signed in to change notification settings - Fork 2
/
ResponseExample.php
110 lines (95 loc) · 3.19 KB
/
ResponseExample.php
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
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
<?php
declare(strict_types=1);
/**
* This file is part of the Pushover package.
*
* (c) Serhiy Lunak <https://github.com/slunak>
*
* For the full copyright and license information, please view the LICENSE
* file that was distributed with this source code.
*/
namespace Serhiy\Pushover\Example;
use Serhiy\Pushover\Api\Message\Message;
use Serhiy\Pushover\Api\Message\Notification;
use Serhiy\Pushover\Application;
use Serhiy\Pushover\Client\Request\Request;
use Serhiy\Pushover\Client\Response\MessageResponse;
use Serhiy\Pushover\Recipient;
/**
* Response object example.
*
* @author Serhiy Lunak <[email protected]>
*/
final class ResponseExample
{
public function responseExample(): void
{
// instantiate pushover application and recipient of the notification (can be injected into service using Dependency Injection)
$application = new Application('replace_with_pushover_application_api_token');
$recipient = new Recipient('replace_with_pushover_user_key');
// compose a message
$message = new Message('This is a test message', 'Simple Notification');
// create notification
$notification = new Notification($application, $recipient, $message);
// push notification
/**
* Response object.
*
* @var MessageResponse $response
*/
$response = $notification->push();
/**
* True if request was successful, false otherwise. Reflects $requestStatus property.
*
* @var bool
*/
$response->isSuccessful();
/**
* Status returned by Pushover API.
* Either 1 if successful or something other than 1 if unsuccessful.
* Reflects $isSuccessful property.
*
* @var int
*/
$response->getRequestStatus();
/**
* Request returned by Pushover API.
* Randomly-generated unique token that associated with your Pushover request.
*
* @var string
*/
$response->getRequestToken();
/**
* Receipt.
* When your application sends an emergency-priority notification, API will respond with a receipt value
* that can be used to get information about whether the notification has been acknowledged.
* See {@link https://pushover.net/api/receipts} for more information.
*
* @var string
*/
$response->getReceipt();
/**
* Errors array.
* In case of errors, API will return array detailing which parameters were invalid.
*
* @var string[]
*/
$response->getErrors();
/**
* Original curl response.
* Original, unmodified response from curl request.
*
* @var string
*/
$response->getCurlResponse();
/**
* Object Containing request.
* It contains array for CURLOPT_POSTFIELDS curl argument and API URL.
*
* @var Request
*/
$request = $response->getRequest();
$request->getCurlPostFields(); // array, array for CURLOPT_POSTFIELDS curl argument
$request->getApiUrl(); // string, API URL
}
}