Skip to content

Commit d863b8a

Browse files
authored
feat(upload): Add support for files.getUploadURLExternal & files.completeUploadExternal (#182)
1 parent 92f8640 commit d863b8a

26 files changed

+3388
-272
lines changed

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,6 @@
1+
# misc
2+
.idea/
3+
14
# Dependencies
25
/vendor
36

composer.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
}
2727
},
2828
"require": {
29+
"ext-curl": "*",
2930
"php": ">=8.0",
3031
"jane-php/open-api-runtime": "^7.7",
3132
"psr/http-client-implementation": "*",

generated/Client.php

Lines changed: 52 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2478,6 +2478,33 @@ public function filesCommentsDelete(array $formParameters = [], array $headerPar
24782478
return $this->executeEndpoint(new Endpoint\FilesCommentsDelete($formParameters, $headerParameters), $fetch);
24792479
}
24802480

2481+
/**
2482+
* Finishes an upload started with files.getUploadURLExternal.
2483+
*
2484+
* @param array $queryParameters {
2485+
*
2486+
* @var string $blocks A JSON-based array of structured rich text blocks, presented as a URL-encoded string. If the `initial_comment` field is provided, the `blocks` field is ignored.
2487+
* @var string $channel_id Channel ID where the file will be shared. If not specified, the file will remain private.
2488+
* @var string $channels comma-separated list of channel IDs where the file will be shared
2489+
* @var string $files an array of file objects, each containing the `id` of the file to be completed
2490+
* @var string $initial_comment the message text introducing the file in specified channels
2491+
* @var string $thread_ts Provide another message's `ts` value to upload this file as a reply. Never use a reply's `ts` value; use its parent instead. Also, make sure to provide only one channel when using `thread_ts`.
2492+
* }
2493+
*
2494+
* @param array $formParameters {
2495+
*
2496+
* @var string $token Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.
2497+
* }
2498+
*
2499+
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE)
2500+
*
2501+
* @return Model\FilesCompleteUploadExternalPostResponse200|Model\FilesCompleteUploadExternalPostResponsedefault|\Psr\Http\Message\ResponseInterface|null
2502+
*/
2503+
public function filesCompleteUploadExternal(array $queryParameters = [], array $formParameters = [], string $fetch = self::FETCH_OBJECT)
2504+
{
2505+
return $this->executeEndpoint(new Endpoint\FilesCompleteUploadExternal($queryParameters, $formParameters), $fetch);
2506+
}
2507+
24812508
/**
24822509
* Deletes a file.
24832510
*
@@ -2500,6 +2527,31 @@ public function filesDelete(array $formParameters = [], array $headerParameters
25002527
return $this->executeEndpoint(new Endpoint\FilesDelete($formParameters, $headerParameters), $fetch);
25012528
}
25022529

2530+
/**
2531+
* Gets a URL for an edge external file upload.
2532+
*
2533+
* @param array $queryParameters {
2534+
*
2535+
* @var string $alt_txt description of image for screen-reader
2536+
* @var string $filename name of the file being uploaded
2537+
* @var int $length size in bytes of the file being uploaded
2538+
* @var string $snippet_type Syntax type of the snippet being uploaded.
2539+
* }
2540+
*
2541+
* @param array $formParameters {
2542+
*
2543+
* @var string $token Authentication token. Requires scope: `files:write`
2544+
* }
2545+
*
2546+
* @param string $fetch Fetch mode to use (can be OBJECT or RESPONSE)
2547+
*
2548+
* @return Model\FilesGetUploadURLExternalPostResponse200|Model\FilesGetUploadURLExternalPostResponsedefault|\Psr\Http\Message\ResponseInterface|null
2549+
*/
2550+
public function filesGetUploadUrlExternal(array $queryParameters = [], array $formParameters = [], string $fetch = self::FETCH_OBJECT)
2551+
{
2552+
return $this->executeEndpoint(new Endpoint\FilesGetUploadUrlExternal($queryParameters, $formParameters), $fetch);
2553+
}
2554+
25032555
/**
25042556
* Gets information about a file.
25052557
*
Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace JoliCode\Slack\Api\Endpoint;
15+
16+
class FilesCompleteUploadExternal extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoint implements \JoliCode\Slack\Api\Runtime\Client\Endpoint
17+
{
18+
use \JoliCode\Slack\Api\Runtime\Client\EndpointTrait;
19+
20+
/**
21+
* Finishes an upload started with files.getUploadURLExternal.
22+
*
23+
* @param array $queryParameters {
24+
*
25+
* @var string $blocks A JSON-based array of structured rich text blocks, presented as a URL-encoded string. If the `initial_comment` field is provided, the `blocks` field is ignored.
26+
* @var string $channel_id Channel ID where the file will be shared. If not specified, the file will remain private.
27+
* @var string $channels comma-separated list of channel IDs where the file will be shared
28+
* @var string $files an array of file objects, each containing the `id` of the file to be completed
29+
* @var string $initial_comment the message text introducing the file in specified channels
30+
* @var string $thread_ts Provide another message's `ts` value to upload this file as a reply. Never use a reply's `ts` value; use its parent instead. Also, make sure to provide only one channel when using `thread_ts`.
31+
* }
32+
*
33+
* @param array $formParameters {
34+
*
35+
* @var string $token Authentication token bearing required scopes. Tokens should be passed as an HTTP Authorization header or alternatively, as a POST parameter.
36+
* }
37+
*/
38+
public function __construct(array $queryParameters = [], array $formParameters = [])
39+
{
40+
$this->queryParameters = $queryParameters;
41+
$this->formParameters = $formParameters;
42+
}
43+
44+
public function getMethod(): string
45+
{
46+
return 'POST';
47+
}
48+
49+
public function getUri(): string
50+
{
51+
return '/files.completeUploadExternal';
52+
}
53+
54+
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
55+
{
56+
return $this->getFormBody();
57+
}
58+
59+
public function getExtraHeaders(): array
60+
{
61+
return ['Accept' => ['application/json']];
62+
}
63+
64+
public function getAuthenticationScopes(): array
65+
{
66+
return ['slackAuth'];
67+
}
68+
69+
protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
70+
{
71+
$optionsResolver = parent::getQueryOptionsResolver();
72+
$optionsResolver->setDefined(['blocks', 'channel_id', 'channels', 'files', 'initial_comment', 'thread_ts']);
73+
$optionsResolver->setRequired(['files']);
74+
$optionsResolver->setDefaults([]);
75+
$optionsResolver->addAllowedTypes('blocks', ['string']);
76+
$optionsResolver->addAllowedTypes('channel_id', ['string']);
77+
$optionsResolver->addAllowedTypes('channels', ['string']);
78+
$optionsResolver->addAllowedTypes('files', ['string']);
79+
$optionsResolver->addAllowedTypes('initial_comment', ['string']);
80+
$optionsResolver->addAllowedTypes('thread_ts', ['string']);
81+
82+
return $optionsResolver;
83+
}
84+
85+
protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
86+
{
87+
$optionsResolver = parent::getFormOptionsResolver();
88+
$optionsResolver->setDefined(['token']);
89+
$optionsResolver->setRequired([]);
90+
$optionsResolver->setDefaults([]);
91+
$optionsResolver->addAllowedTypes('token', ['string']);
92+
93+
return $optionsResolver;
94+
}
95+
96+
/**
97+
* @return \JoliCode\Slack\Api\Model\FilesCompleteUploadExternalPostResponse200|\JoliCode\Slack\Api\Model\FilesCompleteUploadExternalPostResponsedefault|null
98+
*/
99+
protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
100+
{
101+
$status = $response->getStatusCode();
102+
$body = (string) $response->getBody();
103+
if (200 === $status) {
104+
return $serializer->deserialize($body, 'JoliCode\Slack\Api\Model\FilesCompleteUploadExternalPostResponse200', 'json');
105+
}
106+
107+
return $serializer->deserialize($body, 'JoliCode\Slack\Api\Model\FilesCompleteUploadExternalPostResponsedefault', 'json');
108+
}
109+
}
Lines changed: 105 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,105 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace JoliCode\Slack\Api\Endpoint;
15+
16+
class FilesGetUploadUrlExternal extends \JoliCode\Slack\Api\Runtime\Client\BaseEndpoint implements \JoliCode\Slack\Api\Runtime\Client\Endpoint
17+
{
18+
use \JoliCode\Slack\Api\Runtime\Client\EndpointTrait;
19+
20+
/**
21+
* Gets a URL for an edge external file upload.
22+
*
23+
* @param array $queryParameters {
24+
*
25+
* @var string $alt_txt description of image for screen-reader
26+
* @var string $filename name of the file being uploaded
27+
* @var int $length size in bytes of the file being uploaded
28+
* @var string $snippet_type Syntax type of the snippet being uploaded.
29+
* }
30+
*
31+
* @param array $formParameters {
32+
*
33+
* @var string $token Authentication token. Requires scope: `files:write`
34+
* }
35+
*/
36+
public function __construct(array $queryParameters = [], array $formParameters = [])
37+
{
38+
$this->queryParameters = $queryParameters;
39+
$this->formParameters = $formParameters;
40+
}
41+
42+
public function getMethod(): string
43+
{
44+
return 'POST';
45+
}
46+
47+
public function getUri(): string
48+
{
49+
return '/files.getUploadURLExternal';
50+
}
51+
52+
public function getBody(\Symfony\Component\Serializer\SerializerInterface $serializer, $streamFactory = null): array
53+
{
54+
return $this->getFormBody();
55+
}
56+
57+
public function getExtraHeaders(): array
58+
{
59+
return ['Accept' => ['application/json']];
60+
}
61+
62+
public function getAuthenticationScopes(): array
63+
{
64+
return ['slackAuth'];
65+
}
66+
67+
protected function getQueryOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
68+
{
69+
$optionsResolver = parent::getQueryOptionsResolver();
70+
$optionsResolver->setDefined(['alt_txt', 'filename', 'length', 'snippet_type']);
71+
$optionsResolver->setRequired(['filename', 'length']);
72+
$optionsResolver->setDefaults([]);
73+
$optionsResolver->addAllowedTypes('alt_txt', ['string']);
74+
$optionsResolver->addAllowedTypes('filename', ['string']);
75+
$optionsResolver->addAllowedTypes('length', ['int']);
76+
$optionsResolver->addAllowedTypes('snippet_type', ['string']);
77+
78+
return $optionsResolver;
79+
}
80+
81+
protected function getFormOptionsResolver(): \Symfony\Component\OptionsResolver\OptionsResolver
82+
{
83+
$optionsResolver = parent::getFormOptionsResolver();
84+
$optionsResolver->setDefined(['token']);
85+
$optionsResolver->setRequired([]);
86+
$optionsResolver->setDefaults([]);
87+
$optionsResolver->addAllowedTypes('token', ['string']);
88+
89+
return $optionsResolver;
90+
}
91+
92+
/**
93+
* @return \JoliCode\Slack\Api\Model\FilesGetUploadURLExternalPostResponse200|\JoliCode\Slack\Api\Model\FilesGetUploadURLExternalPostResponsedefault|null
94+
*/
95+
protected function transformResponseBody(\Psr\Http\Message\ResponseInterface $response, \Symfony\Component\Serializer\SerializerInterface $serializer, ?string $contentType = null)
96+
{
97+
$status = $response->getStatusCode();
98+
$body = (string) $response->getBody();
99+
if (200 === $status) {
100+
return $serializer->deserialize($body, 'JoliCode\Slack\Api\Model\FilesGetUploadURLExternalPostResponse200', 'json');
101+
}
102+
103+
return $serializer->deserialize($body, 'JoliCode\Slack\Api\Model\FilesGetUploadURLExternalPostResponsedefault', 'json');
104+
}
105+
}
Lines changed: 67 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
<?php
2+
3+
declare(strict_types=1);
4+
5+
/*
6+
* This file is part of JoliCode's Slack PHP API project.
7+
*
8+
* (c) JoliCode <coucou@jolicode.com>
9+
*
10+
* For the full copyright and license information, please view the LICENSE
11+
* file that was distributed with this source code.
12+
*/
13+
14+
namespace JoliCode\Slack\Api\Model;
15+
16+
class FilesCompleteUploadExternalPostResponse200
17+
{
18+
/**
19+
* @var array
20+
*/
21+
protected $initialized = [];
22+
/**
23+
* @var list<FilesCompleteUploadExternalPostResponse200FilesItem>|null
24+
*/
25+
protected $files;
26+
/**
27+
* @var bool|null
28+
*/
29+
protected $ok;
30+
31+
public function isInitialized($property): bool
32+
{
33+
return \array_key_exists($property, $this->initialized);
34+
}
35+
36+
/**
37+
* @return list<FilesCompleteUploadExternalPostResponse200FilesItem>|null
38+
*/
39+
public function getFiles(): ?array
40+
{
41+
return $this->files;
42+
}
43+
44+
/**
45+
* @param list<FilesCompleteUploadExternalPostResponse200FilesItem>|null $files
46+
*/
47+
public function setFiles(?array $files): self
48+
{
49+
$this->initialized['files'] = true;
50+
$this->files = $files;
51+
52+
return $this;
53+
}
54+
55+
public function getOk(): ?bool
56+
{
57+
return $this->ok;
58+
}
59+
60+
public function setOk(?bool $ok): self
61+
{
62+
$this->initialized['ok'] = true;
63+
$this->ok = $ok;
64+
65+
return $this;
66+
}
67+
}

0 commit comments

Comments
 (0)