From baef3e7561a61059500922936e3c3669be9e233b Mon Sep 17 00:00:00 2001 From: Chris Schalenborgh Date: Wed, 12 Apr 2017 13:36:49 +0200 Subject: [PATCH] remove api endpoints to get all reviews and all review descriptions --- lib/ZalandoPHP/Operations/ArticlesReviews.php | 6 +- .../Operations/ArticlesReviewsSummaries.php | 85 ------------------- lib/ZalandoPHP/Operations/Reviews.php | 4 + .../Operations/ReviewsSummaries.php | 84 ------------------ .../Articles/getArticlesReviewsSummaries.php | 47 ---------- samples/Reviews/getReviews.php | 5 +- samples/Reviews/getReviewsSummaries.php | 50 ----------- .../Types/ArticlesReviewsSummariesTest.php | 33 ------- .../Operations/Types/ArticlesReviewsTest.php | 12 ++- .../Operations/Types/ReviewsSummariesTest.php | 33 ------- .../Test/Operations/Types/ReviewsTest.php | 13 ++- 11 files changed, 33 insertions(+), 339 deletions(-) delete mode 100644 lib/ZalandoPHP/Operations/ArticlesReviewsSummaries.php delete mode 100644 lib/ZalandoPHP/Operations/ReviewsSummaries.php delete mode 100644 samples/Articles/getArticlesReviewsSummaries.php delete mode 100644 samples/Reviews/getReviewsSummaries.php delete mode 100644 tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsSummariesTest.php delete mode 100644 tests/ZalandoPHP/Test/Operations/Types/ReviewsSummariesTest.php diff --git a/lib/ZalandoPHP/Operations/ArticlesReviews.php b/lib/ZalandoPHP/Operations/ArticlesReviews.php index 36483a5..06c084b 100644 --- a/lib/ZalandoPHP/Operations/ArticlesReviews.php +++ b/lib/ZalandoPHP/Operations/ArticlesReviews.php @@ -26,10 +26,14 @@ class ArticlesReviews extends AbstractOperation { - protected $endpoint = 'article-reviews?articleId={articleId}'; + protected $endpoint = 'articles/{articleId}/reviews'; public function __construct($articleId = '') { + if (strlen($articleId) == 0) { + throw new \InvalidArgumentException('articleId is empty.'); + } + $this->endpoint = str_replace('{articleId}', $articleId, $this->endpoint); } diff --git a/lib/ZalandoPHP/Operations/ArticlesReviewsSummaries.php b/lib/ZalandoPHP/Operations/ArticlesReviewsSummaries.php deleted file mode 100644 index 48c990c..0000000 --- a/lib/ZalandoPHP/Operations/ArticlesReviewsSummaries.php +++ /dev/null @@ -1,85 +0,0 @@ - - * - * 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 - * - * http://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 ZalandoPHP\Operations; - -/** - * ArticlesReviewsSummaries - * - * @see https://github.com/zalando/shop-api-documentation/wiki/Article-reviews - * @author Chris Schalenborgh - */ -class ArticlesReviewsSummaries extends AbstractOperation -{ - - protected $endpoint = 'article-reviews-summaries?articleId={articleId}'; - - public function __construct($articleId = '') - { - $this->endpoint = str_replace('{articleId}', $articleId, $this->endpoint); - } - - - - - /** - * Sets the resultpage to a specified value - * Allows to browse resultsets which have more than one page - * - * @param integer $page - * - * @return \ZalandoPHP\Operations\ArticlesReviewsSummaries - */ - public function setPage($page) - { - if (false === is_numeric($page) || $page < 1) { - throw new \InvalidArgumentException( - sprintf( - '%s is an invalid page value. It has to be numeric and positive', - $page - ) - ); - } - - $this->filter['page'] = $page; - - return $this; - } - - /** - * Sets the size of te resultset to a specified value - * - * @param integer $pageSize - * - * @return \ZalandoPHP\Operations\ArticlesReviewsSummaries - */ - public function setPageSize($pageSize) - { - if (false === is_numeric($pageSize) || $pageSize < 1 || $pageSize > 200) { - throw new \InvalidArgumentException( - sprintf( - '%s is an invalid page value. It has to be numeric, positive and between than 1 and 200', - $pageSize - ) - ); - } - - $this->filter['pageSize'] = $pageSize; - - return $this; - } -} diff --git a/lib/ZalandoPHP/Operations/Reviews.php b/lib/ZalandoPHP/Operations/Reviews.php index dcd6391..5d499d8 100644 --- a/lib/ZalandoPHP/Operations/Reviews.php +++ b/lib/ZalandoPHP/Operations/Reviews.php @@ -30,6 +30,10 @@ class Reviews extends AbstractOperation public function __construct($reviewId = '') { + if (strlen($reviewId) == 0) { + throw new \InvalidArgumentException('reviewId is empty.'); + } + $this->endpoint = str_replace('{reviewId}', $reviewId, $this->endpoint); } diff --git a/lib/ZalandoPHP/Operations/ReviewsSummaries.php b/lib/ZalandoPHP/Operations/ReviewsSummaries.php deleted file mode 100644 index de334af..0000000 --- a/lib/ZalandoPHP/Operations/ReviewsSummaries.php +++ /dev/null @@ -1,84 +0,0 @@ - - * - * 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 - * - * http://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 ZalandoPHP\Operations; - -/** - * ReviewsSummaries - * - * @see https://github.com/zalando/shop-api-documentation/wiki/Article-reviews - * @author Chris Schalenborgh - */ -class ReviewsSummaries extends AbstractOperation -{ - - protected $endpoint = 'article-reviews-summaries/{articleModelId}'; - - public function __construct($articleModelId = '') - { - $this->endpoint = str_replace('{articleModelId}', $articleModelId, $this->endpoint); - } - - - - /** - * Sets the resultpage to a specified value - * Allows to browse resultsets which have more than one page - * - * @param integer $page - * - * @return \ZalandoPHP\Operations\ReviewsSummaries - */ - public function setPage($page) - { - if (false === is_numeric($page) || $page < 1) { - throw new \InvalidArgumentException( - sprintf( - '%s is an invalid page value. It has to be numeric and positive', - $page - ) - ); - } - - $this->filter['page'] = $page; - - return $this; - } - - /** - * Sets the size of te resultset to a specified value - * - * @param integer $pageSize - * - * @return \ZalandoPHP\Operations\ReviewsSummaries - */ - public function setPageSize($pageSize) - { - if (false === is_numeric($pageSize) || $pageSize < 1 || $pageSize > 200) { - throw new \InvalidArgumentException( - sprintf( - '%s is an invalid page value. It has to be numeric, positive and between than 1 and 200', - $pageSize - ) - ); - } - - $this->filter['pageSize'] = $pageSize; - - return $this; - } -} diff --git a/samples/Articles/getArticlesReviewsSummaries.php b/samples/Articles/getArticlesReviewsSummaries.php deleted file mode 100644 index c0ad171..0000000 --- a/samples/Articles/getArticlesReviewsSummaries.php +++ /dev/null @@ -1,47 +0,0 @@ - -* -* 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 -* -* http://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. -*/ - - -require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'bootstrap.php'); - - -use ZalandoPHP\ZalandoPHP; -use ZalandoPHP\Configuration\GenericConfiguration; -use ZalandoPHP\Operations\ArticlesReviewsSummaries; - -$conf = new GenericConfiguration(); - -try { - $conf -// ->setLocale('nl-be') - ->setLocale('de-DE') - ->setClientName('zalando-php-wrapper') - ->setResponseType('array'); - -} catch (\Exception $e) { - echo $e->getMessage(); -} -$zalandoPHP = new ZalandoPHP($conf); - - -$reviews = new ArticlesReviewsSummaries('L8381D00F-G11'); -$formattedResponse = $zalandoPHP->runOperation($reviews); - -echo '
';
-print_r($formattedResponse);
-echo '
'; \ No newline at end of file diff --git a/samples/Reviews/getReviews.php b/samples/Reviews/getReviews.php index 780ef20..079258d 100644 --- a/samples/Reviews/getReviews.php +++ b/samples/Reviews/getReviews.php @@ -40,10 +40,7 @@ // return one -//$reviews = new Reviews('4385857-AN651H06H-Q11'); - -// return all -$reviews = new Reviews(); +$reviews = new Reviews('4385857-AN651H06H-Q11'); $formattedResponse = $zalandoPHP->runOperation($reviews); echo '
';
diff --git a/samples/Reviews/getReviewsSummaries.php b/samples/Reviews/getReviewsSummaries.php
deleted file mode 100644
index 16799a8..0000000
--- a/samples/Reviews/getReviewsSummaries.php
+++ /dev/null
@@ -1,50 +0,0 @@
-
-*
-* 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
-*
-* http://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.
-*/
-
-
-require_once(dirname(__FILE__).DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'..'.DIRECTORY_SEPARATOR.'tests'.DIRECTORY_SEPARATOR.'bootstrap.php');
-
-
-use ZalandoPHP\ZalandoPHP;
-use ZalandoPHP\Configuration\GenericConfiguration;
-use ZalandoPHP\Operations\ReviewsSummaries;
-
-$conf = new GenericConfiguration();
-
-try {
-    $conf
-//        ->setLocale('nl-be')
-        ->setLocale('de-DE')
-        ->setClientName('zalando-php-wrapper')
-        ->setResponseType('array');
-
-} catch (\Exception $e) {
-    echo $e->getMessage();
-}
-$zalandoPHP = new ZalandoPHP($conf);
-
-// return all
-//$reviews = new ReviewsSummaries();
-
-// return one
-$reviews = new ReviewsSummaries('AD542B0L9');
-$formattedResponse = $zalandoPHP->runOperation($reviews);
-
-echo '
';
-print_r($formattedResponse);
-echo '
'; \ No newline at end of file diff --git a/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsSummariesTest.php b/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsSummariesTest.php deleted file mode 100644 index 94e16df..0000000 --- a/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsSummariesTest.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * 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 - * - * http://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 ZalandoPHP\Test\Operations\Types; - -use ZalandoPHP\Operations\ArticlesReviewsSummaries; - -class ArticlesReviewsSummariesTest extends \PHPUnit_Framework_TestCase -{ - - public function testValidPage() - { - $reviews = new ArticlesReviewsSummaries(); - $reviews->setPage(1); - - $this->assertEquals(1, $reviews->getPage()); - } - -} diff --git a/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsTest.php b/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsTest.php index d5b607f..de19dba 100644 --- a/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsTest.php +++ b/tests/ZalandoPHP/Test/Operations/Types/ArticlesReviewsTest.php @@ -24,10 +24,20 @@ class ArticlesReviewsTest extends \PHPUnit_Framework_TestCase public function testValidPage() { - $reviews = new ArticlesReviews(); + $reviews = new ArticlesReviews(123); $reviews->setPage(1); $this->assertEquals(1, $reviews->getPage()); } + /** + * @expectedException Exception + */ + public function testInvalidArticleId() + { + $operation = new ArticlesReviews(); + $zalando = new ZalandoPHP(); + + $zalando->runOperation($operation); + } } diff --git a/tests/ZalandoPHP/Test/Operations/Types/ReviewsSummariesTest.php b/tests/ZalandoPHP/Test/Operations/Types/ReviewsSummariesTest.php deleted file mode 100644 index 0f17fa2..0000000 --- a/tests/ZalandoPHP/Test/Operations/Types/ReviewsSummariesTest.php +++ /dev/null @@ -1,33 +0,0 @@ - - * - * 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 - * - * http://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 ZalandoPHP\Test\Operations\Types; - -use ZalandoPHP\Operations\ReviewsSummaries; - -class ReviewsSummariesTest extends \PHPUnit_Framework_TestCase -{ - - public function testValidPage() - { - $reviews = new ReviewsSummaries(); - $reviews->setPage(1); - - $this->assertEquals(1, $reviews->getPage()); - } - -} diff --git a/tests/ZalandoPHP/Test/Operations/Types/ReviewsTest.php b/tests/ZalandoPHP/Test/Operations/Types/ReviewsTest.php index 247db0e..c7a8c53 100644 --- a/tests/ZalandoPHP/Test/Operations/Types/ReviewsTest.php +++ b/tests/ZalandoPHP/Test/Operations/Types/ReviewsTest.php @@ -24,10 +24,21 @@ class ReviewsTest extends \PHPUnit_Framework_TestCase public function testValidPage() { - $reviews = new Reviews(); + $reviews = new Reviews(123); $reviews->setPage(1); $this->assertEquals(1, $reviews->getPage()); } + /** + * @expectedException Exception + */ + public function testInvalidReviewId() + { + $operation = new Reviews(); + $zalando = new ZalandoPHP(); + + $zalando->runOperation($operation); + } + }