Skip to content

Commit

Permalink
Merge branch 'develop' into release/2.4.0
Browse files Browse the repository at this point in the history
  • Loading branch information
sta1r committed Jan 31, 2024
2 parents 3263428 + 2fcf817 commit eef4656
Show file tree
Hide file tree
Showing 8 changed files with 118 additions and 6 deletions.
12 changes: 10 additions & 2 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,12 +1,20 @@
# 2.4.0

### What's new
- We added a method to update or create contact insight data.

### Improvements
- We added an annotation for the `getStatus()` method in the Contact model, to fix PHPStan errors.

# 2.3.1

### Improvements
- Its now possible to call `$contact→setDatafields()` passing an empty array.
- It's now possible to call `$contact→setDatafields()` passing an empty array.

# 2.3.0

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

# 2.2.0

Expand Down
9 changes: 9 additions & 0 deletions LICENSE.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
The MIT License (MIT)

Copyright (c) 2021 Dotdigital Group PLC

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
2 changes: 1 addition & 1 deletion 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.3.1",
"version": "2.4.0",
"license": "MIT",
"autoload": {
"psr-4": {
Expand Down
1 change: 1 addition & 0 deletions src/V3/Models/Contact.php
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
* @method getDataFields()
* @method getConsentRecords()
* @method getPreferences()
* @method getStatus()
*/
class Contact extends AbstractSingletonModel
{
Expand Down
35 changes: 34 additions & 1 deletion src/V3/Resources/InsightData.php
Original file line number Diff line number Diff line change
@@ -1,10 +1,11 @@
<?php

declare(strict_types=1);

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;

Expand Down Expand Up @@ -51,4 +52,36 @@ public function createOrUpdateAccountCollectionRecord(
$insightData
);
}

/**
* @param string $collectionName
* @param string $recordId
* @param string $identifier
* @param string $value
* @param array $insightData
*
* @return string
* @throws Exception
* @throws ResponseValidationException
*/
public function createOrUpdateContactCollectionRecord(
string $collectionName,
string $recordId,
string $identifier,
string $value,
array $insightData
): string {
return $this->put(
sprintf(
'%s/%s/%s/%s/%s/%s',
self::RESOURCE_BASE,
'contacts',
$identifier,
$value,
$collectionName,
$recordId
),
$insightData
);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@
* @runTestsInSeparateProcesses
* @coversDefaultClass InsightData
*/
class InsightDataCreateUpdateAccountCollectionTest extends TestCase
class InsightDataAccountCollectionTest extends TestCase
{
use InteractsWithContactTrait;

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

namespace Dotdigital\Tests\V3\Integration\InsightData;

use Dotdigital\AbstractClient;
use Dotdigital\Exception\ResponseValidationException;
use Dotdigital\V3\Models\Contact;
use Dotdigital\V3\Models\ContactCollection;
use Dotdigital\V3\Resources\InsightData;
use Dotdigital\Tests\V3\Integration\TestCase;
use Dotdigital\Tests\V3\Traits\InteractsWithContactTrait;
use Random\RandomException;

/**
* @runTestsInSeparateProcesses
* @coversDefaultClass InsightData
*/
class InsightDataContactCollectionTest extends TestCase
{
use InteractsWithContactTrait;

protected string $resourceBase = InsightData::RESOURCE_BASE;

protected AbstractClient $client;

/**
* @return void
* @throws RandomException
*/
public function testCartInsightDataUpsert()
{
$email = bin2hex(random_bytes(16)) . '@emailsim.io';
$contact = new Contact(
[
'matchIdentifier' => 'email',
'identifiers' => [
'email' => $email
]
]);

$this->client->contacts->create($contact);

$response = $this->client->insightData->createOrUpdateContactCollectionRecord(
'CartInsight',
'1',
'email',
$email,
[
'key' => '1001',
'contactIdentifier' => $email,
'json' => [
'cartId' => '1',
'grandTotal' => '90.00',
'lineItems' => []
]
]
);

$this->assertIsString($response);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
use Dotdigital\Tests\V3\Traits\InteractsWithContactTrait;
use Dotdigital\V3\Resources\InsightData;

class InsightDataTest extends TestCase
class InsightDataImportTest extends TestCase
{
use InteractsWithContactTrait;

Expand Down

0 comments on commit eef4656

Please sign in to comment.