Skip to content

Commit

Permalink
Add subscribers method
Browse files Browse the repository at this point in the history
  • Loading branch information
chapdel committed Nov 25, 2020
1 parent 88c1453 commit f816af8
Show file tree
Hide file tree
Showing 3 changed files with 55 additions and 15 deletions.
6 changes: 4 additions & 2 deletions composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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"
}
26 changes: 20 additions & 6 deletions readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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);
```
Expand All @@ -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);
```
Expand All @@ -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);
```
Expand All @@ -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.
38 changes: 31 additions & 7 deletions src/NotchRelay.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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) {
Expand All @@ -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) {
Expand All @@ -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,
Expand All @@ -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]');

0 comments on commit f816af8

Please sign in to comment.