Skip to content

Commit 857d619

Browse files
committed
Added support for view portions
1 parent a085e5c commit 857d619

13 files changed

+536
-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": "^1.4.0"
20+
"recombee/php-api-client": "^1.5.0"
2121
}
2222
}
2323
```

src/RecommApi/Client.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -112,7 +112,7 @@ protected function getOptionalHttpHeaders() {
112112
}
113113

114114
protected function getHttpHeaders() {
115-
return array_merge(array('User-Agent' => 'recombee-php-api-client/1.4.0'), $this->getOptionalHttpHeaders());
115+
return array_merge(array('User-Agent' => 'recombee-php-api-client/1.5.0'), $this->getOptionalHttpHeaders());
116116
}
117117

118118
protected function getOptionalRequestOptions() {
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,100 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* DeleteViewPortion request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* The view portions feature is currently experimental.
14+
* Deletes an existing view portion specified by (`userId`, `itemId`, `sessionId`) from the database.
15+
*/
16+
class DeleteViewPortion extends Request {
17+
18+
/**
19+
* @var string $user_id ID of the user who rated the item.
20+
*/
21+
protected $user_id;
22+
/**
23+
* @var string $item_id ID of the item which was rated.
24+
*/
25+
protected $item_id;
26+
/**
27+
* @var string $session_id Identifier of a session.
28+
*/
29+
protected $session_id;
30+
/**
31+
* @var array Array containing values of optional parameters
32+
*/
33+
protected $optional;
34+
35+
/**
36+
* Construct the request
37+
* @param string $user_id ID of the user who rated the item.
38+
* @param string $item_id ID of the item which was rated.
39+
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
40+
* - Allowed parameters:
41+
* - *sessionId*
42+
* - Type: string
43+
* - Description: Identifier of a session.
44+
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
45+
*/
46+
public function __construct($user_id, $item_id, $optional = array()) {
47+
$this->user_id = $user_id;
48+
$this->item_id = $item_id;
49+
$this->session_id = isset($optional['sessionId']) ? $optional['sessionId'] : null;
50+
$this->optional = $optional;
51+
52+
$existing_optional = array('sessionId');
53+
foreach ($this->optional as $key => $value) {
54+
if (!in_array($key, $existing_optional))
55+
throw new UnknownOptionalParameterException($key);
56+
}
57+
$this->timeout = 1000;
58+
$this->ensure_https = false;
59+
}
60+
61+
/**
62+
* Get used HTTP method
63+
* @return static Used HTTP method
64+
*/
65+
public function getMethod() {
66+
return Request::HTTP_DELETE;
67+
}
68+
69+
/**
70+
* Get URI to the endpoint
71+
* @return string URI to the endpoint
72+
*/
73+
public function getPath() {
74+
return "/{databaseId}/viewportions/";
75+
}
76+
77+
/**
78+
* Get query parameters
79+
* @return array Values of query parameters (name of parameter => value of the parameter)
80+
*/
81+
public function getQueryParameters() {
82+
$params = array();
83+
$params['userId'] = $this->user_id;
84+
$params['itemId'] = $this->item_id;
85+
if (isset($this->optional['sessionId']))
86+
$params['sessionId'] = $this->optional['sessionId'];
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+
return $p;
97+
}
98+
99+
}
100+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* ListItemViewPortions request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* The view portions feature is currently experimental.
14+
* List all the view portions of an item ever submitted by different users.
15+
*/
16+
class ListItemViewPortions extends Request {
17+
18+
/**
19+
* @var string $item_id ID of the item of which the view portions are to be listed.
20+
*/
21+
protected $item_id;
22+
23+
/**
24+
* Construct the request
25+
* @param string $item_id ID of the item of which the view portions are to be listed.
26+
*/
27+
public function __construct($item_id) {
28+
$this->item_id = $item_id;
29+
$this->timeout = 100000;
30+
$this->ensure_https = false;
31+
}
32+
33+
/**
34+
* Get used HTTP method
35+
* @return static Used HTTP method
36+
*/
37+
public function getMethod() {
38+
return Request::HTTP_GET;
39+
}
40+
41+
/**
42+
* Get URI to the endpoint
43+
* @return string URI to the endpoint
44+
*/
45+
public function getPath() {
46+
return "/{databaseId}/items/{$this->item_id}/viewportions/";
47+
}
48+
49+
/**
50+
* Get query parameters
51+
* @return array Values of query parameters (name of parameter => value of the parameter)
52+
*/
53+
public function getQueryParameters() {
54+
$params = array();
55+
return $params;
56+
}
57+
58+
/**
59+
* Get body parameters
60+
* @return array Values of body parameters (name of parameter => value of the parameter)
61+
*/
62+
public function getBodyParameters() {
63+
$p = array();
64+
return $p;
65+
}
66+
67+
}
68+
?>
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,68 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* ListUserViewPortions request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* The view portions feature is currently experimental.
14+
* List all the view portions ever submitted by a given user.
15+
*/
16+
class ListUserViewPortions extends Request {
17+
18+
/**
19+
* @var string $user_id ID of the user whose view portions are to be listed.
20+
*/
21+
protected $user_id;
22+
23+
/**
24+
* Construct the request
25+
* @param string $user_id ID of the user whose view portions are to be listed.
26+
*/
27+
public function __construct($user_id) {
28+
$this->user_id = $user_id;
29+
$this->timeout = 100000;
30+
$this->ensure_https = false;
31+
}
32+
33+
/**
34+
* Get used HTTP method
35+
* @return static Used HTTP method
36+
*/
37+
public function getMethod() {
38+
return Request::HTTP_GET;
39+
}
40+
41+
/**
42+
* Get URI to the endpoint
43+
* @return string URI to the endpoint
44+
*/
45+
public function getPath() {
46+
return "/{databaseId}/users/{$this->user_id}/viewportions/";
47+
}
48+
49+
/**
50+
* Get query parameters
51+
* @return array Values of query parameters (name of parameter => value of the parameter)
52+
*/
53+
public function getQueryParameters() {
54+
$params = array();
55+
return $params;
56+
}
57+
58+
/**
59+
* Get body parameters
60+
* @return array Values of body parameters (name of parameter => value of the parameter)
61+
*/
62+
public function getBodyParameters() {
63+
$p = array();
64+
return $p;
65+
}
66+
67+
}
68+
?>
+128
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,128 @@
1+
<?php
2+
/*
3+
This file is auto-generated, do not edit
4+
*/
5+
6+
/**
7+
* SetViewPortion request
8+
*/
9+
namespace Recombee\RecommApi\Requests;
10+
use Recombee\RecommApi\Exceptions\UnknownOptionalParameterException;
11+
12+
/**
13+
* The view portions feature is currently experimental.
14+
* Sets viewed portion of an item (for example a video or article) by a user (at a session).
15+
* If you send new request with the same (`userId`, `itemId`, `sessionId`), the portion gets updated.
16+
*/
17+
class SetViewPortion extends Request {
18+
19+
/**
20+
* @var string $user_id User who viewed a portion of the item
21+
*/
22+
protected $user_id;
23+
/**
24+
* @var string $item_id Viewed item
25+
*/
26+
protected $item_id;
27+
/**
28+
* @var string $session_id Id of session in which the user viewed the item
29+
*/
30+
protected $session_id;
31+
/**
32+
* @var string|float $timestamp UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
33+
*/
34+
protected $timestamp;
35+
/**
36+
* @var float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ).
37+
*/
38+
protected $portion;
39+
/**
40+
* @var bool $cascade_create Sets whether the given user/item should be created if not present in the database.
41+
*/
42+
protected $cascade_create;
43+
/**
44+
* @var array Array containing values of optional parameters
45+
*/
46+
protected $optional;
47+
48+
/**
49+
* Construct the request
50+
* @param string $user_id User who viewed a portion of the item
51+
* @param string $item_id Viewed item
52+
* @param float $portion Viewed portion of the item (number between 0.0 (viewed nothing) and 1.0 (viewed full item) ).
53+
* @param array $optional Optional parameters given as an array containing pairs name of the parameter => value
54+
* - Allowed parameters:
55+
* - *sessionId*
56+
* - Type: string
57+
* - Description: Id of session in which the user viewed the item
58+
* - *timestamp*
59+
* - Type: string|float
60+
* - Description: UTC timestamp of the rating as ISO8601-1 pattern or UTC epoch time. The default value is the current time.
61+
* - *cascadeCreate*
62+
* - Type: bool
63+
* - Description: Sets whether the given user/item should be created if not present in the database.
64+
* @throws Exceptions\UnknownOptionalParameterException UnknownOptionalParameterException if an unknown optional parameter is given in $optional
65+
*/
66+
public function __construct($user_id, $item_id, $portion, $optional = array()) {
67+
$this->user_id = $user_id;
68+
$this->item_id = $item_id;
69+
$this->portion = $portion;
70+
$this->session_id = isset($optional['sessionId']) ? $optional['sessionId'] : null;
71+
$this->timestamp = isset($optional['timestamp']) ? $optional['timestamp'] : null;
72+
$this->cascade_create = isset($optional['cascadeCreate']) ? $optional['cascadeCreate'] : null;
73+
$this->optional = $optional;
74+
75+
$existing_optional = array('sessionId','timestamp','cascadeCreate');
76+
foreach ($this->optional as $key => $value) {
77+
if (!in_array($key, $existing_optional))
78+
throw new UnknownOptionalParameterException($key);
79+
}
80+
$this->timeout = 1000;
81+
$this->ensure_https = false;
82+
}
83+
84+
/**
85+
* Get used HTTP method
86+
* @return static Used HTTP method
87+
*/
88+
public function getMethod() {
89+
return Request::HTTP_POST;
90+
}
91+
92+
/**
93+
* Get URI to the endpoint
94+
* @return string URI to the endpoint
95+
*/
96+
public function getPath() {
97+
return "/{databaseId}/viewportions/";
98+
}
99+
100+
/**
101+
* Get query parameters
102+
* @return array Values of query parameters (name of parameter => value of the parameter)
103+
*/
104+
public function getQueryParameters() {
105+
$params = array();
106+
return $params;
107+
}
108+
109+
/**
110+
* Get body parameters
111+
* @return array Values of body parameters (name of parameter => value of the parameter)
112+
*/
113+
public function getBodyParameters() {
114+
$p = array();
115+
$p['userId'] = $this->user_id;
116+
$p['itemId'] = $this->item_id;
117+
$p['portion'] = $this->portion;
118+
if (isset($this->optional['sessionId']))
119+
$p['sessionId'] = $this-> optional['sessionId'];
120+
if (isset($this->optional['timestamp']))
121+
$p['timestamp'] = $this-> optional['timestamp'];
122+
if (isset($this->optional['cascadeCreate']))
123+
$p['cascadeCreate'] = $this-> optional['cascadeCreate'];
124+
return $p;
125+
}
126+
127+
}
128+
?>

tests/DeleteViewPortionTest.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\DeleteViewPortion;
4+
5+
class DeleteViewPortionTest extends DeleteViewPortionTestCase {
6+
7+
protected function createRequest($user_id, $item_id, $optional=array()) {
8+
return new DeleteViewPortion($user_id, $item_id, $optional);
9+
}
10+
}
11+
?>

0 commit comments

Comments
 (0)