Skip to content

Commit 0c2f2b0

Browse files
committed
Support endpoints for handling search synonyms. Support also guzzle 6 as HTTP client.
1 parent a9fcf9c commit 0c2f2b0

15 files changed

+504
-3
lines changed

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^3.1.0"
20+
"recombee/php-api-client": "^3.2.0"
2121
}
2222
}
2323
```

composer.json

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
],
1212
"require": {
1313
"php": ">=7.2.0",
14-
"guzzlehttp/guzzle": "^7.2.0"
14+
"guzzlehttp/guzzle": "^6.0.0 || ^7.0.0"
1515
},
1616
"require-dev": {
1717
"phpunit/phpunit": "^9.2.2",

src/RecommApi/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ public function __construct($account, $token, $protocol = 'https', $options= arr
5858
}
5959

6060
protected function getUserAgent() {
61-
$user_agent = 'recombee-php-api-client/3.1.0';
61+
$user_agent = 'recombee-php-api-client/3.2.0';
6262
if (isset($this->options['serviceName']))
6363
$user_agent .= ' '.($this->options['serviceName']);
6464
return $user_agent;
+104
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* AddSearchSynonym request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* Adds a new synonym for the [Search items](https://docs.recombee.com/api.html#search-items).
14+
* When the `term` is used in the search query, the `synonym` is also used for the full-text search.
15+
* Unless `oneWay=true`, it works also in the opposite way (`synonym` -> `term`).
16+
* An example of a synonym can be `science fiction` for the term `sci-fi`.
17+
*/
18+
class AddSearchSynonym extends Request {
19+
20+
/**
21+
* @var string $term A word to which the `synonym` is specified.
22+
*/
23+
protected $term;
24+
/**
25+
* @var string $synonym A word that should be considered equal to the `term` by the full-text search engine.
26+
*/
27+
protected $synonym;
28+
/**
29+
* @var bool $one_way If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
30+
* Default: `false`.
31+
*/
32+
protected $one_way;
33+
/**
34+
* @var array Array containing values of optional parameters
35+
*/
36+
protected $optional;
37+
38+
/**
39+
* Construct the request
40+
* @param string $term A word to which the `synonym` is specified.
41+
* @param string $synonym A word that should be considered equal to the `term` by the full-text search engine.
42+
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
43+
* - Allowed parameters:
44+
* - *oneWay*
45+
* - Type: bool
46+
* - Description: If set to `true`, only `term` -> `synonym` is considered. If set to `false`, also `synonym` -> `term` works.
47+
* Default: `false`.
48+
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
49+
*/
50+
public function __construct($term, $synonym, $optional = array()) {
51+
$this->term = $term;
52+
$this->synonym = $synonym;
53+
$this->one_way = isset($optional['oneWay']) ? $optional['oneWay'] : null;
54+
$this->optional = $optional;
55+
56+
$existing_optional = array('oneWay');
57+
foreach ($this->optional as $key => $value) {
58+
if (!in_array($key, $existing_optional))
59+
throw new UnknownOptionalParameterException($key);
60+
}
61+
$this->timeout = 10000;
62+
$this->ensure_https = false;
63+
}
64+
65+
/**
66+
* Get used HTTP method
67+
* @return static Used HTTP method
68+
*/
69+
public function getMethod() {
70+
return Request::HTTP_POST;
71+
}
72+
73+
/**
74+
* Get URI to the endpoint
75+
* @return string URI to the endpoint
76+
*/
77+
public function getPath() {
78+
return "/{databaseId}/synonyms/items/";
79+
}
80+
81+
/**
82+
* Get query parameters
83+
* @return array Values of query parameters (name of parameter => value of the parameter)
84+
*/
85+
public function getQueryParameters() {
86+
$params = array();
87+
return $params;
88+
}
89+
90+
/**
91+
* Get body parameters
92+
* @return array Values of body parameters (name of parameter => value of the parameter)
93+
*/
94+
public function getBodyParameters() {
95+
$p = array();
96+
$p['term'] = $this->term;
97+
$p['synonym'] = $this->synonym;
98+
if (isset($this->optional['oneWay']))
99+
$p['oneWay'] = $this-> optional['oneWay'];
100+
return $p;
101+
}
102+
103+
}
104+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,61 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* DeleteAllSearchSynonyms request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* Deletes all synonyms defined in the database.
14+
*/
15+
class DeleteAllSearchSynonyms extends Request {
16+
17+
18+
/**
19+
* Construct the request
20+
*/
21+
public function __construct() {
22+
$this->timeout = 10000;
23+
$this->ensure_https = false;
24+
}
25+
26+
/**
27+
* Get used HTTP method
28+
* @return static Used HTTP method
29+
*/
30+
public function getMethod() {
31+
return Request::HTTP_DELETE;
32+
}
33+
34+
/**
35+
* Get URI to the endpoint
36+
* @return string URI to the endpoint
37+
*/
38+
public function getPath() {
39+
return "/{databaseId}/synonyms/items/";
40+
}
41+
42+
/**
43+
* Get query parameters
44+
* @return array Values of query parameters (name of parameter => value of the parameter)
45+
*/
46+
public function getQueryParameters() {
47+
$params = array();
48+
return $params;
49+
}
50+
51+
/**
52+
* Get body parameters
53+
* @return array Values of body parameters (name of parameter => value of the parameter)
54+
*/
55+
public function getBodyParameters() {
56+
$p = array();
57+
return $p;
58+
}
59+
60+
}
61+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* DeleteSearchSynonym request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* 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).
14+
*/
15+
class DeleteSearchSynonym extends Request {
16+
17+
/**
18+
* @var string $id ID of the synonym that should be deleted.
19+
*/
20+
protected $id;
21+
22+
/**
23+
* Construct the request
24+
* @param string $id ID of the synonym that should be deleted.
25+
*/
26+
public function __construct($id) {
27+
$this->id = $id;
28+
$this->timeout = 10000;
29+
$this->ensure_https = false;
30+
}
31+
32+
/**
33+
* Get used HTTP method
34+
* @return static Used HTTP method
35+
*/
36+
public function getMethod() {
37+
return Request::HTTP_DELETE;
38+
}
39+
40+
/**
41+
* Get URI to the endpoint
42+
* @return string URI to the endpoint
43+
*/
44+
public function getPath() {
45+
return "/{databaseId}/synonyms/items/{$this->id}";
46+
}
47+
48+
/**
49+
* Get query parameters
50+
* @return array Values of query parameters (name of parameter => value of the parameter)
51+
*/
52+
public function getQueryParameters() {
53+
$params = array();
54+
return $params;
55+
}
56+
57+
/**
58+
* Get body parameters
59+
* @return array Values of body parameters (name of parameter => value of the parameter)
60+
*/
61+
public function getBodyParameters() {
62+
$p = array();
63+
return $p;
64+
}
65+
66+
}
67+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,95 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* ListSearchSynonyms request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* Gives the list of synonyms defined in the database.
14+
*/
15+
class ListSearchSynonyms extends Request {
16+
17+
/**
18+
* @var int $count The number of synonyms to be listed.
19+
*/
20+
protected $count;
21+
/**
22+
* @var int $offset Specifies the number of synonyms to skip (ordered by `term`).
23+
*/
24+
protected $offset;
25+
/**
26+
* @var array Array containing values of optional parameters
27+
*/
28+
protected $optional;
29+
30+
/**
31+
* Construct the request
32+
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
33+
* - Allowed parameters:
34+
* - *count*
35+
* - Type: int
36+
* - Description: The number of synonyms to be listed.
37+
* - *offset*
38+
* - Type: int
39+
* - Description: Specifies the number of synonyms to skip (ordered by `term`).
40+
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
41+
*/
42+
public function __construct($optional = array()) {
43+
$this->count = isset($optional['count']) ? $optional['count'] : null;
44+
$this->offset = isset($optional['offset']) ? $optional['offset'] : null;
45+
$this->optional = $optional;
46+
47+
$existing_optional = array('count','offset');
48+
foreach ($this->optional as $key => $value) {
49+
if (!in_array($key, $existing_optional))
50+
throw new UnknownOptionalParameterException($key);
51+
}
52+
$this->timeout = 100000;
53+
$this->ensure_https = false;
54+
}
55+
56+
/**
57+
* Get used HTTP method
58+
* @return static Used HTTP method
59+
*/
60+
public function getMethod() {
61+
return Request::HTTP_GET;
62+
}
63+
64+
/**
65+
* Get URI to the endpoint
66+
* @return string URI to the endpoint
67+
*/
68+
public function getPath() {
69+
return "/{databaseId}/synonyms/items/";
70+
}
71+
72+
/**
73+
* Get query parameters
74+
* @return array Values of query parameters (name of parameter => value of the parameter)
75+
*/
76+
public function getQueryParameters() {
77+
$params = array();
78+
if (isset($this->optional['count']))
79+
$params['count'] = $this->optional['count'];
80+
if (isset($this->optional['offset']))
81+
$params['offset'] = $this->optional['offset'];
82+
return $params;
83+
}
84+
85+
/**
86+
* Get body parameters
87+
* @return array Values of body parameters (name of parameter => value of the parameter)
88+
*/
89+
public function getBodyParameters() {
90+
$p = array();
91+
return $p;
92+
}
93+
94+
}
95+
?>

tests/AddSearchSynonymTest.php

+11
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
<?php
2+
namespace Recombee\RecommApi\Tests;
3+
use Recombee\RecommApi\Requests\AddSearchSynonym;
4+
5+
class AddSearchSynonymTest extends AddSearchSynonymTestCase {
6+
7+
protected function createRequest($term, $synonym, $optional=array()) {
8+
return new AddSearchSynonym($term, $synonym, $optional);
9+
}
10+
}
11+
?>

0 commit comments

Comments
 (0)