/** * @param string|NULL|RecommendationEntitiesBatch $users * @param string|NULL|RecommendationEntitiesBatch $items * @param int $count * @param string|NULL $templateId * @param RecommendationTemplateConfiguration|NULL $configuration * @param int|NULL $offset * @return array * @throws InvalidArgumentException when given user id is empty string value * @throws InvalidArgumentException when given item id is empty string value * @throws InvalidArgumentException when given count isn't integer value or is zero or negative * @throws RequestFailedException when request failed for some reason */ public function getRecommendations($users, $items, $count, $templateId = NULL, RecommendationTemplateConfiguration $configuration = NULL, $offset = NULL) { if ($users !== NULL && is_string($users) && $users == '') { throw new InvalidArgumentException("User id can't be empty string value."); } if ($items !== NULL && is_string($items) && $items == '') { throw new InvalidArgumentException("Item id can't be empty string value."); } if (!is_int($count) || $count <= 0) { throw new InvalidArgumentException("Count must be integer value bigger than 0."); } if ($offset !== NULL && (!is_int($offset) || $offset < 0)) { throw new InvalidArgumentException("Offset must be integer value bigger or equal to 0."); } $parameters = [self::MODEL_ID_PARAMETER => self::DEFAULT_MODEL_ID]; $content = RecommendationContentBuilder::construct($users, $items, $count, $templateId, $configuration, $offset); $restriction = new Restriction($parameters, $content); return $this->performPost(self::GET_RECOMMENDATION_URL, $restriction); }
/** * @param string $requestId * @param float $importance * @param string|NULL|RecommendationEntitiesBatch $users * @param string|NULL|RecommendationEntitiesBatch $items * @param int $count * @param string|NULL $templateId * @param RecommendationTemplateConfiguration|NULL $configuration * @param int|NULL $offset * @return $this * @throws InvalidArgumentException when given request id is empty string value * @throws InvalidArgumentException when given user id is empty string value * @throws InvalidArgumentException when given item id is empty string value * @throws InvalidArgumentException when given count isn't integer value or is zero or negative */ private function addRecommendationsRequest($requestId, $importance, $users, $items, $count, $templateId = NULL, RecommendationTemplateConfiguration $configuration = NULL, $offset = NULL) { if ($requestId == '') { throw new InvalidArgumentException("Request id can't be empty string value."); } if ($users !== NULL && is_string($users) && $users == '') { throw new InvalidArgumentException("User id can't be empty string value."); } if ($items !== NULL && is_string($items) && $items == '') { throw new InvalidArgumentException("Item id can't be empty string value."); } if (!is_int($count) || $count <= 0) { throw new InvalidArgumentException("Count must be integer value bigger than 0."); } if ($offset !== NULL && (!is_int($offset) || $offset < 0)) { throw new InvalidArgumentException("Offset must be integer value bigger or equal to 0."); } $request = RecommendationContentBuilder::construct($users, $items, $count, $templateId, $configuration, $offset); $this->recommendations[] = [self::REQUEST_ID_KEY => $requestId, self::IMPORTANCE_KEY => (double) $importance, self::REQUEST_KEY => $request]; return $this; }