Applications.php
1 year ago
Campaigns.php
1 year ago
Deliveries.php
1 year ago
Events.php
1 year ago
Installations.php
1 year ago
Rest.php
1 year ago
Segments.php
1 year ago
Stats.php
1 year ago
Events.php
38 lines
| 1 | <?php |
| 2 | |
| 3 | namespace WonderPush\Api; |
| 4 | |
| 5 | if (count(get_included_files()) === 1) { http_response_code(403); exit(); } // Prevent direct access |
| 6 | |
| 7 | use WonderPush\Params\TrackEventParams; |
| 8 | use WonderPush\Obj\SuccessResponse; |
| 9 | |
| 10 | /** |
| 11 | * Applications API. |
| 12 | */ |
| 13 | class Events { |
| 14 | |
| 15 | /** |
| 16 | * Instance of the library whose credentials are to be used. |
| 17 | * @var \WonderPush\WonderPush |
| 18 | */ |
| 19 | private $wp; |
| 20 | |
| 21 | public function __construct(\WonderPush\WonderPush $wp) { |
| 22 | $this->wp = $wp; |
| 23 | } |
| 24 | |
| 25 | /** |
| 26 | * Track an event |
| 27 | * @param array|TrackEventParams $params - When using an array, please specify the 'installationId', and 'userId' key with an empty string as value |
| 28 | * @return SuccessResponse |
| 29 | * @throws \WonderPush\Errors\Base |
| 30 | */ |
| 31 | public function track($params) { |
| 32 | $arrayParams = is_array($params) ? $params : $params->toArray(); |
| 33 | $response = $this->wp->rest()->post('/events', $arrayParams); |
| 34 | return $response->checkedResult('\WonderPush\Obj\SuccessResponse'); |
| 35 | } |
| 36 | |
| 37 | } |
| 38 |