Skip to content

Commit

Permalink
Merge pull request #1 from apigee/2.x
Browse files Browse the repository at this point in the history
Update from apigee repo
  • Loading branch information
phdhiren authored Apr 29, 2021
2 parents d0040d8 + 51300f6 commit 2516c81
Show file tree
Hide file tree
Showing 76 changed files with 3,871 additions and 37 deletions.
13 changes: 8 additions & 5 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
language: php
sudo: false

addons:
apt:
Expand All @@ -9,8 +8,9 @@ addons:
php:
- 7.1
- 7.2
- 7.3

matrix:
jobs:
fast_finish: true

cache:
Expand All @@ -27,19 +27,22 @@ env:
# To prevent failing test runs caused by
# "The process "phpunit" exceeded the timeout of 300 seconds.
- COMPOSER_PROCESS_TIMEOUT=0
matrix:
jobs:
- DEPENDENCIES="--prefer-lowest"
- DEPENDENCIES=""
install:
# Disable xDebug (but do not remove its configuration, because we need that for code coverage calculation).
# Clear the default 6 minutes max execution time limit otherwise test suite fails in case of online tests.
- echo -en "max_execution_time = 0\nxdebug.default_enable = 0" >> ~/.phpenv/versions/$(phpenv version-name)/etc/conf.d/travis.ini
- composer self-update --rollback
- composer global require hirak/prestissimo:^0.3.7
- composer self-update --1
- if [[ $(phpenv version-name) = "7.1" ]] || [[ $(phpenv version-name) = "7.2" ]]; then composer global require hirak/prestissimo:^0.3.7; fi

- travis_retry composer update $COMPOSER_OPTIONS $DEPENDENCIES
# Fix PHPUnit tests on PHP >= 7.2 by upgrading Guzzle to >= 6.3.0.
# https://github.com/guzzle/guzzle/issues/1973
- if [[ $(phpenv version-name) = "7.2" ]] && [[ "$DEPENDENCIES" = "--prefer-lowest" ]]; then composer require guzzlehttp/guzzle:^6.3.0 --update-with-dependencies $DEPENDENCIES; fi
- if [[ $(phpenv version-name) = "7.3" ]] && [[ "$DEPENDENCIES" = "--prefer-lowest" ]]; then composer require guzzlehttp/guzzle:^6.3.0 --update-with-dependencies $DEPENDENCIES; fi
- if [[ $(phpenv version-name) = "7.4" ]] && [[ "$DEPENDENCIES" = "--prefer-lowest" ]]; then composer require guzzlehttp/guzzle:^6.3.0 --update-with-dependencies $DEPENDENCIES; fi
- composer show

# We run tests even if the code style analyses fails just to be able get a complete picture about what needs to be
Expand Down
7 changes: 7 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,12 @@
# CHANGELOG

## [2.0.7](https://github.com/apigee/apigee-client-php/milestone/6?closed=1)
* Added support for Apigee X connections (New Feature)
API providers can now connect their Drupal 8/9 developer portals to Apigee X organizations. API providers using Apigee X with Monetization enabled can now leverage monetization features in their Drupal developer portals. For more information, see [Overview of Apigee monetization](https://cloud.google.com/apigee/docs/api-platform/monetization/overview) and the [Apigee Monetization Drupal module documentation](https://www.drupal.org/docs/contributed-modules/apigee-monetization).

* [#105](https://github.com/apigee/apigee-client-php/pull/123) Unable to retrieve analytics data on developer app analytics page for hybrid orgs.
* [#108](https://github.com/apigee/apigee-client-php/pull/125) Notice in recent message logs if description is empty after creating app in Apigee hybrid.

## [2.0.6](https://github.com/apigee/apigee-client-php/milestone/5?closed=1)
* Dropped support of HTTPlug 1.x libraries (HTTPlug, Client Common and Guzzle 6 adapter).
* Added support for GCE Service Account Authentication.
Expand Down
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,8 @@
"guzzlehttp/guzzle": "<6.1.0",
"guzzlehttp/psr7": "<1.4.1",
"phpdocumentor/type-resolver": "<0.2.1",
"vimeo/psalm": ">2.0.13"
"vimeo/psalm": ">2.0.13",
"symfony/polyfill-mbstring": ">1.20.0"
},
"autoload": {
"psr-4": {
Expand Down
171 changes: 171 additions & 0 deletions src/Api/ApigeeX/Controller/AcceptedRatePlanController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,171 @@
<?php

/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface;
use Apigee\Edge\Api\ApigeeX\Entity\RatePlanInterface;
use Apigee\Edge\Api\ApigeeX\Serializer\AcceptedRatePlanSerializer;
use Apigee\Edge\Api\Monetization\Controller\OrganizationAwareEntityController;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Controller\EntityListingControllerTrait;
use Apigee\Edge\Controller\EntityLoadOperationControllerTrait;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Psr\Http\Message\UriInterface;
use ReflectionClass;

abstract class AcceptedRatePlanController extends OrganizationAwareEntityController implements AcceptedRatePlanControllerInterface
{
use EntityListingControllerTrait;
use EntityLoadOperationControllerTrait;
use PaginatedListingHelperTrait;

/**
* AcceptedRatePlanController constructor.
*
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer
*/
public function __construct(string $organization, ClientInterface $client, ?EntitySerializerInterface $entitySerializer = null)
{
$entitySerializer = $entitySerializer ?? new AcceptedRatePlanSerializer();
parent::__construct($organization, $client, $entitySerializer);
}

/**
* {@inheritdoc}
*/
public function getAllAcceptedRatePlans(): array
{
return $this->getAcceptedRatePlans();
}

/**
* {@inheritdoc}
*/
public function getPaginatedAcceptedRatePlanList(int $limit = null, int $page = 1): array
{
$query_params = [
'page' => $page,
];

if (null !== $limit) {
$query_params['size'] = $limit;
}

return $this->getAcceptedRatePlans($query_params);
}

/**
* {@inheritdoc}
*/
public function acceptRatePlan(RatePlanInterface $ratePlan): AcceptedRatePlanInterface
{
$rc = new ReflectionClass($this->getEntityClass());
/** @var \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface $acceptedRatePlan */
$acceptedRatePlan = $rc->newInstance(
[
'ratePlan' => $ratePlan,
]
);

$payload = $this->getEntitySerializer()->serialize($acceptedRatePlan, 'json');

$tmp = json_decode($payload, true);

$payload = json_encode($tmp);

$response = $this->client->post($this->getBaseEndpointUri(), $payload);
$this->getEntitySerializer()->setPropertiesFromResponse($response, $acceptedRatePlan);

return $acceptedRatePlan;
}

/**
* {@inheritdoc}
*
* @psalm-suppress PossiblyNullArgument - id is not null in this context.
*/
public function updateSubscription(AcceptedRatePlanInterface $acceptedRatePlan): void
{
$id = $acceptedRatePlan->getName();
$response = $this->client->post($this->getEntityCancelEndpointUri($id));
}

/**
* Builds context for the entity normalizer.
*
* Allows controllers to add extra metadata to the payload.
*
* @return array
*/
abstract protected function buildContextForEntityTransformerInCreate(): array;

/**
* Returns the URI for listing accepted rate plans.
*
* We have to introduce this because it is not regular that an entity
* has more than one listing endpoint so getBaseEntityEndpoint() was
* enough until this time.
*
* @return \Psr\Http\Message\UriInterface
*/
abstract protected function getAcceptedRatePlansEndpoint(): UriInterface;

/**
* Allows to alter payload before it gets sent to the API.
*
* @param array $payload
* API request payload.
*/
protected function alterRequestPayload(array &$payload, AcceptedRatePlanInterface $acceptedRatePlan): void
{
}

/**
* Helper function for listing accepted rate plans.
*
* @param array $query_params
* Additional query parameters.
*
* @return \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface[]
*
* @psalm-suppress PossiblyNullArrayOffset - id() does not return null here.
*/
private function getAcceptedRatePlans(array $query_params = []): array
{
$entities = [];

foreach ($this->getRawList($this->getAcceptedRatePlansEndpoint()->withQuery(http_build_query($query_params))) as $item) {
// Added ID as name since in ApigeeX name field gives the id
$item->id = (!isset($item->id)) ? $item->name : '';

/** @var \Apigee\Edge\Entity\EntityInterface $tmp */
$tmp = $this->getEntitySerializer()->denormalize(
$item,
AcceptedRatePlanInterface::class,
'json'
);

$entities[$tmp->id()] = $tmp;
}

return $entities;
}
}
69 changes: 69 additions & 0 deletions src/Api/ApigeeX/Controller/AcceptedRatePlanControllerInterface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
<?php

/*
* Copyright 2021 Google LLC
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* https://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

namespace Apigee\Edge\Api\ApigeeX\Controller;

use Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface;
use Apigee\Edge\Api\ApigeeX\Entity\RatePlanInterface;
use Apigee\Edge\Controller\EntityControllerInterface;
use Apigee\Edge\Controller\EntityLoadOperationControllerInterface;

/**
* Interface AcceptedRatePlanControllerInterface.
*
* TODO: Add reference documentation link
*/
interface AcceptedRatePlanControllerInterface extends
EntityControllerInterface,
EntityLoadOperationControllerInterface
{
/**
* Gets all accepted rate plans.
*
* @return \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface[]
*/
public function getAllAcceptedRatePlans(): array;

/**
* Gets accepted rate plans in the provided range.
*
* @param int|null $limit
* @param int $page
*
* @return \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface[]
*/
public function getPaginatedAcceptedRatePlanList(int $limit = null, int $page = 1): array;

/**
* Accepts a rate plan.
*
* @param \Apigee\Edge\Api\ApigeeX\Entity\RatePlanInterface $ratePlan
* The rate plan to be accepted.
*
* @return \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface
*/
public function acceptRatePlan(RatePlanInterface $ratePlan): AcceptedRatePlanInterface;

/**
* Update a rate plan that has been accepted by a developer.
*
* @param \Apigee\Edge\Api\ApigeeX\Entity\AcceptedRatePlanInterface $acceptedRatePlan
* Previously accepted rate plan that should be modified.
*/
public function updateSubscription(AcceptedRatePlanInterface $acceptedRatePlan): void;
}
Loading

0 comments on commit 2516c81

Please sign in to comment.