|
| 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 | +} |
0 commit comments