Skip to content

Commit f1e1543

Browse files
author
Artur (Seti) Łabudziński
committed
User Agent for configuration
1 parent 51a9e2c commit f1e1543

File tree

3 files changed

+20
-1
lines changed

3 files changed

+20
-1
lines changed

src/Client.php

+4-1
Original file line numberDiff line numberDiff line change
@@ -17,6 +17,8 @@
1717
*/
1818
class Client
1919
{
20+
static protected $UserAgent = 'Seti\'s JiraApi Rest Client v1.5.*';
21+
2022
static protected $isJIRAUtf8 = true;
2123

2224
static protected $jMapper = null;
@@ -191,6 +193,7 @@ public function exec($context, $post_data = null, $custom_request = null, $tries
191193
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, $this->getConfiguration()->isCurlOptSslVerifyHost());
192194
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, $this->getConfiguration()->isCurlOptSslVerifyPeer());
193195
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
196+
curl_setopt($ch, CURLOPT_USERAGENT, self::$UserAgent . ($this->getConfiguration()->getUserAgent() ? ' []' : ''));
194197
curl_setopt($ch, CURLOPT_HTTPHEADER,
195198
array('Accept: */*', 'Content-Type: application/json'));
196199
curl_setopt($ch, CURLOPT_VERBOSE, $this->getConfiguration()->isCurlOptVerbose());
@@ -208,7 +211,7 @@ public function exec($context, $post_data = null, $custom_request = null, $tries
208211
$url .= '&startAt='.$post_data->startAt;
209212
$url .= '&maxResults='.$post_data->maxResults;
210213
$url .= '&expand='.$post_data->expand;
211-
if (isset($post_data->fields) && !empty($post_data->fields)) $url .= '&fields='.$post_data -> fields;
214+
if (isset($post_data->fields) && !empty($post_data->fields)) $url .= '&fields='.(is_array($post_data -> fields) ? implode(',', $post_data->fields) : $post_data->fields);
212215
$post_data = null;
213216
curl_setopt($ch, CURLOPT_POST, false);
214217
curl_setopt($ch, CURLOPT_URL, $url);

src/Configuration/AbstractConfiguration.php

+15
Original file line numberDiff line numberDiff line change
@@ -68,6 +68,21 @@ abstract class AbstractConfiguration implements \Jira\Api\Configuration\Configur
6868

6969
protected $utf8support = false;
7070

71+
/**
72+
* Name visible in userAgent (additional data apart from Library version).
73+
*
74+
* @var string
75+
*/
76+
protected $userAgent = '';
77+
78+
/**
79+
* @return string
80+
*/
81+
public function getUserAgent()
82+
{
83+
return $this->userAgent;
84+
}
85+
7186
/**
7287
* @return string
7388
*/

src/Configuration/DotEnvConfiguration.php

+1
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ public function __construct($path = '.')
3434
$this->curlOptSslVerifyHost = $this->env('CURLOPT_SSL_VERIFYHOST', false);
3535
$this->curlOptSslVerifyPeer = $this->env('CURLOPT_SSL_VERIFYPEER', false);
3636
$this->curlOptVerbose = $this->env('CURLOPT_VERBOSE', false);
37+
$this->userAgent = $this->env('USER_AGENT', '');
3738
}
3839

3940
/**

0 commit comments

Comments
 (0)