diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersController.php b/src/Api/ApigeeX/Controller/AppGroupMembersController.php index a4fe6b4b..411eaa3d 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersController.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersController.php @@ -20,6 +20,7 @@ use Apigee\Edge\Api\ApigeeX\Serializer\AppGroupMembershipSerializer; use Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership; +use Apigee\Edge\Api\Management\Serializer\AttributesPropertyAwareEntitySerializer; use Apigee\Edge\ClientInterface; use Apigee\Edge\Controller\AbstractController; use Apigee\Edge\Controller\OrganizationAwareControllerTrait; @@ -47,7 +48,7 @@ class AppGroupMembersController extends AbstractController implements AppGroupMe * * @param string $appGroup * @param string $organization - * @param \Apigee\Edge\ClientInterface $client + * @param ClientInterface $client */ public function __construct(string $appGroup, string $organization, ClientInterface $client) { @@ -73,8 +74,10 @@ public function getMembers(): AppGroupMembership public function setMembers(AppGroupMembership $members): AppGroupMembership { $members = $this->serializer->normalize($members); - $apigeeReservedMembers = new AttributesProperty(); + // We don't have a separate API to get appgroup attributes, + // that is why we are calling getAppGroupAttributes() method. + $apigeeReservedMembers = $this->getAppGroupAttributes(); // Adding the new members into the attribute. $apigeeReservedMembers->add('__apigee_reserved__developer_details', json_encode($members)); $response = $this->client->put( @@ -101,6 +104,23 @@ public function removeMember(string $email): void $this->client->delete($this->getBaseEndpointUri()->withPath("{$this->getBaseEndpointUri()->getPath()}/{$encoded}")); } + /** + * Helper function for getting all attributes in AppGroup. + * + * @return AttributesProperty + */ + public function getAppGroupAttributes(): AttributesProperty + { + $appGroup = $this->responseToArray($this->client->get($this->getBaseEndpointUri())); + $serializer = new AttributesPropertyAwareEntitySerializer(); + $appGroupAttributes = $serializer->denormalize( + $appGroup['attributes'], + AttributesProperty::class + ); + + return $appGroupAttributes; + } + /** * {@inheritdoc} */ diff --git a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php index 9f5f67b1..a321d92e 100644 --- a/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php +++ b/src/Api/ApigeeX/Controller/AppGroupMembersControllerInterface.php @@ -28,7 +28,7 @@ interface AppGroupMembersControllerInterface extends AppGroupAwareControllerInte /** * List all developers associated with a appgroup. * - * @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership + * @return AppGroupMembership * Array of developers with their optional roles in the appgroup. */ public function getMembers(): AppGroupMembership; @@ -39,10 +39,10 @@ public function getMembers(): AppGroupMembership; * WARNING! If you pass en empty membership object you remove all developers * from the appgroup. * - * @param \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership $members + * @param AppGroupMembership $members * Membership object with the changes to be applied. * - * @return \Apigee\Edge\Api\ApigeeX\Structure\AppGroupMembership + * @return AppGroupMembership * Membership object with the applied changes, it does not contain all * members. Use getMembers() to retrieve them. */