Skip to content

Commit

Permalink
Support endpoints for handling search synonyms. Support also guzzle 6…
Browse files Browse the repository at this point in the history
… as HTTP client.
  • Loading branch information
OndraFiedler committed Feb 17, 2021
1 parent a9fcf9c commit 0c2f2b0
Show file tree
Hide file tree
Showing 15 changed files with 504 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ or
```
{
"require": {
"recombee/php-api-client": "^3.1.0"
"recombee/php-api-client": "^3.2.0"
}
}
```
Expand Down
2 changes: 1 addition & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
],
"require": {
"php": ">=7.2.0",
"guzzlehttp/guzzle": "^7.2.0"
"guzzlehttp/guzzle": "^6.0.0 || ^7.0.0"
},
"require-dev": {
"phpunit/phpunit": "^9.2.2",
Expand Down
2 changes: 1 addition & 1 deletion src/RecommApi/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -58,7 +58,7 @@ public function __construct($account, $token, $protocol = 'https', $options= arr
}

protected function getUserAgent() {
$user_agent = 'recombee-php-api-client/3.1.0';
$user_agent = 'recombee-php-api-client/3.2.0';
if (isset($this->options['serviceName']))
$user_agent .= ' '.($this->options['serviceName']);
return $user_agent;
Expand Down
104 changes: 104 additions & 0 deletions src/RecommApi/Requests/AddSearchSynonym.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,104 @@
<?php
/*
This file is auto-generated, do not edit
*/

/**
* AddSearchSynonym request
*/
namespace Recombee\RecommApi\Requests;
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;

/**
* Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
* When the `term` is used in the search query, the `synonym` is also used for the full-text search.
* Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
* An example of a synonym can be `science fiction` for the term `sci-fi`.
*/
class AddSearchSynonym extends Request {

/**
* @var string $term A word to which the `synonym` is specified.
*/
protected $term;
/**
* @var string $synonym A word that should be considered equal to the `term` by the full-text search engine.
*/
protected $synonym;
/**
* @var bool $one_way If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
* Default: `false`.
*/
protected $one_way;
/**
* @var array Array containing values of optional parameters
*/
protected $optional;

/**
* Construct the request
* @param string $term A word to which the `synonym` is specified.
* @param string $synonym A word that should be considered equal to the `term` by the full-text search engine.
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
* - Allowed parameters:
* - *oneWay*
* - Type: bool
* - Description: If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
* Default: `false`.
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
*/
public function __construct($term, $synonym, $optional = array()) {
$this->term = $term;
$this->synonym = $synonym;
$this->one_way = isset($optional['oneWay']) ? $optional['oneWay'] : null;
$this->optional = $optional;

$existing_optional = array('oneWay');
foreach ($this->optional as $key => $value) {
if (!in_array($key, $existing_optional))
throw new UnknownOptionalParameterException($key);
}
$this->timeout = 10000;
$this->ensure_https = false;
}

/**
* Get used HTTP method
* @return static Used HTTP method
*/
public function getMethod() {
return Request::HTTP_POST;
}

/**
* Get URI to the endpoint
* @return string URI to the endpoint
*/
public function getPath() {
return "/{databaseId}/synonyms/items/";
}

/**
* Get query parameters
* @return array Values of query parameters (name of parameter => value of the parameter)
*/
public function getQueryParameters() {
$params = array();
return $params;
}

/**
* Get body parameters
* @return array Values of body parameters (name of parameter => value of the parameter)
*/
public function getBodyParameters() {
$p = array();
$p['term'] = $this->term;
$p['synonym'] = $this->synonym;
if (isset($this->optional['oneWay']))
$p['oneWay'] = $this-> optional['oneWay'];
return $p;
}

}
?>
61 changes: 61 additions & 0 deletions src/RecommApi/Requests/DeleteAllSearchSynonyms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php
/*
This file is auto-generated, do not edit
*/

/**
* DeleteAllSearchSynonyms request
*/
namespace Recombee\RecommApi\Requests;
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;

/**
* Deletes all synonyms defined in the database.
*/
class DeleteAllSearchSynonyms extends Request {


/**
* Construct the request
*/
public function __construct() {
$this->timeout = 10000;
$this->ensure_https = false;
}

/**
* Get used HTTP method
* @return static Used HTTP method
*/
public function getMethod() {
return Request::HTTP_DELETE;
}

/**
* Get URI to the endpoint
* @return string URI to the endpoint
*/
public function getPath() {
return "/{databaseId}/synonyms/items/";
}

/**
* Get query parameters
* @return array Values of query parameters (name of parameter => value of the parameter)
*/
public function getQueryParameters() {
$params = array();
return $params;
}

/**
* Get body parameters
* @return array Values of body parameters (name of parameter => value of the parameter)
*/
public function getBodyParameters() {
$p = array();
return $p;
}

}
?>
67 changes: 67 additions & 0 deletions src/RecommApi/Requests/DeleteSearchSynonym.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,67 @@
<?php
/*
This file is auto-generated, do not edit
*/

/**
* DeleteSearchSynonym request
*/
namespace Recombee\RecommApi\Requests;
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;

/**
* Deletes synonym of given `id` and this synonym is no longer taken into account in the [Search items](https://docs.recombee.com/api.html#search-items).
*/
class DeleteSearchSynonym extends Request {

/**
* @var string $id ID of the synonym that should be deleted.
*/
protected $id;

/**
* Construct the request
* @param string $id ID of the synonym that should be deleted.
*/
public function __construct($id) {
$this->id = $id;
$this->timeout = 10000;
$this->ensure_https = false;
}

/**
* Get used HTTP method
* @return static Used HTTP method
*/
public function getMethod() {
return Request::HTTP_DELETE;
}

/**
* Get URI to the endpoint
* @return string URI to the endpoint
*/
public function getPath() {
return "/{databaseId}/synonyms/items/{$this->id}";
}

/**
* Get query parameters
* @return array Values of query parameters (name of parameter => value of the parameter)
*/
public function getQueryParameters() {
$params = array();
return $params;
}

/**
* Get body parameters
* @return array Values of body parameters (name of parameter => value of the parameter)
*/
public function getBodyParameters() {
$p = array();
return $p;
}

}
?>
95 changes: 95 additions & 0 deletions src/RecommApi/Requests/ListSearchSynonyms.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
<?php
/*
This file is auto-generated, do not edit
*/

/**
* ListSearchSynonyms request
*/
namespace Recombee\RecommApi\Requests;
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;

/**
* Gives the list of synonyms defined in the database.
*/
class ListSearchSynonyms extends Request {

/**
* @var int $count The number of synonyms to be listed.
*/
protected $count;
/**
* @var int $offset Specifies the number of synonyms to skip (ordered by `term`).
*/
protected $offset;
/**
* @var array Array containing values of optional parameters
*/
protected $optional;

/**
* Construct the request
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
* - Allowed parameters:
* - *count*
* - Type: int
* - Description: The number of synonyms to be listed.
* - *offset*
* - Type: int
* - Description: Specifies the number of synonyms to skip (ordered by `term`).
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
*/
public function __construct($optional = array()) {
$this->count = isset($optional['count']) ? $optional['count'] : null;
$this->offset = isset($optional['offset']) ? $optional['offset'] : null;
$this->optional = $optional;

$existing_optional = array('count','offset');
foreach ($this->optional as $key => $value) {
if (!in_array($key, $existing_optional))
throw new UnknownOptionalParameterException($key);
}
$this->timeout = 100000;
$this->ensure_https = false;
}

/**
* Get used HTTP method
* @return static Used HTTP method
*/
public function getMethod() {
return Request::HTTP_GET;
}

/**
* Get URI to the endpoint
* @return string URI to the endpoint
*/
public function getPath() {
return "/{databaseId}/synonyms/items/";
}

/**
* Get query parameters
* @return array Values of query parameters (name of parameter => value of the parameter)
*/
public function getQueryParameters() {
$params = array();
if (isset($this->optional['count']))
$params['count'] = $this->optional['count'];
if (isset($this->optional['offset']))
$params['offset'] = $this->optional['offset'];
return $params;
}

/**
* Get body parameters
* @return array Values of body parameters (name of parameter => value of the parameter)
*/
public function getBodyParameters() {
$p = array();
return $p;
}

}
?>
11 changes: 11 additions & 0 deletions tests/AddSearchSynonymTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
<?php
namespace Recombee\RecommApi\Tests;
use Recombee\RecommApi\Requests\AddSearchSynonym;

class AddSearchSynonymTest extends AddSearchSynonymTestCase {

protected function createRequest($term, $synonym, $optional=array()) {
return new AddSearchSynonym($term, $synonym, $optional);
}
}
?>
Loading

0 comments on commit 0c2f2b0

Please sign in to comment.