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
Installations.php
53 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\Obj\InstallationCollection; |
| 8 | use WonderPush\Params\AllInstallationsParams; |
| 9 | use WonderPush\Params\PatchInstallationParams; |
| 10 | use WonderPush\Obj\SuccessResponse; |
| 11 | |
| 12 | /** |
| 13 | * Applications API. |
| 14 | */ |
| 15 | class Installations { |
| 16 | |
| 17 | /** |
| 18 | * Instance of the library whose credentials are to be used. |
| 19 | * @var \WonderPush\WonderPush |
| 20 | */ |
| 21 | private $wp; |
| 22 | |
| 23 | public function __construct(\WonderPush\WonderPush $wp) { |
| 24 | $this->wp = $wp; |
| 25 | } |
| 26 | |
| 27 | /** |
| 28 | * List applications associated with the access token used to initialize the WonderPush object. |
| 29 | * @param array|AllInstallationsParams $params |
| 30 | * @return InstallationCollection |
| 31 | * @throws \WonderPush\Errors\Base |
| 32 | */ |
| 33 | public function all($params = array()) { |
| 34 | $response = $this->wp->rest()->get('/installations', is_array($params) ? $params : $params->toArray()); |
| 35 | return $response->checkedResult('\WonderPush\Obj\InstallationCollection'); |
| 36 | } |
| 37 | |
| 38 | /** |
| 39 | * Partially update an existing installation |
| 40 | * @param array|PatchInstallationParams $params - When using an array, please specify the 'installationId', and 'userId' key with an empty string as value |
| 41 | * @return SuccessResponse |
| 42 | * @throws \WonderPush\Errors\Base |
| 43 | */ |
| 44 | public function patch($params) { |
| 45 | $arrayParams = is_array($params) ? $params : $params->toArray(); |
| 46 | $installationId = $arrayParams['installationId']; |
| 47 | unset($arrayParams['installationId']); |
| 48 | $response = $this->wp->rest()->patch('/installations/' . $installationId, $arrayParams); |
| 49 | return $response->checkedResult('\WonderPush\Obj\SuccessResponse'); |
| 50 | } |
| 51 | |
| 52 | } |
| 53 |