Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions doc/repo/assets.md
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ $assets = $client->api('repo')->releases()->assets()->all('twbs', 'bootstrap', $
$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId);
```

### Download binary content of asset

```php
$asset = $client->api('repo')->releases()->assets()->show('twbs', 'bootstrap', $assetId, true);
```

### Create an asset

```php
Expand Down
11 changes: 9 additions & 2 deletions lib/Github/Api/Repository/Assets.php
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
namespace Github\Api\Repository;

use Github\Api\AbstractApi;
use Github\Api\AcceptHeaderTrait;
use Github\Exception\ErrorException;
use Github\Exception\MissingArgumentException;

Expand All @@ -13,6 +14,8 @@
*/
class Assets extends AbstractApi
{
use AcceptHeaderTrait;

/**
* Get all release's assets in selected repository
* GET /repos/:owner/:repo/releases/:id/assets.
Expand All @@ -36,10 +39,14 @@ public function all($username, $repository, $id)
* @param string $repository the name of the repo
* @param int $id the id of the asset
*
* @return array
* @return array|string
*/
public function show($username, $repository, $id)
public function show($username, $repository, $id, bool $returnBinaryContent = false)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

missing phpdoc :)

Copy link
Collaborator Author

@acrobat acrobat Mar 28, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I didn't add it because it's fully documented in the typehint 😄

{
if ($returnBinaryContent) {
$this->acceptHeaderValue = 'application/octet-stream';
}

return $this->get('/repos/'.rawurlencode($username).'/'.rawurlencode($repository).'/releases/assets/'.$id);
}

Expand Down
5 changes: 2 additions & 3 deletions lib/Github/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -119,18 +119,17 @@ public function __construct(Builder $httpClientBuilder = null, $apiVersion = nul
{
$this->responseHistory = new History();
$this->httpClientBuilder = $builder = $httpClientBuilder ?? new Builder();
$this->apiVersion = $apiVersion ?: 'v3';

$builder->addPlugin(new GithubExceptionThrower());
$builder->addPlugin(new Plugin\HistoryPlugin($this->responseHistory));
$builder->addPlugin(new Plugin\RedirectPlugin());
$builder->addPlugin(new Plugin\AddHostPlugin(Psr17FactoryDiscovery::findUriFactory()->createUri('https://api.github.com')));
$builder->addPlugin(new Plugin\HeaderDefaultsPlugin([
'User-Agent' => 'php-github-api (http://github.com/KnpLabs/php-github-api)',
'Accept' => sprintf('application/vnd.github.%s+json', $this->apiVersion),
]));

$this->apiVersion = $apiVersion ?: 'v3';
$builder->addHeaderValue('Accept', sprintf('application/vnd.github.%s+json', $this->apiVersion));

if ($enterpriseUrl) {
$this->setEnterpriseUrl($enterpriseUrl);
}
Expand Down