Skip to content

Commit

Permalink
Merge pull request #41 from apivideo/user-agent-extension
Browse files Browse the repository at this point in the history
feat(nodejs): add applicationName parameter
  • Loading branch information
bot-api-video authored Jan 25, 2022
2 parents 05ff9c5 + 5c560b7 commit 2e4541f
Show file tree
Hide file tree
Showing 3 changed files with 37 additions and 2 deletions.
3 changes: 3 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
# Changelog
All changes to this project will be documented in this file.

## [1.2.1] - 2022-01-24
- Add applicationName parameter (to allow user agent extension)

## [1.2.0] - 2022-01-07
- Add watermark endpoints
- Add video clips
Expand Down
28 changes: 26 additions & 2 deletions src/BaseClient.php
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@
*/
class BaseClient
{
private const DEFAULT_USER_AGENT = 'api.video client (php; v:1.2.1; )';

/**
* @var Authenticator
*/
Expand All @@ -41,12 +43,16 @@ class BaseClient
*/
private $streamFactory;


/**
* @var int
*/
private $chunkSize;

/**
* @var string
*/
private $userAgent;


/**
* @param string $baseUri
Expand All @@ -63,6 +69,7 @@ public function __construct(string $baseUri, ?string $apiKey, ClientInterface $h
$this->requestFactory = $requestFactory;
$this->streamFactory = $streamFactory;
$this->chunkSize = $chunkSize;
$this->userAgent = self::DEFAULT_USER_AGENT;

if ($apiKey) {
$this->authenticator = new Authenticator($this, $apiKey);
Expand Down Expand Up @@ -92,11 +99,28 @@ public function request(Request $commandRequest): ?array
$request = $request->withHeader($name, $value);
}

$request = $request->withHeader('User-Agent', 'api.video client (php; v:1.2.0; )');
$request = $request->withHeader('User-Agent', $this->userAgent);

return $this->sendRequest($request);
}

/**
* @param string $applicationName the application name. Allowed characters: A-Z, a-z, 0-9, -, _, /. Max length: 50.
*/
public function setApplicationName(string $applicationName) {
if($applicationName) {
if (!preg_match_all('/^[\w\-.\/]{1,50}$/m', $applicationName)) {
throw new \InvalidArgumentException(
'Invalid application name. Allowed characters: A-Z, a-z, 0-9, \'-\', \'_\', \'/\'. Max length: 50.'
);
}
$this->userAgent = self::DEFAULT_USER_AGENT . " " . $applicationName;
print("setted" . $this->userAgent . "\n");
} else {
$this->userAgent = self::DEFAULT_USER_AGENT;
}
}

/**
* @return int
*/
Expand Down
8 changes: 8 additions & 0 deletions src/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,14 @@ public function __construct(string $baseUri, ?string $apiKey, ClientInterface $h
$this->baseClient = new BaseClient($baseUri, $apiKey, $httpClient, $requestFactory, $streamFactory, $chunkSize);
}

/**
* @param string $applicationName the application name. Allowed characters: A-Z, a-z, 0-9, -, _, /. Max length: 50.
*/
public function setApplicationName(string $applicationName)
{
$this->baseClient->setApplicationName($applicationName);
}


/**
* @return \ApiVideo\Client\Api\CaptionsApi
Expand Down

0 comments on commit 2e4541f

Please sign in to comment.