Skip to content

Commit 3b09d49

Browse files
authored
Merge pull request #60 from Jhut89/3.0.3
3.0.3
2 parents ce575ad + 9d41ce0 commit 3b09d49

File tree

8 files changed

+142
-13
lines changed

8 files changed

+142
-13
lines changed

README.md

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -381,10 +381,12 @@ print $contact_email; // outputs something like "example@domain.com"
381381
|----templateFolders()
382382
|
383383
|----templates()
384-
|
385-
|----defaultContent()
386-
387-
384+
| |
385+
| |----defaultContent()
386+
|
387+
|----verifiedDomains()
388+
|
389+
|----verify()
388390
389391
390392

src/Mailchimp.php

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -239,6 +239,16 @@ public function templates($template_id = null)
239239
return new Resources\Templates($this->request, $this->settings, $template_id);
240240
}
241241

242+
/**
243+
* @param null $domain_name
244+
*
245+
* @return Resources\VerifiedDomains
246+
*/
247+
public function verifiedDomains($domain_name = null)
248+
{
249+
return new Resources\VerifiedDomains($this->request, $this->settings, $domain_name);
250+
}
251+
242252
/**
243253
* @param $client_id
244254
* @param $redirect_uri

src/Resources/VerifiedDomains.php

Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
<?php
2+
3+
namespace MailchimpAPI\Resources;
4+
5+
6+
use MailchimpAPI\Requests\MailchimpRequest;
7+
use MailchimpAPI\Settings\MailchimpSettings;
8+
9+
/**
10+
* Class VerifiedDomains
11+
* Represents the Verified Domains Mailchimp API endpoint
12+
* @package MailchimpAPI\Resources
13+
*/
14+
class VerifiedDomains extends ApiResource
15+
{
16+
/* @var string */
17+
private $domain_name;
18+
19+
/**
20+
* The url component for this endpoint
21+
*/
22+
const URL_COMPONENT = '/verified-domains/';
23+
24+
const VERIFY_URL_COMPONENT = '/actions/verify';
25+
26+
/**
27+
* VerifiedDomains constructor.
28+
*
29+
* @param MailchimpRequest $request
30+
* @param MailchimpSettings $settings
31+
* @param null $domain_name
32+
*/
33+
public function __construct(MailchimpRequest $request, MailchimpSettings $settings, $domain_name = null)
34+
{
35+
parent::__construct($request, $settings);
36+
$request->appendToEndpoint(self::URL_COMPONENT . $domain_name);
37+
$this->domain_name = $domain_name;
38+
}
39+
40+
/**
41+
* @return \MailchimpAPI\Responses\MailchimpResponse
42+
* @throws \MailchimpAPI\MailchimpException
43+
*/
44+
public function verify()
45+
{
46+
$this->throwIfNot("domain-name", $this->domain_name);
47+
return $this->postToActionEndpoint(self::VERIFY_URL_COMPONENT);
48+
}
49+
}

src/Responses/FailureResponse.php

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class FailureResponse extends MailchimpResponse
1818
* @param $body
1919
* @param $http_code
2020
* @param callable|null $failure_callback
21-
* @throws MailchimpException
2221
*/
2322
public function __construct($headers, $body, $http_code, callable $failure_callback = null)
2423
{
2524
parent::__construct($headers, $body, $http_code);
26-
if ($failure_callback && is_callable($failure_callback)) {
25+
26+
if ($failure_callback) {
2727
call_user_func($failure_callback);
28-
} elseif ($failure_callback && !is_callable($failure_callback)) {
29-
throw new MailchimpException("The failure callback is not callable");
3028
}
3129
}
3230
}

src/Responses/SuccessResponse.php

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,13 @@ class SuccessResponse extends MailchimpResponse
1818
* @param $body
1919
* @param $http_code
2020
* @param callable|null $success_callback
21-
* @throws MailchimpException
2221
*/
2322
public function __construct($headers, $body, $http_code, callable $success_callback = null)
2423
{
2524
parent::__construct($headers, $body, $http_code);
26-
if (is_callable($success_callback)) {
27-
call_user_func("foo");
28-
} elseif ($success_callback && !is_callable($success_callback)) {
29-
throw new MailchimpException("The success callback is not callable");
25+
26+
if ($success_callback) {
27+
call_user_func($success_callback);
3028
}
3129
}
3230
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
4+
namespace MailchimpTests\Responses;
5+
6+
7+
use MailchimpAPI\Responses\FailureResponse;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class FailureResponseTest extends TestCase
11+
{
12+
public function testFailureCallback()
13+
{
14+
$called = false;
15+
16+
$callback = function () use (&$called) {
17+
$called = true;
18+
};
19+
20+
(new FailureResponse([], '', 200, $callback));
21+
$this->assertTrue($called == true, 'The callback should be called by FailureResponse');
22+
}
23+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
<?php
2+
3+
4+
namespace MailchimpTests\Responses;
5+
6+
7+
use MailchimpAPI\Responses\SuccessResponse;
8+
use PHPUnit\Framework\TestCase;
9+
10+
class SuccessResponseTest extends TestCase
11+
{
12+
public function testSuccessCallback()
13+
{
14+
$called = false;
15+
16+
$callback = function () use (&$called) {
17+
$called = true;
18+
};
19+
20+
(new SuccessResponse([], '', 200, $callback));
21+
$this->assertTrue($called == true, 'The callback should be called by SuccessResponse');
22+
}
23+
}

tests/VerifiedDomainsTest.php

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace MailchimpTests;
4+
5+
use MailchimpAPI\Resources\VerifiedDomains;
6+
7+
class VerifiedDomainsTest extends MailChimpTestCase
8+
{
9+
public function testVerifiedDomainsCollectionEndpoint()
10+
{
11+
$this->endpointUrlBuildTest(
12+
VerifiedDomains::URL_COMPONENT,
13+
$this->mailchimp->verifiedDomains(),
14+
"The verified domains collection endpoint should be constructed correctly"
15+
);
16+
}
17+
18+
public function testVerifiedDomainsInstanceEndpoint()
19+
{
20+
$this->endpointUrlBuildTest(
21+
VerifiedDomains::URL_COMPONENT . 'my-domain',
22+
$this->mailchimp->verifiedDomains('my-domain'),
23+
"The verified domains instance endpoint should be constructed correctly"
24+
);
25+
}
26+
}

0 commit comments

Comments
 (0)