-
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
Showing
4 changed files
with
111 additions
and
83 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 |
---|---|---|
|
@@ -15,20 +15,16 @@ Make sure the file is loaded, either by `require 'vendor/autoload.php'` if you a | |
|
||
```php | ||
<?php | ||
require 'vendor/autoload.php'; | ||
|
||
$clientId = 'ThisIsMyId'; | ||
$clientSecret = '123456789asdf'; | ||
$client = new Minutemailer\Minutemailer($clientId, $clientSecret); | ||
require 'vendor/autoload.php'; | ||
|
||
// Data required | ||
$contactListToken = 'asdf123'; | ||
$postData = [ | ||
'name' => 'Firstname Lastname', | ||
'email' => '[email protected]' | ||
]; | ||
$personalAccessToken = 'myAccessToken'; | ||
|
||
$response = $client->subscribe($contactListToken)->post($postData); | ||
$client = new Minutemailer\Minutemailer($personalAccessToken); | ||
$response = $client->contact_lists('123abc')->subscribe([ | ||
'name' => 'Firstname Lastname', | ||
'email' => '[email protected]' | ||
]); | ||
``` | ||
|
||
Please note that both name and email are required. `$response` will be filled with the contact data if the request is valid. Otherwise, an error will be returned. | ||
Email is required and name is optional. `$response` will be filled with the contact data if the request is valid. Otherwise, an error will be returned. |
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,16 @@ | ||
<?php | ||
|
||
namespace Minutemailer; | ||
|
||
class ContactLists extends RestAPI | ||
{ | ||
public $endpoint = 'contactlists'; | ||
|
||
public function subscribe($data) | ||
{ | ||
$this->segment = 'subscribe'; | ||
$response = $this->post($data); | ||
|
||
return $response; | ||
} | ||
} |
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
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,62 @@ | ||
<?php | ||
|
||
namespace Minutemailer; | ||
|
||
class RestAPI | ||
{ | ||
public $endpoint; | ||
public $client; | ||
public $id; | ||
public $segment; | ||
|
||
public function __construct($client, $id = null) | ||
{ | ||
$this->client = $client; | ||
$this->id = $id; | ||
} | ||
|
||
protected function getEndpoint() | ||
{ | ||
$endpoint = $this->endpoint; | ||
|
||
if ($this->id) { | ||
$endpoint .= '/' . $this->id; | ||
} | ||
|
||
if ($this->segment) { | ||
$endpoint .= '/' . $this->segment; | ||
} | ||
|
||
return $endpoint; | ||
} | ||
|
||
/** | ||
* Get resource | ||
* @param array $query | ||
* @return GuzzleHttp\Psr7\Response | ||
*/ | ||
public function get($query = []) | ||
{ | ||
$endpoint = $this->getEndpoint(); | ||
|
||
$response = $this->client->get($endpoint, ['query' => $query]); | ||
$response = json_decode($response->getBody()); | ||
|
||
return $response; | ||
} | ||
|
||
/** | ||
* Post data | ||
* @param array $data | ||
* @return GuzzleHttp\Psr7\Response | ||
*/ | ||
public function post($data = []) | ||
{ | ||
$endpoint = $this->getEndpoint(); | ||
|
||
$response = $this->client->post($endpoint, ['form_params' => $data]); | ||
$response = json_decode($response->getBody()); | ||
|
||
return $response; | ||
} | ||
} |