From 49231d3e910083e79ba30349d5ee06ce0bb3891e Mon Sep 17 00:00:00 2001 From: Marco Date: Tue, 3 Jan 2017 13:48:48 +0100 Subject: [PATCH] support of recommendationCategory --- composer.json | 1 + src/BreinRecommendation.php | 33 ++++++++++++++++++++++--- tests/BreinRecommendationTest.php | 41 ++++++++++++++++++++++++++++++- 3 files changed, 71 insertions(+), 4 deletions(-) diff --git a/composer.json b/composer.json index b6d9a46..8db247d 100644 --- a/composer.json +++ b/composer.json @@ -1,6 +1,7 @@ { "name": "breinify/brein-engine-api", "description": "A PHP library to exchange data through the API of the Brein Engine.", + "version": "1.0.2", "config": { "platform": { "php": "5.6.17" diff --git a/src/BreinRecommendation.php b/src/BreinRecommendation.php index 70f2feb..b12e189 100644 --- a/src/BreinRecommendation.php +++ b/src/BreinRecommendation.php @@ -13,6 +13,11 @@ class BreinRecommendation extends BreinBase */ private $numberOfRecommendations = 3; + /** + * @var String contains optional category + */ + private $category; + /** * @return array */ @@ -25,12 +30,18 @@ public function data() } $recommendationFields = array(); - $recommendationFields['numRecommendations'] = $this->numberOfRecommendations; + // optional field(s) + if (!empty($this->getCategory())) { + $recommendationFields['recommendationCategory'] = $this->getCategory(); + } + + // mandatory field + $recommendationFields['numRecommendations'] = $this->numberOfRecommendations; $requestData['recommendation'] = $recommendationFields; - // echo("content of recommendation-data is: "); - // echo(print_r($requestData),1); + // echo("\n content of recommendation-data is: \n"); + // echo(print_r($requestData,1)); return $requestData; } @@ -61,6 +72,22 @@ public function setNumberOfRecommendations($number) return $this->numberOfRecommendations = $number; } + /** + * @return String the category + */ + public function getCategory() + { + return $this->category; + } + + /** + * @param String $category + */ + public function setCategory($category) + { + $this->category = $category; + } + /** * @return null|string creates the activity signature */ diff --git a/tests/BreinRecommendationTest.php b/tests/BreinRecommendationTest.php index 15110bb..887da3d 100644 --- a/tests/BreinRecommendationTest.php +++ b/tests/BreinRecommendationTest.php @@ -6,7 +6,6 @@ class BreinRecommendationTest extends PHPUnit_Framework_TestCase { - public static $API_KEY = "- HAS TO BE A VALID KEY -"; public static $API_KEY_WITH_SECRET = "- HAS TO BE A VALID KEY FOR SECRET -"; @@ -52,6 +51,46 @@ public function testRecommendationDataRequest() echo "=========== END TEST ============="; } + /** + * Testcase of recommendation request with category + */ + public function testRecommendationDataRequestWithCategory() + { + echo "\n=========== START TEST =============\n"; + echo "Running testRecommendationDataRequestWithCategory\n"; + + // configuration + $breinify = new Breinify(BreinRecommendationTest::$API_KEY_WITH_SECRET, BreinRecommendationTest::$SECRET); + + // user + $user = new BreinUser; + $user->setEmail("sola@thedog.com"); + + // recommendation + $recommendation = new BreinRecommendation; + $recommendation->setUser($user); + $recommendation->setNumberOfRecommendations(2); + $recommendation->setCategory("some category"); + + // invoke request + $recResult = $breinify->recommendation($recommendation); + + // result + if ($recResult->getStatus() == 200) { + echo "\n Status from BreinRecommendationResult is: " . $recResult->getStatus(); + echo "\n Message from BreinRecommendationResult is: " . $recResult->getMessage(); + + // loop over results + foreach ($recResult->getResults() as $value) { + echo "\n Result is: " . print_r($value, true); + } + + } + + echo "\n"; + echo "=========== END TEST ============="; + } + public function testRecommendationDataRequestComprehensive() {