Skip to content

Commit

Permalink
Merge pull request #5 from 77web/feat/reserve-send
Browse files Browse the repository at this point in the history
feature: changed sendCampaign and added scheduleCampaign
  • Loading branch information
77web authored Nov 14, 2023
2 parents 1f9d66e + 95a22bd commit 39bcb63
Show file tree
Hide file tree
Showing 5 changed files with 27 additions and 18 deletions.
17 changes: 17 additions & 0 deletions src/Campaign/ScheduleCampaignRequest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
<?php

declare(strict_types=1);

namespace Linkage\SendgridMarketingCampaignApiClient\Campaign;

readonly class ScheduleCampaignRequest
{
// timestamp
public int $sendAt;

public function __construct(
\DateTimeImmutable $shouldSendAt,
) {
$this->sendAt = $shouldSendAt->getTimestamp();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,11 @@

namespace Linkage\SendgridMarketingCampaignApiClient\Campaign;

readonly class SendCampaignResponse
readonly class ScheduleCampaignResponse
{
public function __construct(
public int $id,
public int $sendAt,
public string $status,
) {
}
Expand Down
9 changes: 0 additions & 9 deletions src/Campaign/SendCampaignRequest.php

This file was deleted.

10 changes: 5 additions & 5 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Linkage\SendgridMarketingCampaignApiClient\Campaign\CreateCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\CreateCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\SendCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\SendCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\ScheduleCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\ScheduleCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\AddMultipleRecipientsRequest;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\AddMultipleRecipientsResponse;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\CreateContactListRequest;
Expand Down Expand Up @@ -81,12 +81,12 @@ public function createCampaign(CreateCampaignRequest $request): CreateCampaignRe
* @throws SendgridApiClientException
* @throws SendgridApiServerException
*/
public function sendCampaign(int $campaignId, SendCampaignRequest $request): SendCampaignResponse
public function scheduleCampaign(int $campaignId, ScheduleCampaignRequest $request): ScheduleCampaignResponse
{
return $this->requester->post(
sprintf('campaigns/%d/schedules/now', $campaignId),
sprintf('campaigns/%d/schedules', $campaignId),
$request,
SendCampaignResponse::class,
ScheduleCampaignResponse::class,
);
}
}
6 changes: 3 additions & 3 deletions src/ClientInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,8 +6,8 @@

use Linkage\SendgridMarketingCampaignApiClient\Campaign\CreateCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\CreateCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\SendCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\SendCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\ScheduleCampaignRequest;
use Linkage\SendgridMarketingCampaignApiClient\Campaign\ScheduleCampaignResponse;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\AddMultipleRecipientsRequest;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\AddMultipleRecipientsResponse;
use Linkage\SendgridMarketingCampaignApiClient\ContactList\CreateContactListRequest;
Expand Down Expand Up @@ -55,5 +55,5 @@ public function createCampaign(CreateCampaignRequest $request): CreateCampaignRe
* @throws SendgridApiClientException
* @throws SendgridApiServerException
*/
public function sendCampaign(int $campaignId, SendCampaignRequest $request): SendCampaignResponse;
public function scheduleCampaign(int $campaignId, ScheduleCampaignRequest $request): ScheduleCampaignResponse;
}

0 comments on commit 39bcb63

Please sign in to comment.