Skip to content

Commit

Permalink
Merge pull request #51 from mxr576/DRUP-487
Browse files Browse the repository at this point in the history
DRUP-487 Added support for Monetization Reports API
  • Loading branch information
cnovak authored May 8, 2019
2 parents edfda4b + 5eb182c commit 02dd82e
Show file tree
Hide file tree
Showing 70 changed files with 3,447 additions and 113 deletions.
24 changes: 12 additions & 12 deletions src/Api/Management/Query/StatsQueryInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ public function getMetrics(): array;
/**
* @param string[] $metrics
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setMetrics(array $metrics): StatsQueryInterface;

Expand All @@ -49,7 +49,7 @@ public function getTimeRange(): Period;
/**
* @param Period $timeRange
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setTimeRange(Period $timeRange): StatsQueryInterface;

Expand All @@ -61,7 +61,7 @@ public function getTimeUnit(): ?string;
/**
* @param string|null $timeUnit
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setTimeUnit(?string $timeUnit): StatsQueryInterface;

Expand All @@ -73,7 +73,7 @@ public function getSortBy(): ?string;
/**
* @param string|null $sortBy
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setSortBy(?string $sortBy): StatsQueryInterface;

Expand All @@ -85,7 +85,7 @@ public function getSort(): ?string;
/**
* @param string|null $sort
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setSort(?string $sort): StatsQueryInterface;

Expand All @@ -97,7 +97,7 @@ public function getTopK(): ?int;
/**
* @param int|null $topK
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setTopK(?int $topK): StatsQueryInterface;

Expand All @@ -109,7 +109,7 @@ public function getLimit(): ?int;
/**
* @param int|null $limit
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setLimit(?int $limit): StatsQueryInterface;

Expand All @@ -121,7 +121,7 @@ public function getOffset(): ?int;
/**
* @param int|null $offset
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setOffset(?int $offset): StatsQueryInterface;

Expand All @@ -133,7 +133,7 @@ public function getRealtime(): ?bool;
/**
* @param bool|null $realtime
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setRealtime(?bool $realtime): StatsQueryInterface;

Expand All @@ -145,7 +145,7 @@ public function getAccuracy(): ?int;
/**
* @param int|null $accuracy
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setAccuracy(?int $accuracy): StatsQueryInterface;

Expand All @@ -157,7 +157,7 @@ public function getTsAscending(): bool;
/**
* @param bool $tsAscending
*
* @return StatsQueryInterface
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*/
public function setTsAscending(bool $tsAscending): StatsQueryInterface;

Expand All @@ -169,7 +169,7 @@ public function getFilter(): ?string;
/**
* @param string|null $filter
*
* @return StatsQuery
* @return \Apigee\Edge\Api\Management\Query\StatsQueryInterface
*
* @see https://docs.apigee.com/analytics-services/reference/analytics-reference#filters
*/
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* Copyright 2018 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\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Entity\CompanyReportDefinition;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Psr\Http\Message\UriInterface;

class CompanyReportDefinitionController extends LegalEntityReportDefinitionController implements CompanyReportDefinitionControllerInterface
{
/**
* @var string
*/
protected $companyName;

/**
* CompanyReportDefinitionController constructor.
*
* @param string $developerId
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param \Apigee\Edge\Api\Monetization\Controller\ReportDefinitionControllerInterface|null $reportDefinitionController
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer
*/
public function __construct(string $developerId, string $organization, ClientInterface $client, ?ReportDefinitionControllerInterface $reportDefinitionController = null, ?EntitySerializerInterface $entitySerializer = null)
{
$this->companyName = $developerId;
parent::__construct($organization, $client, $reportDefinitionController, $entitySerializer);
}

/**
* @inheritdoc
*/
protected function getBaseEndpointUri(): UriInterface
{
return $this->client->getUriFactory()->createUri("/mint/organizations/{$this->organization}/companies/{$this->companyName}/report-definitions");
}

/**
* @inheritdoc
*/
protected function getEntityClass(): string
{
return CompanyReportDefinition::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* Copyright 2018 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\Monetization\Controller;

interface CompanyReportDefinitionControllerInterface extends ReportDefinitionControllerInterface
{
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?php

/*
* Copyright 2018 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\Monetization\Controller;

use Apigee\Edge\Api\Monetization\Entity\DeveloperReportDefinition;
use Apigee\Edge\ClientInterface;
use Apigee\Edge\Serializer\EntitySerializerInterface;
use Psr\Http\Message\UriInterface;

class DeveloperReportDefinitionController extends LegalEntityReportDefinitionController implements DeveloperReportDefinitionControllerInterface
{
/**
* @var string
*/
protected $developerId;

/**
* DeveloperReportDefinitionController constructor.
*
* @param string $developerId
* @param string $organization
* @param \Apigee\Edge\ClientInterface $client
* @param \Apigee\Edge\Api\Monetization\Controller\ReportDefinitionControllerInterface|null $reportDefinitionController
* @param \Apigee\Edge\Serializer\EntitySerializerInterface|null $entitySerializer
*/
public function __construct(string $developerId, string $organization, ClientInterface $client, ?ReportDefinitionControllerInterface $reportDefinitionController = null, ?EntitySerializerInterface $entitySerializer = null)
{
$this->developerId = $developerId;
parent::__construct($organization, $client, $reportDefinitionController, $entitySerializer);
}

/**
* @inheritdoc
*/
protected function getBaseEndpointUri(): UriInterface
{
return $this->client->getUriFactory()->createUri("/mint/organizations/{$this->organization}/developers/{$this->developerId}/report-definitions");
}

/**
* @inheritdoc
*/
protected function getEntityClass(): string
{
return DeveloperReportDefinition::class;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
<?php

/*
* Copyright 2018 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\Monetization\Controller;

interface DeveloperReportDefinitionControllerInterface extends ReportDefinitionControllerInterface
{
}
40 changes: 40 additions & 0 deletions src/Api/Monetization/Controller/FilteredReportDefinitionsTrait.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* Copyright 2018 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\Monetization\Controller;

use Apigee\Edge\Controller\BaseEndpointAwareControllerTrait;

trait FilteredReportDefinitionsTrait
{
use BaseEndpointAwareControllerTrait;
use PaginatedListingHelperTrait;

/**
* @inheritdoc
*/
public function getFilteredEntities(int $limit = null, int $page = 1, string $sort = null): array
{
$queryParams = [];
if (null !== $sort) {
$queryParams = ['sort' => $sort];
}

return $this->listEntitiesInRange($this->getBaseEndpointUri()->withQuery(http_build_query($queryParams)), $limit, $page);
}
}
Loading

0 comments on commit 02dd82e

Please sign in to comment.