Skip to content
This repository was archived by the owner on Oct 24, 2023. It is now read-only.

Commit 0522fe0

Browse files
committed
feat(Project): support external OAuth
Closes #474
1 parent 1e6961d commit 0522fe0

File tree

5 files changed

+127
-1
lines changed

5 files changed

+127
-1
lines changed

src/Core/Builder/Update/ProjectActionBuilder.php

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
1111
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
1212
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
13+
use Commercetools\Core\Request\Project\Command\ProjectSetExternalOAuthAction;
1314
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
1415

1516
class ProjectActionBuilder
@@ -82,6 +83,17 @@ public function changeName($action = null)
8283
return $this;
8384
}
8485

86+
/**
87+
* @link https://docs.commercetools.com/http-api-projects-project.html#set-externaloauth
88+
* @param ProjectSetExternalOAuthAction|callable $action
89+
* @return $this
90+
*/
91+
public function setExternalOAuth($action = null)
92+
{
93+
$this->addAction($this->resolveAction(ProjectSetExternalOAuthAction::class, $action));
94+
return $this;
95+
}
96+
8597
/**
8698
* @link https://docs.commercetools.com/http-api-projects-project.html#set-shippingrateinputtype
8799
* @param ProjectSetShippingRateInputTypeAction|callable $action
Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,26 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Model\Project;
4+
5+
use Commercetools\Core\Model\Common\Context;
6+
use Commercetools\Core\Model\Common\JsonObject;
7+
use Commercetools\Core\Model\Common\LocalizedEnumCollection;
8+
9+
/**
10+
* @package Commercetools\Core\Model\Project
11+
* @link https://docs.commercetools.com/http-api-projects-project.html#externaloauth
12+
* @method string getUrl()
13+
* @method ExternalOAuth setUrl(string $url = null)
14+
* @method string getAuthorizationHeader()
15+
* @method ExternalOAuth setAuthorizationHeader(string $authorizationHeader = null)
16+
*/
17+
class ExternalOAuth extends JsonObject
18+
{
19+
public function fieldDefinitions()
20+
{
21+
return [
22+
'url' => [static::TYPE => 'string'],
23+
'authorizationHeader' => [static::TYPE => 'string']
24+
];
25+
}
26+
}

src/Core/Model/Project/Project.php

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,8 @@
3434
* @method Project setVersion(int $version = null)
3535
* @method ShippingRateInputType getShippingRateInputType()
3636
* @method Project setShippingRateInputType(ShippingRateInputType $shippingRateInputType = null)
37+
* @method ExternalOAuth getExternalOAuth()
38+
* @method Project setExternalOAuth(ExternalOAuth $externalOAuth = null)
3739
*/
3840
class Project extends JsonObject
3941
{
@@ -55,7 +57,8 @@ public function fieldDefinitions()
5557
static::DECORATOR => DateTimeDecorator::class
5658
],
5759
'messages' => [static::TYPE => MessagesConfiguration::class],
58-
'shippingRateInputType' => [static::TYPE => ShippingRateInputType::class]
60+
'shippingRateInputType' => [static::TYPE => ShippingRateInputType::class],
61+
'externalOAuth' => [static::TYPE => ExternalOAuth::class]
5962
];
6063
}
6164
}
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
<?php
2+
3+
namespace Commercetools\Core\Request\Project\Command;
4+
5+
use Commercetools\Core\Model\Common\Context;
6+
use Commercetools\Core\Model\Project\ExternalOAuth;
7+
use Commercetools\Core\Request\AbstractAction;
8+
9+
/**
10+
* @package Commercetools\Core\Request\Project\Command
11+
* @link https://docs.commercetools.com/http-api-projects-project.html#set-externaloauth
12+
* @method string getAction()
13+
* @method ProjectSetExternalOAuthAction setAction(string $action = null)
14+
* @method ExternalOAuth getExternalOAuth()
15+
* @method ProjectSetExternalOAuthAction setExternalOAuth(ExternalOAuth $externalOAuth = null)
16+
*/
17+
class ProjectSetExternalOAuthAction extends AbstractAction
18+
{
19+
public function fieldDefinitions()
20+
{
21+
return [
22+
'action' => [static::TYPE => 'string'],
23+
'externalOAuth' => [static::TYPE => ExternalOAuth::class],
24+
];
25+
}
26+
27+
/**
28+
* @param array $data
29+
* @param Context|callable $context
30+
*/
31+
public function __construct(array $data = [], $context = null)
32+
{
33+
parent::__construct($data, $context);
34+
$this->setAction('setExternalOAuth');
35+
}
36+
37+
/**
38+
* @param ExternalOAuth $externalOAuth
39+
* @param Context|callable $context
40+
* @return ProjectSetExternalOAuthAction
41+
*/
42+
public static function ofExternalOAuth(ExternalOAuth $externalOAuth, $context = null)
43+
{
44+
return static::of($context)->setExternalOAuth($externalOAuth);
45+
}
46+
}

tests/integration/Project/ProjectUpdateRequestTest.php

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55

66
namespace Commercetools\Core\IntegrationTests\Project;
77

8+
use Commercetools\Core\Builder\Request\RequestBuilder;
9+
use Commercetools\Core\Builder\Update\ActionBuilder;
810
use Commercetools\Core\IntegrationTests\ApiTestCase;
911
use Commercetools\Core\Model\Common\LocalizedEnum;
1012
use Commercetools\Core\Model\Common\LocalizedEnumCollection;
@@ -13,13 +15,15 @@
1315
use Commercetools\Core\Model\Project\CartClassificationType;
1416
use Commercetools\Core\Model\Project\CartScoreType;
1517
use Commercetools\Core\Model\Project\CartValueType;
18+
use Commercetools\Core\Model\Project\ExternalOAuth;
1619
use Commercetools\Core\Model\Project\Project;
1720
use Commercetools\Core\Request\Project\Command\ProjectChangeCountriesAction;
1821
use Commercetools\Core\Request\Project\Command\ProjectChangeCurrenciesAction;
1922
use Commercetools\Core\Request\Project\Command\ProjectChangeLanguagesAction;
2023
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesConfigurationAction;
2124
use Commercetools\Core\Request\Project\Command\ProjectChangeMessagesEnabledAction;
2225
use Commercetools\Core\Request\Project\Command\ProjectChangeNameAction;
26+
use Commercetools\Core\Request\Project\Command\ProjectSetExternalOAuthAction;
2327
use Commercetools\Core\Request\Project\Command\ProjectSetShippingRateInputTypeAction;
2428
use Commercetools\Core\Request\Project\ProjectGetRequest;
2529
use Commercetools\Core\Request\Project\ProjectUpdateRequest;
@@ -280,4 +284,39 @@ public function testSetShippingRateInputTypeCartClassification()
280284
$response = $request->executeWithClient($this->getClient());
281285
$this->assertFalse($response->isError());
282286
}
287+
288+
public function testExternalOAuth()
289+
{
290+
$request = ProjectGetRequest::of();
291+
$response = $request->executeWithClient($this->getClient());
292+
$project = $request->mapResponse($response);
293+
294+
$this->assertInstanceOf(Project::class, $project);
295+
296+
$request = RequestBuilder::of()->project()->update($project)->setActions(
297+
ActionBuilder::of()->project()->setExternalOAuth(function (ProjectSetExternalOAuthAction $action) {
298+
$action->setExternalOAuth(
299+
ExternalOAuth::of()->setUrl("https://localhost")
300+
->setAuthorizationHeader("Bearer")
301+
);
302+
return $action;
303+
})->getActions()
304+
);
305+
$response = $request->executeWithClient($this->getClient());
306+
$result = $request->mapResponse($response);
307+
308+
$this->assertInstanceOf(Project::class, $result);
309+
$this->assertInstanceOf(ExternalOAuth::class, $result->getExternalOAuth());
310+
$this->assertNotSame("Bearer", $result->getExternalOAuth()->getAuthorizationHeader());
311+
312+
$request = RequestBuilder::of()->project()->update($result)->setActions(
313+
ActionBuilder::of()->project()->setExternalOAuth(function (ProjectSetExternalOAuthAction $action) {
314+
return $action;
315+
})->getActions()
316+
);
317+
$response = $request->executeWithClient($this->getClient());
318+
$result = $request->mapResponse($response);
319+
$this->assertFalse($response->isError());
320+
$this->assertNull($result->getExternalOAuth());
321+
}
283322
}

0 commit comments

Comments
 (0)