Skip to content

Commit d2d4f8a

Browse files
author
John Hutcheson
authored
Merge pull request #3 from Jhut89/v2.0.01
Version 2.0.01
2 parents 12fe3d2 + 302c573 commit d2d4f8a

File tree

62 files changed

+492
-1893
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+492
-1893
lines changed

README.md

Lines changed: 46 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -79,22 +79,24 @@ $mailchimp->lists('1a2b3c4d')->members('8bdbf060209f35b52087992a3cbdf4d7')->GET(
7979
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:
8080

8181
```php
82-
$mailchimp->lists('1a2b3c4d')->members()->POST('subscribed', 'example@domain.com');
82+
$post_params = ['email_address'=>'example@domain.com', 'status'=>'subscribed']
83+
84+
$mailchimp->lists('1a2b3c4d')->members()->POST($post_params);
8385
```
8486

85-
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:
87+
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:
8688

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

90-
$optional_parameters = array( "email_type" => "html", "merge_fields" => $merge_values )
92+
$post_params = array("email_address" => "example@domain.com", "status" => "subscribed", "email_type" => "html", "merge_fields" => $merge_values )
9193

92-
$mailchimp->lists('1a2b3c4d')->members()->POST('subscribed', 'example@domain.com', $optional_parameters);
94+
$mailchimp->lists('1a2b3c4d')->members()->POST($post_params);
9395
```
9496

9597
###PATCH/PUT
9698

97-
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.
99+
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.
98100

99101
```php
100102
$mailchimp->lists('1a2b3c4d')->members('a1167f5be2df7113beb69c95ebcdb2fd')->PATCH( [ "merge_fields" => ["FNAME" => "Jane"] ] );
@@ -119,6 +121,8 @@ $mailchimp->lists('1a2b3c4d')->members('a1167f5be2df7113beb69c95ebcdb2fd')->DELE
119121
removedSubscribers()
120122
emails()
121123
queue()
124+
PAUSE_ALL()
125+
START_ALL()
122126

123127
batches()
124128

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

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

203+
## Settings
204+
205+
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.
206+
207+
### Debugger
208+
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:
209+
210+
```php
211+
const DEBUGGER = false;
212+
```
213+
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:
214+
215+
```php
216+
const DEBUGGER_LOG_FILE = 'path/to/some/file.php';
217+
```
218+
219+
By default this option is set to `false`.
220+
221+
### SSL Verify
222+
`CURLOPT_SSL_VERIFYPEER` can be disabled by setting:
223+
224+
```php
225+
const VERIFY_SSL = false;
226+
````
227+
228+
By default this option is set to `true`.
229+
230+
### Request Headers
231+
To include the returned headers in the output from this library set:
232+
233+
```php
234+
const HEADERS = true;
235+
```
236+
237+
By default this option is set to `false`.
238+
239+
199240
\*\*Please watch for updates, and feel free to Fork or Pull Request. Check out the Wiki for a little more info on contributing.
200241

201242

src/account/accountRoot.php

Lines changed: 3 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,9 @@
22

33
class Mailchimp_Account extends Mailchimp
44
{
5-
6-
public function GET()
5+
function __construct($apikey)
76
{
8-
$url = $this->url . "/";
9-
$response = $this->curlGet($url);
10-
return $response;
7+
parent::__construct($apikey);
8+
$this->url .= '/';
119
}
12-
1310
}

src/authorizedApps/authorizedAppsRoot.php

Lines changed: 6 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,12 @@
33
class Authorized_Apps extends Mailchimp
44
{
55

6+
//REQUIRED FIELDS DEFINITIONS
7+
public $req_post_prarams = [
8+
'client_id',
9+
'client_secret'
10+
];
11+
612

713
function __construct($apikey, $class_input)
814
{
@@ -14,36 +20,5 @@ function __construct($apikey, $class_input)
1420
}
1521

1622
}
17-
18-
public function GET( $query_params = null )
19-
{
20-
$query_string = '';
21-
22-
if (is_array($query_params)) {
23-
$query_string = $this->constructQueryParams($query_params);
24-
}
25-
26-
$url = $this->url . $query_string;
27-
$response = $this->curlGet($url);
28-
29-
return $response;
30-
31-
32-
}
33-
34-
public function POST($client_id, $client_sec)
35-
{
36-
$params = array(
37-
'client_id' => $client_id,
38-
'client_secret' => $client_sec
39-
);
40-
41-
$payload = json_encode($params);
42-
$url = $this->url;
43-
44-
$response = $this->curlPost($url, $payload);
45-
46-
return $response;
47-
}
4823

4924
}

src/automations/autoamtionsRemovedSubscribers.php

Lines changed: 4 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
class Automations_Removed_Subscribers extends Automations
44
{
5+
//REQUIRED FIELDS DEFINITIONS
6+
public $req_post_prarams = [
7+
'email_address'
8+
];
59

610
function __construct($apikey, $class_input = null)
711
{
@@ -10,31 +14,5 @@ function __construct($apikey, $class_input = null)
1014

1115
}
1216

13-
public function GET( $query_params = null )
14-
{
15-
16-
$query_string = '';
17-
18-
if (is_array($query_params)) {
19-
$query_string = $this->constructQueryParams($query_params);
20-
}
21-
22-
$url = $this->url . $query_string;
23-
$response = $this->curlGet($url);
24-
25-
return $response;
26-
}
27-
28-
public function POST($emailaddress)
29-
{
30-
$params = array('email_address' => $emailaddress);
31-
32-
$payload = json_encode($params);
33-
$url = $this->url;
34-
35-
$response = $this->curlPost($url, $payload);
36-
37-
return $response;
38-
}
3917

4018
}

src/automations/automationsRoot.php

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -19,16 +19,26 @@ function __construct($apikey, $class_input = null)
1919
$this->subclass_resource = $class_input;
2020
}
2121

22-
public function GET( $query_params = null )
22+
public function PAUSE_ALL()
2323
{
24-
$query_string = '';
24+
$params = array();
2525

26-
if (is_array($query_params)) {
27-
$query_string = $this->constructQueryParams($query_params);
28-
}
26+
$payload = json_encode($params);
27+
$url = $this->url . '/actions/pause-all-emails/';
28+
29+
$response = $this->curlPost($url, $payload);
30+
31+
return $response;
32+
}
33+
34+
public function START_ALL()
35+
{
36+
$params = array();
37+
38+
$payload = json_encode($params);
39+
$url = $this->url . '/actions/start-all-emails/';
2940

30-
$url = $this->url . $query_string;
31-
$response = $this->curlGet($url);
41+
$response = $this->curlPost($url, $payload);
3242

3343
return $response;
3444
}

src/automations/emails/automationsEmailsQueue.php

Lines changed: 4 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -2,44 +2,18 @@
22

33
class Automations_Email_Queue extends Automations_Emails
44
{
5+
//REQUIRED FIELDS DEFINITIONS
6+
public $req_post_prarams = [
7+
'email_address'
8+
];
59

610
function __construct($apikey, $parent_reference, $grandchild_resource, $member)
711
{
8-
912
parent::__construct($apikey, $parent_reference, $grandchild_resource);
1013
if (isset($member)) {
1114
$this->url .= '/queue/' . md5(strtolower($member));
1215
} else {
1316
$this->url .= '/queue/';
1417
}
1518
}
16-
17-
public function GET( $query_params = null )
18-
{
19-
$query_string = '';
20-
21-
if (is_array($query_params)) {
22-
$query_string = $this->constructQueryParams($query_params);
23-
}
24-
25-
$url = $this->url . $query_string;
26-
$response = $this->curlGet($url);
27-
28-
return $response;
29-
}
30-
31-
public function POST($emailaddress)
32-
{
33-
$params = array(
34-
'email_address' => $emailaddress
35-
);
36-
37-
$payload = json_encode($params);
38-
$url = $this->url;
39-
40-
$response = $this->curlPost($url, $payload);
41-
42-
return $response;
43-
}
44-
4519
}

src/automations/emails/automationsEmailsRoot.php

Lines changed: 0 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -21,22 +21,6 @@ function __construct($apikey, $parent_reference, $class_input)
2121

2222
}
2323

24-
public function GET( $query_params = null )
25-
{
26-
27-
$query_string = '';
28-
29-
if (is_array($query_params)) {
30-
$query_string = $this->constructQueryParams($query_params);
31-
}
32-
33-
$url = $this->url . $query_string;
34-
$response = $this->curlGet($url);
35-
36-
return $response;
37-
38-
}
39-
4024
// PAUSE AND START FUNCTIONS
4125
// exemptions needed here for attempting to pause emails without providing email_id
4226

src/batchOperations/batchOperationsRoot.php

Lines changed: 4 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,10 @@
22

33
class Batch_Operations extends Mailchimp
44
{
5+
//REQUIRED FIELDS DEFINITIONS
6+
public $req_post_prarams = [
7+
'operations'
8+
];
59

610
function __construct($apikey, $class_input)
711
{
@@ -13,31 +17,4 @@ function __construct($apikey, $class_input)
1317
}
1418
}
1519

16-
public function POST( $operations = array() )
17-
{
18-
19-
$params = array('operations' => $operations);
20-
21-
$payload = json_encode($params);
22-
$url = $this->url;
23-
24-
$response = $this->curlPost($url, $payload);
25-
26-
return $response;
27-
}
28-
29-
public function GET( $query_params = null )
30-
{
31-
$query_string = '';
32-
33-
if (is_array($query_params)) {
34-
$query_string = $this->constructQueryParams($query_params);
35-
}
36-
37-
$url = $this->url . $query_string;
38-
$response = $this->curlGet($url);
39-
40-
return $response;
41-
}
42-
4320
}

0 commit comments

Comments
 (0)