From d0f3da6befa61e9fcd675f0ff9a12579ca51c11a Mon Sep 17 00:00:00 2001 From: Nic Malan Date: Sun, 22 Nov 2015 18:23:52 +0200 Subject: [PATCH 1/2] `team.info` request & payload. --- src/CL/Slack/Model/Team.php | 150 ++++++++++++++++++ src/CL/Slack/Payload/TeamInfoPayload.php | 28 ++++ .../Slack/Payload/TeamInfoPayloadResponse.php | 33 ++++ .../config/serializer/CL.Slack.Model.Team.yml | 28 ++++ .../CL.Slack.Payload.TeamInfoPayload.yml | 4 + ....Slack.Payload.TeamInfoPayloadResponse.yml | 4 + src/CL/Slack/Resources/doc/methods/index.md | 1 + .../Slack/Resources/doc/methods/team-info.md | 31 ++++ tests/src/CL/Slack/Test/Model/ModelTrait.php | 40 +++++ .../src/CL/Slack/Tests/Model/TeamInfoTest.php | 47 ++++++ .../Payload/TeamInfoPayloadResponseTest.php | 43 +++++ .../Tests/Payload/TeamInfoPayloadTest.php | 40 +++++ 12 files changed, 449 insertions(+) create mode 100644 src/CL/Slack/Model/Team.php create mode 100644 src/CL/Slack/Payload/TeamInfoPayload.php create mode 100644 src/CL/Slack/Payload/TeamInfoPayloadResponse.php create mode 100644 src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml create mode 100644 src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayload.yml create mode 100644 src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayloadResponse.yml create mode 100644 src/CL/Slack/Resources/doc/methods/team-info.md create mode 100644 tests/src/CL/Slack/Tests/Model/TeamInfoTest.php create mode 100644 tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadResponseTest.php create mode 100644 tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadTest.php diff --git a/src/CL/Slack/Model/Team.php b/src/CL/Slack/Model/Team.php new file mode 100644 index 00000000..68278053 --- /dev/null +++ b/src/CL/Slack/Model/Team.php @@ -0,0 +1,150 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Model; + +/** + * @author Nic Malan + * + * @link Official documentation at https://api.slack.com/types + */ +class Team extends AbstractModel +{ + /** + * @var string + */ + private $id; + + /** + * @var string + */ + private $name; + + /** + * @var string + */ + private $domain; + + /** + * @var string + */ + private $emailDomain; + + /** + * @var string|null + */ + private $image34; + + /** + * @var string|null + */ + private $image44; + + /** + * @var string|null + */ + private $image68; + + /** + * @var string|null + */ + private $image88; + + /** + * @var string|null + */ + private $image102; + + /** + * @var string|null + */ + private $image132; + + /** + * @return string The ID of this team. + */ + public function getId() + { + return $this->id; + } + + /** + * @return string The name of this team. + */ + public function getName() + { + return $this->name; + } + + /** + * @return string The domain of this team. + */ + public function getDomain() + { + return $this->domain; + } + + /** + * @return string The email domain of this team. + */ + public function getEmailDomain() + { + return $this->emailDomain; + } + + /** + * @return string The image 34 of this team. + */ + public function getImage34() + { + return $this->image34; + } + + /** + * @return string The image 44 of this team. + */ + public function getImage44() + { + return $this->image44; + } + + /** + * @return string The image 68 of this team. + */ + public function getImage68() + { + return $this->image68; + } + + /** + * @return string The image 88 of this team. + */ + public function getImage88() + { + return $this->image88; + } + + /** + * @return string The image 102 of this team. + */ + public function getImage102() + { + return $this->image102; + } + + /** + * @return string The image 132 of this team. + */ + public function getImage132() + { + return $this->image132; + } +} diff --git a/src/CL/Slack/Payload/TeamInfoPayload.php b/src/CL/Slack/Payload/TeamInfoPayload.php new file mode 100644 index 00000000..ff4a51e5 --- /dev/null +++ b/src/CL/Slack/Payload/TeamInfoPayload.php @@ -0,0 +1,28 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Payload; + +/** + * @author Nic Malan + * + * @link Official documentation at https://api.slack.com/methods/team.info + */ +class TeamInfoPayload extends AbstractPayload +{ + /** + * {@inheritdoc} + */ + public function getMethod() + { + return 'team.info'; + } +} diff --git a/src/CL/Slack/Payload/TeamInfoPayloadResponse.php b/src/CL/Slack/Payload/TeamInfoPayloadResponse.php new file mode 100644 index 00000000..7ab4f6f1 --- /dev/null +++ b/src/CL/Slack/Payload/TeamInfoPayloadResponse.php @@ -0,0 +1,33 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Payload; + +use CL\Slack\Model\Team; + +/** + * @author Nic Malan + */ +class TeamInfoPayloadResponse extends AbstractPayloadResponse +{ + /** + * @var Team|null + */ + private $team; + + /** + * @return Team|null + */ + public function getTeam() + { + return $this->team; + } +} diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml new file mode 100644 index 00000000..d004f8ab --- /dev/null +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml @@ -0,0 +1,28 @@ +CL\Slack\Model\Team: + properties: + id: + type: string + name: + type: string + domain: + type: string + emailDomain: + type: string + image34: + type: string + serialized_name: image_34 + image44: + type: string + serialized_name: image_44 + image68: + type: string + serialized_name: image_68 + image88: + type: string + serialized_name: image_88 + image102: + type: string + serialized_name: image_102 + image132: + type: string + serialized_name: image_132 diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayload.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayload.yml new file mode 100644 index 00000000..ab3cb054 --- /dev/null +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayload.yml @@ -0,0 +1,4 @@ +CL\Slack\Payload\TeamInfoPayload: + properties: + error: + type: string diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayloadResponse.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayloadResponse.yml new file mode 100644 index 00000000..98ac7b0b --- /dev/null +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Payload.TeamInfoPayloadResponse.yml @@ -0,0 +1,4 @@ +CL\Slack\Payload\TeamInfoPayloadResponse: + properties: + team: + type: CL\Slack\Model\Team diff --git a/src/CL/Slack/Resources/doc/methods/index.md b/src/CL/Slack/Resources/doc/methods/index.md index 3012f113..2780ebd5 100644 --- a/src/CL/Slack/Resources/doc/methods/index.md +++ b/src/CL/Slack/Resources/doc/methods/index.md @@ -51,6 +51,7 @@ The following API methods are accessible with this library (click on a name to g - [search.files](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/search-files.md) - [search.messages](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/search-messages.md) - [stars.list](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/stars-list.md) (Documentation coming soon!) +- [team.info](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/team-info.md) - [users.info](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/users-info.md) (Documentation coming soon!) - [users.list](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/users-list.md) - [users.setActive](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Resources/doc/methods/users-set-active.md) (Documentation coming soon!) diff --git a/src/CL/Slack/Resources/doc/methods/team-info.md b/src/CL/Slack/Resources/doc/methods/team-info.md new file mode 100644 index 00000000..de4b1d72 --- /dev/null +++ b/src/CL/Slack/Resources/doc/methods/team-info.md @@ -0,0 +1,31 @@ +## channels.list + +This method is used to get the info for a team. + +| | | +|-------------------------|---------------------------------------------------------------------------------------------------------------------------------| +| Official documentation | https://api.slack.com/methods/team.info | +| `Payload` class | [TeamInfoPayload](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Payload/TeamInfoPayload.php) | +| `PayloadResponse` class | [TeamInfoPayloadResponse](https://github.com/cleentfaar/slack/blob/master/src/CL/Slack/Payload/TeamInfoPayloadResponse.php) | + + +### Usage + +```php +$payload = new TeamInfoPayload(); + +$apiClient = new ApiClient('your-slack-token-here'); +$response = $apiClient->send($payload); + +if ($response->isOk()) { + $response->getTeam() // the team's info +} else { + // something went wrong, but what? + + // simple error (Slack's error message) + echo $response->getError(); + + // explained error (Slack's explanation of the error, according to the documentation) + echo $response->getErrorExplanation(); +} +``` diff --git a/tests/src/CL/Slack/Test/Model/ModelTrait.php b/tests/src/CL/Slack/Test/Model/ModelTrait.php index f86ba705..4d5a64f5 100644 --- a/tests/src/CL/Slack/Test/Model/ModelTrait.php +++ b/tests/src/CL/Slack/Test/Model/ModelTrait.php @@ -24,6 +24,7 @@ use CL\Slack\Model\SimpleChannel; use CL\Slack\Model\SimpleMessage; use CL\Slack\Model\StarredItem; +use CL\Slack\Model\Team; use CL\Slack\Model\User; use CL\Slack\Model\UserProfile; use PHPUnit_Framework_Assert as Assert; @@ -575,6 +576,45 @@ protected function assertUserProfile(array $expected, UserProfile $actual) ]); } + /** + * @return array + */ + protected function createTeam() + { + return [ + 'id' => 'T12345', + 'name' => 'My Team', + 'domain' => 'example.com', + 'email_domain' => 'example.com', + 'image_34' => 'https:\/\/www.example.com/image34.jpg', + 'image_44' => 'https:\/\/www.example.com/image44.jpg', + 'image_68' => 'https:\/\/www.example.com/image68.jpg', + 'image_88' => 'https:\/\/www.example.com/image88.jpg', + 'image_102' => 'https:\/\/www.example.com/image102.jpg', + 'image_132' => 'https:\/\/www.example.com/image132.jpg', + ]; + } + + /** + * @param array $expected + * @param Team $actual + */ + protected function assertTeam(array $expected, Team $actual) + { + $this->assertEquals($expected, [ + 'id' => $actual->getId(), + 'name' => $actual->getName(), + 'domain' => $actual->getDomain(), + 'email_domain' => $actual->getEmailDomain(), + 'image_34' => $actual->getImage34(), + 'image_44' => $actual->getImage44(), + 'image_68' => $actual->getImage68(), + 'image_88' => $actual->getImage88(), + 'image_102' => $actual->getImage102(), + 'image_132' => $actual->getImage132(), + ]); + } + /** * @return array */ diff --git a/tests/src/CL/Slack/Tests/Model/TeamInfoTest.php b/tests/src/CL/Slack/Tests/Model/TeamInfoTest.php new file mode 100644 index 00000000..910527c0 --- /dev/null +++ b/tests/src/CL/Slack/Tests/Model/TeamInfoTest.php @@ -0,0 +1,47 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Tests\Model; + +use CL\Slack\Model\AbstractModel; +use CL\Slack\Model\Team; + +/** + * @author Nic Malan + */ +class TeamInfoTest extends AbstractModelTest +{ + /** + * @return array + */ + protected function getModelData() + { + return $this->createTeam(); + } + + /** + * @return string + */ + protected function getModelClass() + { + return 'CL\Slack\Model\Team'; + } + + /** + * {@inheritdoc} + * + * @param Team $actualModel + */ + protected function assertModel(array $expectedData, AbstractModel $actualModel) + { + $this->assertTeam($expectedData, $actualModel); + } +} diff --git a/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadResponseTest.php b/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadResponseTest.php new file mode 100644 index 00000000..8ac28d90 --- /dev/null +++ b/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadResponseTest.php @@ -0,0 +1,43 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Tests\Payload; + +use CL\Slack\Payload\PayloadResponseInterface; +use CL\Slack\Payload\TeamInfoPayloadResponse; + +/** + * @author Nic Malan + */ +class TeamInfoPayloadResponseTest extends AbstractPayloadResponseTest +{ + /** + * {@inheritdoc} + */ + public function createResponseData() + { + return [ + 'team' => $this->createTeam(), + ]; + } + + /** + * {@inheritdoc} + * + * @param array $responseData + * @param TeamInfoPayloadResponse $payloadResponse + */ + protected function assertResponse(array $responseData, PayloadResponseInterface $payloadResponse) + { + $this->assertInstanceOf('CL\Slack\Model\Team', $payloadResponse->getTeam()); + $this->assertTeam($responseData['team'], $payloadResponse->getTeam()); + } +} diff --git a/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadTest.php b/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadTest.php new file mode 100644 index 00000000..52389ddc --- /dev/null +++ b/tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadTest.php @@ -0,0 +1,40 @@ + + * + * For the full copyright and license information, please view the LICENSE + * file that was distributed with this source code. + */ + +namespace CL\Slack\Tests\Payload; + +use CL\Slack\Payload\PayloadInterface; +use CL\Slack\Payload\TeamInfoPayload; + +/** + * @author Nic Malan + */ +class TeamInfoPayloadTest extends AbstractPayloadTest +{ + /** + * {@inheritdoc} + */ + protected function createPayload() + { + $payload = new TeamInfoPayload(); + return $payload; + } + + /** + * {@inheritdoc} + * + * @param TeamInfoPayload $payload + */ + protected function getExpectedPayloadData(PayloadInterface $payload) + { + return []; + } +} From a9d55592813a08e0e1d9b6c281a91678e5c8db83 Mon Sep 17 00:00:00 2001 From: Nic Malan Date: Wed, 30 Dec 2015 09:18:20 +0200 Subject: [PATCH 2/2] store team icon data in an array --- src/CL/Slack/Model/Team.php | 75 ++----------------- .../config/serializer/CL.Slack.Model.Team.yml | 21 +----- 2 files changed, 8 insertions(+), 88 deletions(-) diff --git a/src/CL/Slack/Model/Team.php b/src/CL/Slack/Model/Team.php index 68278053..f04b24b0 100644 --- a/src/CL/Slack/Model/Team.php +++ b/src/CL/Slack/Model/Team.php @@ -39,34 +39,9 @@ class Team extends AbstractModel private $emailDomain; /** - * @var string|null + * @var array */ - private $image34; - - /** - * @var string|null - */ - private $image44; - - /** - * @var string|null - */ - private $image68; - - /** - * @var string|null - */ - private $image88; - - /** - * @var string|null - */ - private $image102; - - /** - * @var string|null - */ - private $image132; + private $icon; /** * @return string The ID of this team. @@ -101,50 +76,10 @@ public function getEmailDomain() } /** - * @return string The image 34 of this team. - */ - public function getImage34() - { - return $this->image34; - } - - /** - * @return string The image 44 of this team. - */ - public function getImage44() - { - return $this->image44; - } - - /** - * @return string The image 68 of this team. - */ - public function getImage68() - { - return $this->image68; - } - - /** - * @return string The image 88 of this team. - */ - public function getImage88() - { - return $this->image88; - } - - /** - * @return string The image 102 of this team. - */ - public function getImage102() - { - return $this->image102; - } - - /** - * @return string The image 132 of this team. + * @return array of icons */ - public function getImage132() + public function getIcon() { - return $this->image132; + return $this->icon; } } diff --git a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml index d004f8ab..66255942 100644 --- a/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml +++ b/src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml @@ -8,21 +8,6 @@ CL\Slack\Model\Team: type: string emailDomain: type: string - image34: - type: string - serialized_name: image_34 - image44: - type: string - serialized_name: image_44 - image68: - type: string - serialized_name: image_68 - image88: - type: string - serialized_name: image_88 - image102: - type: string - serialized_name: image_102 - image132: - type: string - serialized_name: image_132 + serialized_name: email_domain + icon: + type: array