Skip to content

Commit

Permalink
support of recommendationCategory
Browse files Browse the repository at this point in the history
  • Loading branch information
Marco committed Jan 3, 2017
1 parent 4cab1c4 commit 49231d3
Show file tree
Hide file tree
Showing 3 changed files with 71 additions and 4 deletions.
1 change: 1 addition & 0 deletions composer.json
Original file line number Diff line number Diff line change
@@ -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"
Expand Down
33 changes: 30 additions & 3 deletions src/BreinRecommendation.php
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,11 @@ class BreinRecommendation extends BreinBase
*/
private $numberOfRecommendations = 3;

/**
* @var String contains optional category
*/
private $category;

/**
* @return array
*/
Expand All @@ -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;
}
Expand Down Expand Up @@ -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
*/
Expand Down
41 changes: 40 additions & 1 deletion tests/BreinRecommendationTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 -";
Expand Down Expand Up @@ -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("[email protected]");

// 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()
{
Expand Down

0 comments on commit 49231d3

Please sign in to comment.