Skip to content

Commit

Permalink
Merge pull request #87 from vzlatev/extend-group-methods
Browse files Browse the repository at this point in the history
Extend MailchimpLists with methods for working with groups and interests
  • Loading branch information
mortenson committed Nov 20, 2019
2 parents f914dc8 + 32e58af commit a8500d1
Show file tree
Hide file tree
Showing 3 changed files with 371 additions and 0 deletions.
171 changes: 171 additions & 0 deletions src/MailchimpLists.php
Expand Up @@ -68,6 +68,90 @@ public function getInterestCategories($list_id, $parameters = []) {
return $this->request('GET', '/lists/{list_id}/interest-categories', $tokens, $parameters);
}

/**
* Create new interest category associated with a list.
*
* @param string $list_id
* The ID of the list.
* @param string $title
* The title of interest category.
* @param string $type
* The type of interest category.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/#create-post_lists_list_id_interest_categories
*/
public function addInterestCategories($list_id, $title, $type, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
];

$parameters += [
'title' => $title,
'type' => $type,
];

return $this->request('POST', '/lists/{list_id}/interest-categories', $tokens, $parameters);
}

/**
* Update interest category associated with a list.
*
* @param string $list_id
* The ID of the list.
* @param string $interest_category_id
* The ID of the interest category.
* @param string $title
* The title of interest category.
* @param string $type
* The type of interest category.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/#create-post_lists_list_id_interest_categories
*/
public function updateInterestCategories($list_id, $interest_category_id, $title, $type, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
'interest_category_id' => $interest_category_id,
];

$parameters += [
'title' => $title,
'type' => $type,
];

return $this->request('PATCH', '/lists/{list_id}/interest-categories/{interest_category_id}', $tokens, $parameters);
}

/**
* Update interest category associated with a list.
*
* @param string $list_id
* The ID of the list.
* @param string $interest_category_id
* The ID of the interest category.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/#create-post_lists_list_id_interest_categories
*/
public function deleteInterestCategories($list_id, $interest_category_id, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
'interest_category_id' => $interest_category_id,
];

return $this->request('DELETE', '/lists/{list_id}/interest-categories/{interest_category_id}', $tokens, $parameters);
}

/**
* Gets information about all interests associated with an interest category.
*
Expand All @@ -91,6 +175,93 @@ public function getInterests($list_id, $interest_category_id, $parameters = [])
return $this->request('GET', '/lists/{list_id}/interest-categories/{interest_category_id}/interests', $tokens, $parameters);
}

/**
* Create new interest in category.
*
* @param string $list_id
* The ID of the list.
* @param string $interest_category_id
* The ID of interest category.
* @param string $name
* The name of interest.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://mailchimp.com/developer/reference/lists/interest-categories/interests/
*/
public function addInterests($list_id, $interest_category_id, $name, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
'interest_category_id' => $interest_category_id,
];

$parameters += [
'name' => $name,
];

return $this->request('POST', '/lists/{list_id}/interest-categories/{interest_category_id}/interests', $tokens, $parameters);
}

/**
* Edit interest in category.
*
* @param string $list_id
* The ID of the list.
* @param string $interest_category_id
* The ID of interest category.
* @param string $interest_id
* The ID of interest.
* @param string $name
* The name of interest.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/#create-post_lists_list_id_interest_categories
*/
public function updateInterests($list_id, $interest_category_id, $interest_id, $name, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
'interest_category_id' => $interest_category_id,
'interest_id' => $interest_id,
];

$parameters += [
'name' => $name,
];

return $this->request('PATCH', '/lists/{list_id}/interest-categories/{interest_category_id}/interests/{interest_id}', $tokens, $parameters);
}

/**
* Delete interest in category.
*
* @param string $list_id
* The ID of the list.
* @param string $interest_category_id
* The ID of interest category.
* @param string $interest_id
* The ID of interest.
* @param array $parameters
* Associative array of optional request parameters.
*
* @return object
*
* @see https://developer.mailchimp.com/documentation/mailchimp/reference/lists/interest-categories/#create-post_lists_list_id_interest_categories
*/
public function deleteInterests($list_id, $interest_category_id, $interest_id, $parameters = [], $batch = FALSE) {
$tokens = [
'list_id' => $list_id,
'interest_category_id' => $interest_category_id,
'interest_id' => $interest_id,
];

return $this->request('DELETE', '/lists/{list_id}/interest-categories/{interest_category_id}/interests/{interest_id}', $tokens, $parameters);
}

/**
* Gets merge fields associated with a Mailchimp list.
*
Expand Down
117 changes: 117 additions & 0 deletions tests/MailchimpListsTest.php
Expand Up @@ -48,6 +48,65 @@ public function testGetInterestCategories() {
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories', $mc->getClient()->uri);
}

/**
* Tests library functionality for adding new interest categories.
*/
public function testAddInterestCategories() {
$list_id = '57afe96172';
$title = 'Test Interest Category';
$type = 'checkbox';

$mc = new MailchimpLists();
$mc->addInterestCategories($list_id, $title, $type);

$this->assertEquals('POST', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories', $mc->getClient()->uri);

$this->assertNotEmpty($mc->getClient()->options['json']);

$request_body = $mc->getClient()->options['json'];

$this->assertEquals($title, $request_body->title);
$this->assertEquals($type, $request_body->type);
}

/**
* Tests library functionality for updating interest categories.
*/
public function testUpdateInterestCategories() {
$list_id = '57afe96172';
$title = 'Test Interest Category Edited';
$type = 'dropdown';
$interest_category_id = '08f0b1d7b2';

$mc = new MailchimpLists();
$mc->updateInterestCategories($list_id, $interest_category_id, $title, $type);

$this->assertEquals('PATCH', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id, $mc->getClient()->uri);

$this->assertNotEmpty($mc->getClient()->options['json']);

$request_body = $mc->getClient()->options['json'];

$this->assertEquals($title, $request_body->title);
$this->assertEquals($type, $request_body->type);
}

/**
* Tests library functionality for deleting interest categories.
*/
public function testDeleteInterestCategories() {
$list_id = '57afe96172';
$interest_category_id = '08f0b1d7b2';

$mc = new MailchimpLists();
$mc->deleteInterestCategories($list_id, $interest_category_id);

$this->assertEquals('DELETE', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id, $mc->getClient()->uri);
}

/**
* Tests library functionality for interests information.
*/
Expand All @@ -62,6 +121,64 @@ public function testGetInterests() {
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests', $mc->getClient()->uri);
}

/**
* Tests library functionality for adding interests.
*/
public function testAddInterests() {
$list_id = '57afe96172';
$interest_category_id = '08f0b1d7b2';
$name = 'Test Interest';

$mc = new MailchimpLists();
$mc->addInterests($list_id, $interest_category_id, $name);

$this->assertEquals('POST', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests', $mc->getClient()->uri);

$this->assertNotEmpty($mc->getClient()->options['json']);

$request_body = $mc->getClient()->options['json'];

$this->assertEquals($name, $request_body->name);
}

/**
* Tests library functionality for updating interests.
*/
public function testUpdateInterests() {
$list_id = '57afe96172';
$interest_category_id = '08f0b1d7b2';
$interest_id = '9143cf3bd1';
$name = 'Test Interest Edited';

$mc = new MailchimpLists();
$mc->updateInterests($list_id, $interest_category_id, $interest_id, $name);

$this->assertEquals('PATCH', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests/' . $interest_id, $mc->getClient()->uri);

$this->assertNotEmpty($mc->getClient()->options['json']);

$request_body = $mc->getClient()->options['json'];

$this->assertEquals($name, $request_body->name);
}

/**
* Tests library functionality for deleting interests.
*/
public function testDeleteInterests() {
$list_id = '57afe96172';
$interest_category_id = '08f0b1d7b2';
$interest_id = '9143cf3bd1';

$mc = new MailchimpLists();
$mc->deleteInterests($list_id, $interest_category_id, $interest_id);

$this->assertEquals('DELETE', $mc->getClient()->method);
$this->assertEquals($mc->getEndpoint() . '/lists/' . $list_id . '/interest-categories/' . $interest_category_id . '/interests/' . $interest_id, $mc->getClient()->uri);
}

/**
* Tests library functionality for merge fields information.
*/
Expand Down

0 comments on commit a8500d1

Please sign in to comment.