Applications.php
5 months 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
Applications.php
59 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\ApplicationCollection; |
| 8 | use WonderPush\Params\CollectionParams; |
| 9 | |
| 10 | /** |
| 11 | * Applications API. |
| 12 | */ |
| 13 | class Applications { |
| 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 | * List applications associated with the access token used to initialize the WonderPush object. |
| 27 | * @param array|CollectionParams $collectionParams |
| 28 | * @return ApplicationCollection |
| 29 | * @throws \WonderPush\Errors\Base |
| 30 | */ |
| 31 | public function all($collectionParams = array()) { |
| 32 | $response = $this->wp->rest()->get('/applications', is_array($collectionParams) ? $collectionParams : $collectionParams->toArray()); |
| 33 | return $response->checkedResult('\WonderPush\Obj\ApplicationCollection'); |
| 34 | } |
| 35 | |
| 36 | public function patch($applicationId, $body = array(), $params = array()) { |
| 37 | $response = $this->wp->rest()->patch('/applications/' . $applicationId, array_merge($params, array('body' => $body))); |
| 38 | return $response->checkedResult('\WonderPush\Obj\Application', 'application'); |
| 39 | } |
| 40 | |
| 41 | /** |
| 42 | * Get domains for an application. |
| 43 | * @param string $applicationId |
| 44 | * @return \WonderPush\Obj\WebDomain[] |
| 45 | * @throws \WonderPush\Errors\Base |
| 46 | */ |
| 47 | public function domains($applicationId) { |
| 48 | $response = $this->wp->rest()->get('/applications/' . urlencode($applicationId) . '/domains'); |
| 49 | $body = $response->parsedBody(); |
| 50 | $domains = array(); |
| 51 | if (isset($body->domains) && is_array($body->domains)) { |
| 52 | foreach ($body->domains as $domainData) { |
| 53 | $domains[] = new \WonderPush\Obj\WebDomain($domainData); |
| 54 | } |
| 55 | } |
| 56 | return $domains; |
| 57 | } |
| 58 | } |
| 59 |