Skip to content

Commit

Permalink
Merged PR 48986: Release 2.3.0
Browse files Browse the repository at this point in the history
Related work items: #211425, #229536, #229740, #229910, #231234, #231346
  • Loading branch information
sertlab committed Oct 31, 2023
2 parents 18f7b59 + 34d1b98 commit d23b895
Show file tree
Hide file tree
Showing 19 changed files with 421 additions and 261 deletions.
5 changes: 5 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,8 @@
# 2.3.0

### What's new
- We’ve added a new V3 InsightData resource, with two PUT methods for bulk import and single upsert.

# 2.2.0

### What's new
Expand Down
6 changes: 3 additions & 3 deletions composer.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "dotdigital/dotdigital-php",
"description": "Dotdigital PHP Library",
"version": "2.2.0",
"version": "2.3.0",
"license": "MIT",
"autoload": {
"psr-4": {
Expand All @@ -26,9 +26,9 @@
"guzzlehttp/guzzle": "^7.4",
"symplify/easy-coding-standard": "^9.4",
"phpstan/phpstan": "^1.0",
"phpunit/phpunit": "^10.1.1",
"phpunit/phpunit": "^9.6",
"php-http/curl-client": "^2.2",
"symfony/dotenv": "^6.2",
"symfony/dotenv": "^5.4",
"fakerphp/faker": "^1.22"
},
"config": {
Expand Down
3 changes: 2 additions & 1 deletion phpunit.xml → phpunit.xml.dist
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?xml version="1.0" encoding="UTF-8"?>
<phpunit bootstrap="vendor/autoload.php">
<phpunit
bootstrap="vendor/autoload.php">
<testsuites>
<testsuite name="Dotdigital_V2">
<directory>./tests/V2</directory>
Expand Down
3 changes: 2 additions & 1 deletion src/HttpClient/Message/V3/ResponseMediator.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ class ResponseMediator
private static $passableStatusCodes = [
200,
201,
202
202,
204
];

/**
Expand Down
2 changes: 2 additions & 0 deletions src/V3/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,12 @@
use Dotdigital\Exception\ResponseValidationException;
use Dotdigital\HttpClient\Message\V3\ResponseMediator;
use Dotdigital\V3\Resources\Contacts;
use Dotdigital\V3\Resources\InsightData;
use Psr\Http\Message\ResponseInterface;

/**
* @property Contacts $contacts
* @property InsightData $insightData
*/
class Client extends AbstractClient
{
Expand Down
46 changes: 46 additions & 0 deletions src/V3/Models/InsightData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
<?php

declare(strict_types=1);

namespace Dotdigital\V3\Models;

use Dotdigital\V3\Models\InsightData\Record;
use Dotdigital\V3\Models\InsightData\RecordsCollection;

class InsightData extends AbstractSingletonModel
{
/**
* @var string
*/
protected string $collectionName;

/**
* @var string
*/
protected string $collectionScope;

/**
* @var string
*/
protected string $collectionType;

/**
* @var RecordsCollection
*/
protected RecordsCollection $records;

/**
* @param $data
* @return void
* @throws \Exception
*/
public function setRecords($data)
{
$recordsCollection = new RecordsCollection();
foreach ($data as $array) {
$record = new Record($array);
$recordsCollection->add($record);
}
$this->records = $recordsCollection;
}
}
18 changes: 18 additions & 0 deletions src/V3/Models/InsightData/ContactIdentity.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
<?php

namespace Dotdigital\V3\Models\InsightData;

use Dotdigital\V3\Models\AbstractSingletonModel;

class ContactIdentity extends AbstractSingletonModel
{
/**
* @var string
*/
protected string $identifier;

/**
* @var string
*/
protected string $value;
}
34 changes: 34 additions & 0 deletions src/V3/Models/InsightData/Record.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
<?php

namespace Dotdigital\V3\Models\InsightData;

use Dotdigital\V3\Models\AbstractSingletonModel;
use Dotdigital\V3\Models\InsightData\ContactIdentity;

class Record extends AbstractSingletonModel
{
/**
* @var ContactIdentity|null
*/
protected ?ContactIdentity $contactIdentity;

/**
* @var string
*/
protected string $key;

/**
* @var array
*/
protected array $json;

/**
* @param array $data
* @return void
* @throws \Exception
*/
public function setContactIdentity(array $data)
{
$this->contactIdentity = new ContactIdentity($data);
}
}
9 changes: 9 additions & 0 deletions src/V3/Models/InsightData/RecordsCollection.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<?php

namespace Dotdigital\V3\Models\InsightData;

use Dotdigital\V3\Models\Collection;

class RecordsCollection extends Collection
{
}
54 changes: 54 additions & 0 deletions src/V3/Resources/InsightData.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<?php

namespace Dotdigital\V3\Resources;

use Dotdigital\Exception\ResponseValidationException;
use Dotdigital\Resources\AbstractResource;
use Dotdigital\V3\Models\AbstractSingletonModel;
use Dotdigital\V3\Models\InsightData as InsightDataModel;
use Http\Client\Exception;

class InsightData extends AbstractResource
{
public const RESOURCE_BASE = '/insightData/v3';

/**
* @param InsightDataModel $insightData
* @return string
* @throws \Dotdigital\Exception\ResponseValidationException
* @throws \Http\Client\Exception
*/
public function import(InsightDataModel $insightData): string
{
return $this->put(
sprintf('%s/%s', self::RESOURCE_BASE, 'import'),
json_decode(json_encode($insightData), true)
);
}

/**
* @param string $collectionName
* @param string $recordId
* @param array $insightData
*
* @return string
* @throws ResponseValidationException
* @throws Exception
*/
public function createOrUpdateAccountCollectionRecord(
string $collectionName,
string $recordId,
array $insightData
): string {
return $this->put(
sprintf(
'%s/%s/%s/%s/',
self::RESOURCE_BASE,
'account',
$collectionName,
$recordId
),
$insightData
);
}
}
15 changes: 9 additions & 6 deletions src/V3/Utility/Pagination/Link.php
Original file line number Diff line number Diff line change
Expand Up @@ -53,13 +53,16 @@ public function getLink(): string
*/
public function getParams(): array
{
parse_str(
parse_url(
$this->link,
PHP_URL_QUERY
),
$params
$queryString = parse_url(
$this->link,
PHP_URL_QUERY
);

if (!is_string($queryString)) {
return [];
}

parse_str($queryString, $params);
return $params;
}
}
22 changes: 0 additions & 22 deletions tests/ApiConfigurationTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,26 +18,4 @@ protected function clientInit(): void
$this->client::setApiPassword('demo');
$this->client::setApiEndpoint('https://r1-api.dotmailer.com');
}

/** @test */
public function testSuccessResponse()
{
$response = $this->client->getHttpClient()->get($this->resourceBase);
Assert::assertEquals(200, $response->getStatusCode());

$contentType = $response->getHeaders()["Content-Type"][0];
Assert::assertEquals("application/json; charset=utf-8", $contentType);
}

/** @test */
public function testFailedResponse()
{
$this->client::setApiUser('invalid_ec_user');
$this->client::setApiPassword('invalid_ec_password');
$response = $this->client->getHttpClient()->get($this->resourceBase);;
Assert::assertEquals(401, $response->getStatusCode());

$contentType = $response->getHeaders()["Content-Type"][0];
Assert::assertEquals("application/json; charset=utf-8", $contentType);
}
}
66 changes: 18 additions & 48 deletions tests/V3/Integration/ContactCreateTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@
use Dotdigital\Exception\ResponseValidationException;
use Dotdigital\V3\Models\Contact;
use Dotdigital\V3\Resources\Contacts;
use Dotdigital\Tests\V3\Traits\InteractsWithContactTrait;
use PHPUnit\Framework\Assert;

class ContactCreateTest extends TestCase
{
use InteractsWithContactTrait;

protected string $resourceBase = Contacts::RESOURCE_BASE;

protected AbstractClient $client;

public function setUp(): void
/** @test */
public function testSuccessResponse()
{
parent::setUp();
$response = $this->client->getHttpClient()->get($this->resourceBase);
Assert::assertEquals(200, $response->getStatusCode());

$this->testSuccessResponse();
$contentType = $response->getHeaders()["Content-Type"][0];
Assert::assertEquals("application/json; charset=utf-8", $contentType);
}

/**
Expand Down Expand Up @@ -45,52 +52,15 @@ public function testCreateInvalidContact()
$this->client->contacts->create($contact);
}

private function buildInvalidContact()
/** @test */
public function testFailedResponse()
{
return new Contact(
[
'matchIdentifier' => 'email',
'dataFields' => [
'firstName' => 'Chaznay',
'lastName' => 'Kangaroo',
'gender' => 'female'
],
'consentRecords' => [
[
"text" => "Yes, I would like to receive a monthly newsletter",
"dateTimeConsented" => "2018-01-26T21:29:00",
"url" => "http://www.example.com/signup",
"ipAddress" => "129.168.0.2",
"userAgent" => "Mozilla/5.0 (X11; OpenBSD i386) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
]
]
]
);
}
$this->client::setApiUser('invalid_ec_user');
$this->client::setApiPassword('invalid_ec_password');
$response = $this->client->getHttpClient()->get($this->resourceBase);;
Assert::assertEquals(401, $response->getStatusCode());

private function buildContact()
{
return new Contact(
[
'matchIdentifier' => 'email',
'identifiers' => [
'email' => bin2hex(random_bytes(16)) . '@emailsim.io'
],
'dataFields' => [
'firstName' => 'Chaznay',
'lastName' => 'Kangaroo',
'gender' => 'female'
],
'consentRecords' => [
[
"text" => "Yes, I would like to receive a monthly newsletter",
"dateTimeConsented" => "2018-01-26T21:29:00",
"url" => "http://www.example.com/signup",
"ipAddress" => "129.168.0.2",
"userAgent" => "Mozilla/5.0 (X11; OpenBSD i386) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/36.0.1985.125 Safari/537.36"
]
]
]
);
$contentType = $response->getHeaders()["Content-Type"][0];
Assert::assertEquals("application/json; charset=utf-8", $contentType);
}
}
6 changes: 0 additions & 6 deletions tests/V3/Integration/ContactImportReportTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -21,12 +21,6 @@ class ContactImportReportTest extends DotdigitalTestCase
*/
protected AbstractClient $client;

public function setUp(): void
{
parent::setUp();
$this->testSuccessResponse();
}

public function testSuccessfulImport()
{
$importId = $this->client->contacts->import($this->generateContactCollection(200));
Expand Down
Loading

0 comments on commit d23b895

Please sign in to comment.