Skip to content

Commit

Permalink
Merge pull request #3 from Jhut89/v2.0.01
Browse files Browse the repository at this point in the history
Version 2.0.01
  • Loading branch information
John Hutcheson authored Jan 20, 2017
2 parents 12fe3d2 + 302c573 commit d2d4f8a
Show file tree
Hide file tree
Showing 62 changed files with 492 additions and 1,893 deletions.
51 changes: 46 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -79,22 +79,24 @@ $mailchimp->lists('1a2b3c4d')->members('8bdbf060209f35b52087992a3cbdf4d7')->GET(
While being able to retrieve data from your account is great we also need to be able to post new data. This can be done by calling the `POST()` method at the end of a chain. As an example subscribing an address to a list would look like this:

```php
$mailchimp->lists('1a2b3c4d')->members()->POST('subscribed', '[email protected]');
$post_params = ['email_address'=>'[email protected]', 'status'=>'subscribed']

$mailchimp->lists('1a2b3c4d')->members()->POST($post_params);
```

In this case I would not provide `members()` with an identifier as I want to post to its collection. Also notice that the post data is a series of arguments. These are the required parameters as defined by [MailChimp's documentation](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members) in the order that they appear there (top to bottom). Assuming there are more parameters listed in MailChimp's documentation than just those required a final argument can be passed as an `array()` to add these optional parameters to the request. As an example if I wanted to add 'email_type' and merge-fields containing my subscriber's name to the above request I can:
In this case I would not provide `members()` with an identifier as I want to post to its collection. Also notice that the post data is an array of key-value pairs representing what parameters I want to pass to the MailChimp API. Be sure that you provide all required fields for the endpoint you are posting to check [MailChimp's documentation](http://developer.mailchimp.com/documentation/mailchimp/reference/lists/members/#create-post_lists_list_id_members) for what parameters are required. Non-required parameters can just be added to the post data, and MailChimp will ignore any unusable parameters. To illustrate here is an example of adding a subscriber to a list with some non-required parameters:

```php
$merge_values = array( "FNAME" => "John", "LNAME" => "Doe");

$optional_parameters = array( "email_type" => "html", "merge_fields" => $merge_values )
$post_params = array("email_address" => "[email protected]", "status" => "subscribed", "email_type" => "html", "merge_fields" => $merge_values )

$mailchimp->lists('1a2b3c4d')->members()->POST('subscribed', '[email protected]', $optional_parameters);
$mailchimp->lists('1a2b3c4d')->members()->POST($post_params);
```

###PATCH/PUT

This library handles PUT and PATCH request similar to that of POST requests. Meaning that if there are required fields listed in MailChimp's documentation they will be listed arguments for that method. Those methods that do not have any required parameters take a single argument being and array of parameters you wish to patch. As an example if I was patching the subscriber that we used above, to have a new first name, that would look like this.
This library handles PUT and PATCH request similar to that of POST requests. Meaning that `PUT()` & `PATCH()` both accept an array of key-value pairs that reqpresent the data you wish altered in MailChimp. As an example if I was patching the subscriber that we subscribed above, to have a new first name, that would look like this.

```php
$mailchimp->lists('1a2b3c4d')->members('a1167f5be2df7113beb69c95ebcdb2fd')->PATCH( [ "merge_fields" => ["FNAME" => "Jane"] ] );
Expand All @@ -119,6 +121,8 @@ $mailchimp->lists('1a2b3c4d')->members('a1167f5be2df7113beb69c95ebcdb2fd')->DELE
removedSubscribers()
emails()
queue()
PAUSE_ALL()
START_ALL()

batches()

Expand Down Expand Up @@ -196,6 +200,43 @@ $mailchimp->lists('1a2b3c4d')->members('a1167f5be2df7113beb69c95ebcdb2fd')->DELE

\*Please see [MailChimp's API Documentation](http://developer.mailchimp.com/documentation/mailchimp/reference/overview/) for what verbs are appropriate where.

## Settings

This library offers several setting that can be altered by changing the value of the class constants at the begining of the `Mailchimp` class in the `mailchimpRoot.php` file. Be sure to check them out to see if they can be altered to fit your project a little better.

### Debugger
This library has a very small debug function that will allow you to output some request information and what was returned. This can be turned on by setting:

```php
const DEBUGGER = false;
```
The debugger can also log to a file if you provide a file for it to write to using `const DEBUGGER_LOG_FILE` like this:

```php
const DEBUGGER_LOG_FILE = 'path/to/some/file.php';
```

By default this option is set to `false`.

### SSL Verify
`CURLOPT_SSL_VERIFYPEER` can be disabled by setting:

```php
const VERIFY_SSL = false;
````

By default this option is set to `true`.

### Request Headers
To include the returned headers in the output from this library set:

```php
const HEADERS = true;
```

By default this option is set to `false`.


\*\*Please watch for updates, and feel free to Fork or Pull Request. Check out the Wiki for a little more info on contributing.


Expand Down
9 changes: 3 additions & 6 deletions src/account/accountRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,12 +2,9 @@

class Mailchimp_Account extends Mailchimp
{

public function GET()
function __construct($apikey)
{
$url = $this->url . "/";
$response = $this->curlGet($url);
return $response;
parent::__construct($apikey);
$this->url .= '/';
}

}
37 changes: 6 additions & 31 deletions src/authorizedApps/authorizedAppsRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,12 @@
class Authorized_Apps extends Mailchimp
{

//REQUIRED FIELDS DEFINITIONS
public $req_post_prarams = [
'client_id',
'client_secret'
];


function __construct($apikey, $class_input)
{
Expand All @@ -14,36 +20,5 @@ function __construct($apikey, $class_input)
}

}

public function GET( $query_params = null )
{
$query_string = '';

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}

$url = $this->url . $query_string;
$response = $this->curlGet($url);

return $response;


}

public function POST($client_id, $client_sec)
{
$params = array(
'client_id' => $client_id,
'client_secret' => $client_sec
);

$payload = json_encode($params);
$url = $this->url;

$response = $this->curlPost($url, $payload);

return $response;
}

}
30 changes: 4 additions & 26 deletions src/automations/autoamtionsRemovedSubscribers.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class Automations_Removed_Subscribers extends Automations
{
//REQUIRED FIELDS DEFINITIONS
public $req_post_prarams = [
'email_address'
];

function __construct($apikey, $class_input = null)
{
Expand All @@ -10,31 +14,5 @@ function __construct($apikey, $class_input = null)

}

public function GET( $query_params = null )
{

$query_string = '';

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}

$url = $this->url . $query_string;
$response = $this->curlGet($url);

return $response;
}

public function POST($emailaddress)
{
$params = array('email_address' => $emailaddress);

$payload = json_encode($params);
$url = $this->url;

$response = $this->curlPost($url, $payload);

return $response;
}

}
24 changes: 17 additions & 7 deletions src/automations/automationsRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -19,16 +19,26 @@ function __construct($apikey, $class_input = null)
$this->subclass_resource = $class_input;
}

public function GET( $query_params = null )
public function PAUSE_ALL()
{
$query_string = '';
$params = array();

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}
$payload = json_encode($params);
$url = $this->url . '/actions/pause-all-emails/';

$response = $this->curlPost($url, $payload);

return $response;
}

public function START_ALL()
{
$params = array();

$payload = json_encode($params);
$url = $this->url . '/actions/start-all-emails/';

$url = $this->url . $query_string;
$response = $this->curlGet($url);
$response = $this->curlPost($url, $payload);

return $response;
}
Expand Down
34 changes: 4 additions & 30 deletions src/automations/emails/automationsEmailsQueue.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,44 +2,18 @@

class Automations_Email_Queue extends Automations_Emails
{
//REQUIRED FIELDS DEFINITIONS
public $req_post_prarams = [
'email_address'
];

function __construct($apikey, $parent_reference, $grandchild_resource, $member)
{

parent::__construct($apikey, $parent_reference, $grandchild_resource);
if (isset($member)) {
$this->url .= '/queue/' . md5(strtolower($member));
} else {
$this->url .= '/queue/';
}
}

public function GET( $query_params = null )
{
$query_string = '';

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}

$url = $this->url . $query_string;
$response = $this->curlGet($url);

return $response;
}

public function POST($emailaddress)
{
$params = array(
'email_address' => $emailaddress
);

$payload = json_encode($params);
$url = $this->url;

$response = $this->curlPost($url, $payload);

return $response;
}

}
16 changes: 0 additions & 16 deletions src/automations/emails/automationsEmailsRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,6 @@ function __construct($apikey, $parent_reference, $class_input)

}

public function GET( $query_params = null )
{

$query_string = '';

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}

$url = $this->url . $query_string;
$response = $this->curlGet($url);

return $response;

}

// PAUSE AND START FUNCTIONS
// exemptions needed here for attempting to pause emails without providing email_id

Expand Down
31 changes: 4 additions & 27 deletions src/batchOperations/batchOperationsRoot.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,10 @@

class Batch_Operations extends Mailchimp
{
//REQUIRED FIELDS DEFINITIONS
public $req_post_prarams = [
'operations'
];

function __construct($apikey, $class_input)
{
Expand All @@ -13,31 +17,4 @@ function __construct($apikey, $class_input)
}
}

public function POST( $operations = array() )
{

$params = array('operations' => $operations);

$payload = json_encode($params);
$url = $this->url;

$response = $this->curlPost($url, $payload);

return $response;
}

public function GET( $query_params = null )
{
$query_string = '';

if (is_array($query_params)) {
$query_string = $this->constructQueryParams($query_params);
}

$url = $this->url . $query_string;
$response = $this->curlGet($url);

return $response;
}

}
Loading

0 comments on commit d2d4f8a

Please sign in to comment.