This repository has been archived by the owner on Jul 17, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
0 parents
commit a9afd62
Showing
10 changed files
with
576 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
.idea | ||
composer.lock | ||
vendor | ||
bin | ||
coverage | ||
coverage.xml |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
language: php | ||
|
||
php: | ||
- 5.6 | ||
- 7.0 | ||
- 7.1 | ||
- hhvm | ||
- nightly | ||
|
||
before_script: | ||
- composer install |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
The MIT License (MIT) | ||
|
||
Copyright (c) 2016 Superbalist.com a division of Takealot Online (Pty) Ltd | ||
|
||
Permission is hereby granted, free of charge, to any person obtaining a copy | ||
of this software and associated documentation files (the "Software"), to deal | ||
in the Software without restriction, including without limitation the rights | ||
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell | ||
copies of the Software, and to permit persons to whom the Software is | ||
furnished to do so, subject to the following conditions: | ||
|
||
The above copyright notice and this permission notice shall be included in all | ||
copies or substantial portions of the Software. | ||
|
||
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR | ||
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, | ||
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE | ||
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER | ||
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, | ||
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE | ||
SOFTWARE. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,50 @@ | ||
# php-localytics-push | ||
|
||
A PHP client for sending push notifications via the [Localytics Push Notification](https://www.localytics.com/features/push-messaging/) service | ||
|
||
[![Author](http://img.shields.io/badge/author-@superbalist-blue.svg?style=flat-square)](https://twitter.com/superbalist) | ||
[![Build Status](https://img.shields.io/travis/Superbalist/php-localytics-push/master.svg?style=flat-square)](https://travis-ci.org/Superbalist/php-localytics-push) | ||
[![Software License](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat-square)](LICENSE) | ||
[![Packagist Version](https://img.shields.io/packagist/v/superbalist/php-localytics-push.svg?style=flat-square)](https://packagist.org/packages/superbalist/php-localytics-push) | ||
[![Total Downloads](https://img.shields.io/packagist/dt/superbalist/php-localytics-push.svg?style=flat-square)](https://packagist.org/packages/superbalist/php-localytics-push) | ||
|
||
|
||
## Installation | ||
|
||
```bash | ||
composer require superbalist/php-localytics-push | ||
``` | ||
|
||
## Usage | ||
|
||
```php | ||
$client = new GuzzleHttp\Client(); | ||
$appID = 'your-app-id'; | ||
$apiKey = 'your-api-key'; | ||
$apiSecret = 'your-api-secret'; | ||
|
||
$localytics = new \Superbalist\LocalyticsPush\LocalyticsPush($client, $appID, $apiKey, $apiSecret); | ||
$message = [ | ||
'target' => [ | ||
'profile' => [ | ||
'criteria' => [ | ||
[ | ||
'key' => '$email', | ||
'scope' => 'Organization', | ||
'type' => 'string', | ||
'op' => 'in', | ||
'values' => [ | ||
'matthew@superbalist.com', | ||
] | ||
] | ||
], | ||
'op' => 'and', | ||
], | ||
], | ||
'alert' => [ | ||
'title' => 'Message Title', | ||
'body' => 'This is my message content!', | ||
] | ||
]; | ||
$response = $localytics->pushMessage('profile', $message); | ||
``` |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,5 @@ | ||
# Changelog | ||
|
||
## 1.0.0 - 2016-10-19 | ||
|
||
* Initial release |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
{ | ||
"name": "superbalist/php-localytics-push", | ||
"description": "A PHP client for sending push notifications via the Localytics Push Notification service", | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Superbalist.com a division of Takealot Online (Pty) Ltd", | ||
"email": "info@superbalist.com" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.6.0", | ||
"guzzlehttp/guzzle": "^6.2" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Superbalist\\LocalyticsPush\\": "src/", | ||
"Tests\\": "tests/" | ||
} | ||
}, | ||
"extra": { | ||
"branch-alias": { | ||
"dev-master": "1.0-dev" | ||
} | ||
}, | ||
"require-dev": { | ||
"phpunit/phpunit": "^5.6", | ||
"mockery/mockery": "^0.9.5" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
<?php | ||
|
||
include __DIR__ . '/vendor/autoload.php'; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
<?xml version="1.0" encoding="UTF-8"?> | ||
<phpunit backupGlobals="false" | ||
backupStaticAttributes="false" | ||
bootstrap="./phpunit.php" | ||
colors="true" | ||
convertErrorsToExceptions="true" | ||
convertNoticesToExceptions="true" | ||
convertWarningsToExceptions="true" | ||
processIsolation="false" | ||
stopOnFailure="false" | ||
syntaxCheck="true" | ||
verbose="true" | ||
> | ||
<testsuites> | ||
<testsuite name="php-localytics-push/tests"> | ||
<directory suffix=".php">./tests/</directory> | ||
</testsuite> | ||
</testsuites> | ||
<filter> | ||
<whitelist> | ||
<directory suffix=".php">./src/</directory> | ||
</whitelist> | ||
</filter> | ||
<logging> | ||
<log type="coverage-text" target="php://stdout" showUncoveredFiles="true"/> | ||
<log type="coverage-html" target="coverage" showUncoveredFiles="true"/> | ||
<log type="coverage-clover" target="coverage.xml" showUncoveredFiles="true"/> | ||
</logging> | ||
</phpunit> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,219 @@ | ||
<?php | ||
|
||
namespace Superbalist\LocalyticsPush; | ||
|
||
use GuzzleHttp\Client; | ||
use Psr\Http\Message\RequestInterface; | ||
|
||
class LocalyticsPush | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $uri = 'https://messaging.localytics.com/v2/push/'; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $appID; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $apiKey; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $apiSecret; | ||
|
||
/** | ||
* @param Client $client | ||
* @param string $appID | ||
* @param string $apiKey | ||
* @param string $apiSecret | ||
*/ | ||
public function __construct(Client $client, $appID = null, $apiKey = null, $apiSecret = null) | ||
{ | ||
$this->client = $client; | ||
$this->appID = $appID; | ||
$this->apiKey = $apiKey; | ||
$this->apiSecret = $apiSecret; | ||
} | ||
|
||
/** | ||
* Set the uri. | ||
* | ||
* @param string $uri | ||
*/ | ||
public function setUri($uri) | ||
{ | ||
$this->uri = $uri; | ||
} | ||
/** | ||
* Return the uri. | ||
* | ||
* @return string | ||
*/ | ||
public function getUri() | ||
{ | ||
return $this->uri; | ||
} | ||
|
||
/** | ||
* Set the App ID. | ||
* | ||
* The App ID can be found on the settings screen of your dashboard. | ||
* https://dashboard.localytics.com/settings/apps | ||
* | ||
* @param string $appID | ||
*/ | ||
public function setAppID($appID) | ||
{ | ||
$this->appID = $appID; | ||
} | ||
|
||
/** | ||
* Return the App ID. | ||
* | ||
* @return string | ||
*/ | ||
public function getAppID() | ||
{ | ||
return $this->appID; | ||
} | ||
|
||
/** | ||
* Set the API Key. | ||
* | ||
* The API Key can be found on the settings screen of your dashboard. | ||
* https://dashboard.localytics.com/settings/apps | ||
* | ||
* @param string $apiKey | ||
*/ | ||
public function setAPIKey($apiKey) | ||
{ | ||
$this->apiKey = $apiKey; | ||
} | ||
|
||
/** | ||
* Return the API Key. | ||
* | ||
* @return string | ||
*/ | ||
public function getAPIKey() | ||
{ | ||
return $this->apiKey; | ||
} | ||
|
||
/** | ||
* Set the API Secret. | ||
* | ||
* The API Secret can be found on the settings screen of your dashboard. | ||
* https://dashboard.localytics.com/settings/apps | ||
* | ||
* @param string $apiSecret | ||
*/ | ||
public function setAPISecret($apiSecret) | ||
{ | ||
$this->apiSecret = $apiSecret; | ||
} | ||
|
||
/** | ||
* Return the API Secret. | ||
* | ||
* @return string | ||
*/ | ||
public function getAPISecret() | ||
{ | ||
return $this->apiSecret; | ||
} | ||
|
||
/** | ||
* Send an HTTP request. | ||
* | ||
* @param RequestInterface $request | ||
* @return array | ||
* @throws \Exception | ||
*/ | ||
protected function sendRequest(RequestInterface $request) | ||
{ | ||
$response = $this->client->send($request); | ||
return json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* Send one or many push notification messages. | ||
* | ||
* @param string $targetType (broadcast|customer_id|audience_id|profile) | ||
* @param array $messages | ||
* @param string $requestId | ||
* @param string $campaignKey | ||
* @return array | ||
*/ | ||
public function pushMessages($targetType, array $messages, $requestId = null, $campaignKey = null) | ||
{ | ||
$data = [ | ||
'request_id' => $requestId, | ||
'campaign_key' => $campaignKey, | ||
'target_type' => $targetType, | ||
'messages' => $messages, | ||
]; | ||
|
||
$options = [ | ||
'auth' => [ | ||
$this->apiKey, | ||
$this->apiSecret, | ||
], | ||
'json' => $data, | ||
]; | ||
$uri = rtrim($this->uri, '/') . '/' . $this->appID; | ||
$response = $this->client->post($uri, $options); | ||
return json_decode($response->getBody(), true); | ||
} | ||
|
||
/** | ||
* Send a single push notification message. | ||
* | ||
* **Example** | ||
* | ||
* ```php | ||
* $message = [ | ||
* 'target' => [ | ||
* 'profile' => [ | ||
* 'criteria' => [ | ||
* [ | ||
* 'key' => '$email', | ||
* 'scope' => 'Organization', | ||
* 'type' => 'string', | ||
* 'op' => 'in', | ||
* 'values' => [ | ||
* 'matthew@superbalist.com', | ||
* ] | ||
* ] | ||
* ] | ||
* ] | ||
* ], | ||
* 'alert' => [ | ||
* 'title' => 'Message Title', | ||
* 'body' => 'This is my message content!', | ||
* ], | ||
* ]; | ||
* $response = $localytics->pushMessage('profile', $message); | ||
* | ||
* @param string $targetType (broadcast|customer_id|audience_id|profile) | ||
* @param array $message | ||
* @param string $requestId | ||
* @param string $campaignKey | ||
* @return array | ||
*/ | ||
public function pushMessage($targetType, array $message, $requestId = null, $campaignKey = null) | ||
{ | ||
return $this->pushMessages($targetType, [$message], $requestId, $campaignKey); | ||
} | ||
} |
Oops, something went wrong.