├── .gitattributes ├── .gitignore ├── LICENSE ├── README.md ├── composer.json ├── config └── pushover.php └── src ├── Api ├── Api.php ├── ApiFake.php └── ApiService.php ├── PushoverLimitation.php ├── PushoverMessage.php ├── PushoverReceipt.php ├── Responses ├── LimitsResponse.php ├── MessageResponse.php ├── PushoverResponse.php ├── ReceiptCancelRetriesResponse.php └── ReceiptResponse.php └── ServiceProvider.php /.gitattributes: -------------------------------------------------------------------------------- 1 | tests/ export-ignore 2 | -------------------------------------------------------------------------------- /.gitignore: -------------------------------------------------------------------------------- 1 | vendor/ 2 | node_modules/ 3 | .idea/ 4 | -------------------------------------------------------------------------------- /LICENSE: -------------------------------------------------------------------------------- 1 | MIT License 2 | 3 | Copyright (c) 2018 edwardkarlsson 4 | 5 | Permission is hereby granted, free of charge, to any person obtaining a copy 6 | of this software and associated documentation files (the "Software"), to deal 7 | in the Software without restriction, including without limitation the rights 8 | to use, copy, modify, merge, publish, distribute, sublicense, and/or sell 9 | copies of the Software, and to permit persons to whom the Software is 10 | furnished to do so, subject to the following conditions: 11 | 12 | The above copyright notice and this permission notice shall be included in all 13 | copies or substantial portions of the Software. 14 | 15 | THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR 16 | IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, 17 | FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE 18 | AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER 19 | LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, 20 | OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE 21 | SOFTWARE. 22 | 23 | -------------------------------------------------------------------------------- /README.md: -------------------------------------------------------------------------------- 1 | # A Pushover.net API implementation for Laravel 5 2 | 3 | A simple, yet very powerful, package that helps you get started with sending push notifications to your iOS or Android device through the [pushover.net](https://pushover.net/) service. 4 | 5 | ### Content 6 | - [Installation](#installation) 7 | - [Configuration](#configuration) 8 | - [Usage](#usage) 9 | - [License](#license) 10 | 11 | ### Installation 12 | To get the latest version of edwardkarlsson/laravel-pushover simply require it in your `composer.json` file. 13 | 14 | ```bash 15 | composer require edwardkarlsson/laravel-pushover:dev-master 16 | ``` 17 | 18 | This package utilizes the autodiscovery features of Laravel so the installation will be a breeze. 19 | 20 | ### Configuration 21 | The only configuration you need to do is to add the following to your `.env` file 22 | 23 | ```js 24 | PUSHOVER_TOKEN=[enter your token here] 25 | PUSHOVER_USER=[place this your user key here] 26 | ``` 27 | 28 | ### Usage 29 | #### Send message 30 | To send a notification, simply add this to your code: 31 | ```php 32 | $message = new PushoverMessage('My message'); 33 | $message->send(); 34 | ``` 35 | You can optionally add a second parameter that will be attached as a title to the message 36 | ```php 37 | $message = new PushoverMessage('My content', 'My title'); 38 | $message->send(); 39 | ``` 40 | _Don't forget to import the class into your file: `use Pushover\PushoverMessage;`_ 41 | 42 | Advanced usage: 43 | ```php 44 | $message = new PushoverMessage('My message content.', 'My title!'); 45 | 46 | $message->isHtml() 47 | ->sound('cashregister') 48 | ->url('http://example.com') 49 | ->urlTitle('ExampleSite') 50 | ->priority(1) 51 | ->device('my-main-device') 52 | ->send(); 53 | ``` 54 | 55 | #### Get limits 56 | To get your monthly limits, write the following: 57 | ```php 58 | $limitation = new PushoverLimitation(); 59 | 60 | $limitsResponse = $limitation->get(); 61 | 62 | echo $limitsResponse->limit(); 63 | echo $limitsResponse->remaining(); 64 | echo $limitsResponse->reset(); 65 | ``` 66 | 67 | #### Get receipt 68 | When a message with priority `2` is sent, you can get a receipt to check on the acknowledgment of the message. 69 | 70 | ```php 71 | $message = new PushoverMessage($this->faker->sentence, $this->faker->word); 72 | 73 | $messageResponse = $message 74 | ->priority(2) 75 | ->retry(30) 76 | ->expire(120) 77 | ->send(); 78 | 79 | $receiptResponse = $messageResponse->receipt()->get(); 80 | 81 | // Available methods 82 | $receiptResponse->acknowledged(); // returns boolean 83 | $receiptResponse->acknowledgedAt(); // returns Carbon 84 | $receiptResponse->acknowledgedBy(); // returns string 85 | $receiptResponse->acknowledgedByDevice(); // returns string 86 | $receiptResponse->lastDeliveredAt(); // returns Carbon 87 | $receiptResponse->expired(); // returns boolean 88 | $receiptResponse->expiresAt(); // returns Carbon 89 | $receiptResponse->calledBack(); // returns boolean 90 | $receiptResponse->calledBackAt(); // returns Carbon 91 | ``` 92 | 93 | #### License 94 | 95 | Copyright (c) 2018 Edward Karlsson Licensed under the [MIT license](https://github.com/edwardkarlsson/laravel-pushover/blob/master/LICENSE). 96 | -------------------------------------------------------------------------------- /composer.json: -------------------------------------------------------------------------------- 1 | { 2 | "name": "edwardkarlsson/laravel-pushover", 3 | "description": "A simple, yet very powerful, package that helps you get started with sending push notifications to your iOS or Android device through the pushover.net service.", 4 | "type": "library", 5 | "keywords": ["laravel", "pushover", "notification"], 6 | "license": "MIT", 7 | "authors": [ 8 | { 9 | "name": "Edward Karlsson", 10 | "email": "edward@medinaproduction.se" 11 | } 12 | ], 13 | "require": { 14 | "php": ">=7.0", 15 | "laravel/framework": "~5.4", 16 | "fzaninotto/faker": "~1.7" 17 | }, 18 | "require-dev": { 19 | "mockery/mockery": "^0.9.5", 20 | "phpunit/phpunit": "~7.0" 21 | }, 22 | "autoload": { 23 | "psr-4": { 24 | "Pushover\\": "src/", 25 | "Pushover\\Tests\\": "tests/" 26 | } 27 | }, 28 | "scripts": { 29 | "test": "vendor/bin/phpunit" 30 | }, 31 | "extra": { 32 | "laravel": { 33 | "providers": [ 34 | "Pushover\\ServiceProvider" 35 | ] 36 | } 37 | } 38 | } 39 | -------------------------------------------------------------------------------- /config/pushover.php: -------------------------------------------------------------------------------- 1 | env('PUSHOVER_TOKEN'), 5 | 'user' => env('PUSHOVER_USER'), 6 | ]; 7 | -------------------------------------------------------------------------------- /src/Api/Api.php: -------------------------------------------------------------------------------- 1 | api = new ApiService(); 28 | } 29 | 30 | /** 31 | * @return LimitsResponse 32 | */ 33 | public function get() 34 | { 35 | $response = $this->api->get($this->endpoint); 36 | 37 | return new LimitsResponse($response); 38 | } 39 | } 40 | -------------------------------------------------------------------------------- /src/PushoverMessage.php: -------------------------------------------------------------------------------- 1 | message = $message; 54 | $this->title = $title; 55 | $this->api = new ApiService(); 56 | } 57 | 58 | /** 59 | * @param string $title 60 | * 61 | * @return $this 62 | */ 63 | public function title(string $title) 64 | { 65 | $this->title = $title; 66 | 67 | return $this; 68 | } 69 | 70 | /** 71 | * @param $sound 72 | * 73 | * @return $this 74 | */ 75 | public function sound($sound) 76 | { 77 | $this->sound = $sound; 78 | 79 | return $this; 80 | } 81 | 82 | /** 83 | * @return $this 84 | */ 85 | public function isHtml() 86 | { 87 | $this->html = 1; 88 | 89 | return $this; 90 | } 91 | 92 | /** 93 | * @param string $url 94 | * 95 | * @return $this 96 | */ 97 | public function url(string $url) 98 | { 99 | $this->url = $url; 100 | 101 | return $this; 102 | } 103 | 104 | /** 105 | * @param string $urlTitle 106 | * 107 | * @return $this 108 | */ 109 | public function urlTitle(string $urlTitle) 110 | { 111 | $this->url_title = $urlTitle; 112 | 113 | return $this; 114 | } 115 | 116 | /** 117 | * @param string $device 118 | * 119 | * @return $this 120 | */ 121 | public function device(string $device) 122 | { 123 | $this->device = $device; 124 | 125 | return $this; 126 | } 127 | 128 | /** 129 | * @param $priority 130 | * 131 | * @return $this 132 | */ 133 | public function priority($priority) 134 | { 135 | $this->priority = $priority; 136 | 137 | return $this; 138 | } 139 | 140 | /** 141 | * @param int $interval 142 | * 143 | * @return $this 144 | */ 145 | public function retry(int $interval) 146 | { 147 | $this->retry = $interval; 148 | 149 | return $this; 150 | } 151 | 152 | /** 153 | * @param int $duration 154 | * 155 | * @return $this 156 | */ 157 | public function expire(int $duration) 158 | { 159 | $this->expire = $duration; 160 | 161 | return $this; 162 | } 163 | 164 | /** 165 | * @param string $callbackUrl 166 | * 167 | * @return $this 168 | */ 169 | public function callback(string $callbackUrl) 170 | { 171 | $this->callback = $callbackUrl; 172 | 173 | return $this; 174 | } 175 | 176 | /** 177 | * @param string|null $time 178 | * 179 | * @return MessageResponse 180 | */ 181 | public function send(string $time = null) 182 | { 183 | $response = $this->api->post($this->endpoint, $this->toArray()); 184 | 185 | return new MessageResponse($response); 186 | } 187 | 188 | /** 189 | * @return array 190 | */ 191 | public function toArray(): array 192 | { 193 | return [ 194 | 'title' => $this->title, 195 | 'message' => $this->message, 196 | 'url' => $this->url, 197 | 'url_title' => $this->url_title, 198 | 'sound' => $this->sound, 199 | 'html' => $this->html, 200 | 'priority' => $this->priority, 201 | 'device' => $this->device, 202 | 'retry' => $this->retry, 203 | 'expire' => $this->expire, 204 | 'callback' => $this->callback, 205 | ]; 206 | } 207 | } 208 | -------------------------------------------------------------------------------- /src/PushoverReceipt.php: -------------------------------------------------------------------------------- 1 | receiptToken = $receiptToken; 29 | $this->api = new ApiService(); 30 | } 31 | 32 | /** 33 | * Retrieves the message receipt info. 34 | * 35 | * @return ReceiptResponse 36 | */ 37 | public function retrieveInfo() 38 | { 39 | $endpoint = '/1/receipts/' . $this->receiptToken . '.json'; 40 | $response = $this->api->get($endpoint); 41 | 42 | return new ReceiptResponse($response); 43 | } 44 | 45 | /** 46 | * @return ReceiptCancelRetriesResponse 47 | */ 48 | public function cancel() 49 | { 50 | $endpoint = '/1/receipts/' . $this->receiptToken . '/cancel.json'; 51 | 52 | return new ReceiptCancelRetriesResponse($this->api->post($endpoint)); 53 | } 54 | } 55 | -------------------------------------------------------------------------------- /src/Responses/LimitsResponse.php: -------------------------------------------------------------------------------- 1 | limit = $response->limit; 29 | $this->remaining = $response->remaining; 30 | $this->reset = $response->reset; 31 | } 32 | 33 | /** 34 | * @return int 35 | */ 36 | public function limit() 37 | { 38 | return $this->limit; 39 | } 40 | 41 | /** 42 | * @return int 43 | */ 44 | public function remaining() 45 | { 46 | return $this->remaining; 47 | } 48 | 49 | /** 50 | * @return Carbon 51 | */ 52 | public function reset() 53 | { 54 | return Carbon::createFromTimestamp($this->reset); 55 | } 56 | } 57 | -------------------------------------------------------------------------------- /src/Responses/MessageResponse.php: -------------------------------------------------------------------------------- 1 | api = new ApiService(); 25 | 26 | $this->handleReceipt($response); 27 | } 28 | 29 | /** 30 | * @return null|PushoverReceipt 31 | */ 32 | public function receipt() 33 | { 34 | return $this->receipt; 35 | } 36 | 37 | /** 38 | * @param $response 39 | */ 40 | private function handleReceipt($response): void 41 | { 42 | if (property_exists($response, 'receipt')) { 43 | $this->receipt = new PushoverReceipt($response->receipt); 44 | } 45 | } 46 | } 47 | -------------------------------------------------------------------------------- /src/Responses/PushoverResponse.php: -------------------------------------------------------------------------------- 1 | status = $response->status; 25 | $this->request = $response->request; 26 | } 27 | 28 | /** 29 | * @return bool 30 | */ 31 | public function success() 32 | { 33 | return boolval($this->status); 34 | } 35 | 36 | /** 37 | * @return string 38 | */ 39 | public function request() 40 | { 41 | return $this->request; 42 | } 43 | } 44 | -------------------------------------------------------------------------------- /src/Responses/ReceiptCancelRetriesResponse.php: -------------------------------------------------------------------------------- 1 | acknowledged = $response->acknowledged; 64 | $this->acknowledged_at = $response->acknowledged_at; 65 | $this->acknowledged_by = $response->acknowledged_by; 66 | $this->acknowledged_by_device = $response->acknowledged_by_device; 67 | $this->last_delivered_at = $response->last_delivered_at; 68 | $this->expired = $response->expired; 69 | $this->expires_at = $response->expires_at; 70 | $this->called_back = $response->called_back; 71 | $this->called_back_at = $response->called_back_at; 72 | } 73 | 74 | /** 75 | * @return bool 76 | */ 77 | public function acknowledged() 78 | { 79 | return boolval($this->acknowledged); 80 | } 81 | 82 | /** 83 | * @return Carbon 84 | */ 85 | public function acknowledgedAt() 86 | { 87 | return Carbon::createFromTimestamp($this->acknowledged_at); 88 | } 89 | 90 | /** 91 | * @return string 92 | */ 93 | public function acknowledgedBy() 94 | { 95 | return $this->acknowledged_by; 96 | } 97 | 98 | /** 99 | * @return string 100 | */ 101 | public function acknowledgedByDevice() 102 | { 103 | return $this->acknowledged_by_device; 104 | } 105 | 106 | /** 107 | * @return string 108 | */ 109 | public function lastDeliveredAt() 110 | { 111 | return Carbon::createFromTimestamp($this->last_delivered_at); 112 | } 113 | 114 | /** 115 | * @return bool 116 | */ 117 | public function expired() 118 | { 119 | return boolval($this->expired); 120 | } 121 | 122 | /** 123 | * @return Carbon 124 | */ 125 | public function expiresAt() 126 | { 127 | return Carbon::createFromTimestamp($this->expires_at); 128 | } 129 | 130 | /** 131 | * @return bool 132 | */ 133 | public function calledBack() 134 | { 135 | return boolval($this->called_back); 136 | } 137 | 138 | /** 139 | * @return Carbon 140 | */ 141 | public function calledBackAt() 142 | { 143 | return Carbon::createFromTimestamp($this->called_back_at); 144 | } 145 | } 146 | -------------------------------------------------------------------------------- /src/ServiceProvider.php: -------------------------------------------------------------------------------- 1 | mergeConfigFrom( 15 | __DIR__ . '/../config/pushover.php', 'pushover' 16 | ); 17 | } 18 | 19 | /** 20 | * Bootstrap the application events. 21 | * 22 | * @return void 23 | */ 24 | public function boot() 25 | { 26 | if ($this->app->runningInConsole()) { 27 | $this->commands([ 28 | // UserSumsUpdateCommand::class, 29 | ]); 30 | } 31 | 32 | $this->publishes([ 33 | __DIR__ . '/../config/pushover.php' => config_path('pushover.php'), 34 | ]); 35 | } 36 | } 37 | --------------------------------------------------------------------------------