Skip to content

Commit 55a9b28

Browse files
committed
Support optional parameter serviceName
1 parent b617806 commit 55a9b28

File tree

2 files changed

+12
-5
lines changed

2 files changed

+12
-5
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ or
1717
```
1818
{
1919
"require": {
20-
"recombee/php-api-client": "^2.1.0"
20+
"recombee/php-api-client": "^2.1.1"
2121
}
2222
}
2323
```

src/RecommApi/Client.php

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -48,8 +48,17 @@ public function __construct($account, $token, $protocol = 'http', $options= arra
4848
if(getenv("RAPI_URI") !== false)
4949
$this->base_uri = getenv("RAPI_URI");
5050
$this->options = $options;
51+
$this->user_agent = $this->getUserAgent();
5152
}
5253

54+
protected function getUserAgent() {
55+
$user_agent = 'recombee-php-api-client/2.1.1';
56+
if (isset($this->options['serviceName']))
57+
$user_agent .= ' '.($this->options['serviceName']);
58+
return $user_agent;
59+
}
60+
61+
5362
/**
5463
* Send a request to the Recombee API
5564
* @param Requests\Request $request Request that will be sent
@@ -94,9 +103,7 @@ public function send(Requests\Request $request) {
94103
catch(\Requests_Exception $e)
95104
{
96105
if(strpos($e->getMessage(), 'cURL error 28') !== false) throw new ApiTimeoutException($request);
97-
if((strpos($e->getMessage(), 'cURL error 7') !== false) && (strpos($e->getMessage(), 'timed out') !== false))
98-
throw new ApiTimeoutException($request);
99-
if(strpos($e->getMessage(), 'fsocket timed out') !== false) throw new ApiTimeoutException($request);
106+
if(strpos($e->getMessage(), 'timed out') !== false) throw new ApiTimeoutException($request);
100107

101108
throw $e;
102109
}
@@ -112,7 +119,7 @@ protected function getOptionalHttpHeaders() {
112119
}
113120

114121
protected function getHttpHeaders() {
115-
return array_merge(array('User-Agent' => 'recombee-php-api-client/2.1.0'), $this->getOptionalHttpHeaders());
122+
return array_merge(array('User-Agent' => $this->user_agent), $this->getOptionalHttpHeaders());
116123
}
117124

118125
protected function getOptionalRequestOptions() {

0 commit comments

Comments
 (0)