-
Notifications
You must be signed in to change notification settings - Fork 0
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
chapdel
committed
Nov 25, 2020
1 parent
88c1453
commit f816af8
Showing
3 changed files
with
55 additions
and
15 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 |
---|---|---|
|
@@ -11,12 +11,14 @@ | |
"Chapdel\\NotchRelay\\": "src" | ||
} | ||
}, | ||
"homepage": "https://github.com/chapdel/notchrelay-api", | ||
"homepage": "https://notchrelay.xyz/docs", | ||
"authors": [ | ||
{ | ||
"name": "Chapdel KAMGA", | ||
"email": "[email protected]", | ||
"homepage": "http://chapdel.xyz" | ||
} | ||
] | ||
], | ||
"prefer-stable": true, | ||
"minimum-stability": "dev" | ||
} |
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 |
---|---|---|
|
@@ -2,11 +2,11 @@ | |
|
||
Notch Relay API wrapper | ||
|
||
Requires PHP 5.3 and hightler. | ||
Requires PHP 5.3 and higher. | ||
|
||
## Installation | ||
|
||
Install mnotchrelay-api using Composer: | ||
Install notchrelay-api using Composer: | ||
|
||
``` | ||
composer require chapdel/notchrelay-api | ||
|
@@ -32,7 +32,7 @@ Subscribe someone to a list (with `subscribe` method): | |
```php | ||
$list_id = '1234346'; | ||
|
||
$result = $notchrelay->subscribe('[email protected]', $list_id); | ||
$result = $notchrelay->subscribe($list_id, '[email protected]'); | ||
|
||
print_r($result); | ||
``` | ||
|
@@ -42,7 +42,7 @@ Unsubscribe someone to a list (with `unsubscribe` method): | |
```php | ||
$list_id = '1234346'; | ||
|
||
$result = $notchrelay->unsubscribe('[email protected]', $list_id); | ||
$result = $notchrelay->unsubscribe($list_id,'[email protected]'); | ||
|
||
print_r($result); | ||
``` | ||
|
@@ -52,7 +52,21 @@ Subscribe or update someone to a list (with `subscribeOrUpdate` method): | |
```php | ||
$list_id = '1234346'; | ||
|
||
$result = $notchrelay->unsubscribe('[email protected]', $list_id); | ||
$result = $notchrelay->subscribeOrUpdate`($list_id, '[email protected]', [ | ||
'first_name' => 'KAMGA', | ||
'last_name' => 'Chapdel' | ||
]); | ||
|
||
print_r($result); | ||
``` | ||
|
||
|
||
All subscribers in list (with `subscribers` method): | ||
|
||
```php | ||
$list_id = '1234346'; | ||
|
||
$result = $notchrelay->subscribers($list_id); | ||
|
||
print_r($result); | ||
``` | ||
|
@@ -61,4 +75,4 @@ print_r($result); | |
|
||
This is a fairly simple wrapper, but it has been made much better by contributions from those using it. If you'd like to suggest an improvement, please raise an issue to discuss it before making your pull request. | ||
|
||
Pull requests for bugs are more than welcome - please explain the bug you're trying to fix in the message. | ||
Pull requests for bugs and features are more than welcome - please explain the bug you're trying to fix in the 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 |
---|---|---|
|
@@ -16,8 +16,7 @@ class NotchRelay | |
{ | ||
public $curl; | ||
public $api_key; | ||
public $base_url = 'http://notch-relay.test/api'; | ||
//public $base_url = 'http://notchrelay.xyz/api'; | ||
public $base_url = 'http://notchrelay.xyz/api'; | ||
|
||
/** | ||
* Create a new instance | ||
|
@@ -41,16 +40,17 @@ public function __construct($api_key = null) | |
/** | ||
* Susbcribe | ||
* | ||
* @param string $email Customer email | ||
* @param string $list_id Notch Relay List ID | ||
* | ||
* @param string $email Customer email | ||
* @param array $data others customer data | ||
* @return bool | ||
*/ | ||
public function subscribe($email, $list_id) | ||
public function subscribe($list_id, $email, $data = []) | ||
{ | ||
$this->curl->post("$this->base_url/contacts", array( | ||
'email' => $email, | ||
'uid' => $list_id, | ||
'data' => $data | ||
)); | ||
|
||
if ($this->curl->error) { | ||
|
@@ -69,11 +69,12 @@ public function subscribe($email, $list_id) | |
* | ||
* @return bool | ||
*/ | ||
public function subscribeOrUpdate($email, $list_id) | ||
public function subscribeOrUpdate($list_id, $email, $data = []) | ||
{ | ||
$this->curl->put("$this->base_url/contacts", array( | ||
'email' => $email, | ||
'uid' => $list_id, | ||
'data' => $data | ||
)); | ||
|
||
if ($this->curl->error) { | ||
|
@@ -91,7 +92,7 @@ public function subscribeOrUpdate($email, $list_id) | |
* | ||
* @return bool | ||
*/ | ||
public function unsubscribe($email, $list_id) | ||
public function unsubscribe($list_id, $email) | ||
{ | ||
$this->curl->delete("$this->base_url/contacts", array( | ||
'email' => $email, | ||
|
@@ -104,4 +105,27 @@ public function unsubscribe($email, $list_id) | |
|
||
return true; | ||
} | ||
|
||
/** | ||
* Subscribers | ||
* | ||
* @param string $list_id Notch Relay List ID | ||
* | ||
* @return bool | ||
*/ | ||
public function subscribers($list_id) | ||
{ | ||
$this->curl->get("$this->base_url/lists/$list_id"); | ||
|
||
if ($this->curl->error) { | ||
return false; | ||
} | ||
return $this->curl->response; | ||
} | ||
} | ||
|
||
require_once __DIR__. '/../vendor/autoload.php'; | ||
|
||
$notch = new NotchRelay('ApIHUrnaUgnQ98NC67QKKHbbGlOyvEsdlOPMEH10'); | ||
|
||
$notch->subscribe('Jeqne7TGL', '[email protected]'); |