-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #6 from mailerlite/issue-9983
Issue 9983
- Loading branch information
Showing
8 changed files
with
243 additions
and
1 deletion.
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
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 MailerLite\Endpoints; | ||
|
||
class Batch extends AbstractEndpoint | ||
{ | ||
protected string $endpoint = 'batch'; | ||
|
||
public function send(array $params): array | ||
{ | ||
return $this->httpLayer->post( | ||
$this->buildUri($this->endpoint), | ||
$params | ||
); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace MailerLite\Endpoints; | ||
|
||
class CampaignLanguage extends AbstractEndpoint | ||
{ | ||
protected string $endpoint = 'campaigns/languages'; | ||
|
||
public function get(): array | ||
{ | ||
return $this->httpLayer->get( | ||
$this->buildUri($this->endpoint) | ||
); | ||
} | ||
} |
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,15 @@ | ||
<?php | ||
|
||
namespace MailerLite\Endpoints; | ||
|
||
class Timezone extends AbstractEndpoint | ||
{ | ||
protected string $endpoint = 'timezones'; | ||
|
||
public function get(): array | ||
{ | ||
return $this->httpLayer->get( | ||
$this->buildUri($this->endpoint) | ||
); | ||
} | ||
} |
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,50 @@ | ||
<?php | ||
|
||
namespace MailerLite\Tests\Endpoints; | ||
|
||
use Http\Mock\Client; | ||
use MailerLite\Common\HttpLayer; | ||
use MailerLite\Endpoints\Batch; | ||
use MailerLite\Tests\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class BatchTest extends TestCase | ||
{ | ||
protected Batch $batch; | ||
protected ResponseInterface $response; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->client = new Client(); | ||
|
||
$this->batch = new Batch(new HttpLayer(self::OPTIONS, $this->client), self::OPTIONS); | ||
|
||
$this->response = $this->createMock(ResponseInterface::class); | ||
$this->response->method('getStatusCode')->willReturn(200); | ||
$this->client->addResponse($this->response); | ||
} | ||
|
||
public function test_send() | ||
{ | ||
$data = [ | ||
'requests' => [ | ||
[ | ||
'method' => 'post', | ||
'path' => 'api/subscribers', | ||
'body' => [ | ||
'email' => 'new_subscriber@mail.com' | ||
] | ||
] | ||
] | ||
]; | ||
|
||
$this->batch->send($data); | ||
|
||
$request = $this->client->getLastRequest(); | ||
|
||
self::assertEquals('POST', $request->getMethod()); | ||
self::assertEquals('/api/batch', $request->getUri()->getPath()); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace MailerLite\Tests\Endpoints; | ||
|
||
use Http\Mock\Client; | ||
use MailerLite\Common\HttpLayer; | ||
use MailerLite\Endpoints\CampaignLanguage; | ||
use MailerLite\Tests\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class CampaignLanguageTest extends TestCase | ||
{ | ||
protected CampaignLanguage $campaignLanguage; | ||
protected ResponseInterface $response; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->client = new Client(); | ||
|
||
$this->campaignLanguage = new CampaignLanguage(new HttpLayer(self::OPTIONS, $this->client), self::OPTIONS); | ||
|
||
$this->response = $this->createMock(ResponseInterface::class); | ||
$this->response->method('getStatusCode')->willReturn(200); | ||
$this->client->addResponse($this->response); | ||
} | ||
|
||
public function test_read_all() | ||
{ | ||
$this->campaignLanguage->get(); | ||
|
||
$request = $this->client->getLastRequest(); | ||
|
||
self::assertEquals('GET', $request->getMethod()); | ||
self::assertEquals('/api/campaigns/languages', $request->getUri()->getPath()); | ||
} | ||
} |
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,38 @@ | ||
<?php | ||
|
||
namespace MailerLite\Tests\Endpoints; | ||
|
||
use Http\Mock\Client; | ||
use MailerLite\Common\HttpLayer; | ||
use MailerLite\Endpoints\Timezone; | ||
use MailerLite\Tests\TestCase; | ||
use Psr\Http\Message\ResponseInterface; | ||
|
||
class TimezoneTest extends TestCase | ||
{ | ||
protected Timezone $timezone; | ||
protected ResponseInterface $response; | ||
|
||
protected function setUp(): void | ||
{ | ||
parent::setUp(); | ||
|
||
$this->client = new Client(); | ||
|
||
$this->timezone = new Timezone(new HttpLayer(self::OPTIONS, $this->client), self::OPTIONS); | ||
|
||
$this->response = $this->createMock(ResponseInterface::class); | ||
$this->response->method('getStatusCode')->willReturn(200); | ||
$this->client->addResponse($this->response); | ||
} | ||
|
||
public function test_read_all() | ||
{ | ||
$this->timezone->get(); | ||
|
||
$request = $this->client->getLastRequest(); | ||
|
||
self::assertEquals('GET', $request->getMethod()); | ||
self::assertEquals('/api/timezones', $request->getUri()->getPath()); | ||
} | ||
} |