Skip to content

Commit

Permalink
Merge pull request #6 from mailerlite/issue-9983
Browse files Browse the repository at this point in the history
Issue 9983
  • Loading branch information
npetrunova authored Jan 27, 2023
2 parents d8274fe + c628be6 commit 2e1f96c
Show file tree
Hide file tree
Showing 8 changed files with 243 additions and 1 deletion.
63 changes: 62 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,15 @@
* [Signups](#form-subscribers)
* [Automation API](#automation)
* [Read](#automation-read)
* [Activity](#automation-activity)
* [Activity](#automation-activity)
* [Webhook API](#webhook)
* [Create](#webhook-create)
* [Update](#webhook-update)
* [Read](#webhook-read)
* [Delete](#webhook-delete)
* [Campaign language API](#campaign-language-read)
* [Timezone API](#timezone-read)
* [Batch API](#batch-send)
* [Testing](#testing)
* [License](#license)

Expand Down Expand Up @@ -726,6 +734,59 @@ $webhookId = '123';
$response = $mailerLite->webhooks->delete($webhookId);
```

## Campaign language API
More information about request parameters on https://developers.mailerlite.com/docs/campaign-languages.html

<a name="campaign-language-read"></a>
### Read

```php
use MailerLite\MailerLite;

$mailerLite = new MailerLite(['api_key' => 'key']);

$response = $mailerLite->campaignLanguages->get();
```

## Timezone API
More information about request parameters on https://developers.mailerlite.com/docs/timezones.html

<a name="timezone-read"></a>
### Read

```php
use MailerLite\MailerLite;

$mailerLite = new MailerLite(['api_key' => 'key']);

$response = $mailerLite->timezones->get();
```

## Batch API
More information about request parameters on https://developers.mailerlite.com/docs/batching.html

<a name="batch-send"></a>
### Send

```php
use MailerLite\MailerLite;

$mailerLite = new MailerLite(['api_key' => 'key']);

$data = [
'requests' => [
[
'method' => 'post',
'path' => 'api/subscribers',
'body' => [
'email' => 'new_subscriber@mail.com'
]
]
]
];
$response = $mailerLite->batches->send($data);
```

<a name="testing"></a>
# Testing

Expand Down
16 changes: 16 additions & 0 deletions src/Endpoints/Batch.php
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
);
}
}
15 changes: 15 additions & 0 deletions src/Endpoints/CampaignLanguage.php
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)
);
}
}
15 changes: 15 additions & 0 deletions src/Endpoints/Timezone.php
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)
);
}
}
9 changes: 9 additions & 0 deletions src/MailerLite.php
Original file line number Diff line number Diff line change
Expand Up @@ -4,12 +4,15 @@

use MailerLite\Common\HttpLayer;
use MailerLite\Endpoints\Automation;
use MailerLite\Endpoints\Batch;
use MailerLite\Endpoints\Campaign;
use MailerLite\Endpoints\CampaignLanguage;
use MailerLite\Endpoints\Field;
use MailerLite\Endpoints\Form;
use MailerLite\Endpoints\Group;
use MailerLite\Endpoints\Segment;
use MailerLite\Endpoints\Subscriber;
use MailerLite\Endpoints\Timezone;
use MailerLite\Endpoints\Webhook;
use MailerLite\Exceptions\MailerLiteException;

Expand Down Expand Up @@ -37,6 +40,9 @@ class MailerLite
public Form $forms;
public Automation $automations;
public Webhook $webhooks;
public Timezone $timezones;
public CampaignLanguage $campaignLanguages;
public Batch $batches;

public function __construct(array $options = [], ?HttpLayer $httpLayer = null)
{
Expand Down Expand Up @@ -75,5 +81,8 @@ protected function setEndpoints(): void
$this->groups = new Group($this->httpLayer, $this->options);
$this->automations = new Automation($this->httpLayer, $this->options);
$this->webhooks = new Webhook($this->httpLayer, $this->options);
$this->timezones = new Timezone($this->httpLayer, $this->options);
$this->campaignLanguages = new CampaignLanguage($this->httpLayer, $this->options);
$this->batches = new Batch($this->httpLayer, $this->options);
}
}
50 changes: 50 additions & 0 deletions tests/Endpoints/BatchTest.php
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());
}
}
38 changes: 38 additions & 0 deletions tests/Endpoints/CampaignLanguageTest.php
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());
}
}
38 changes: 38 additions & 0 deletions tests/Endpoints/TimezoneTest.php
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());
}
}

0 comments on commit 2e1f96c

Please sign in to comment.