Skip to content
This repository has been archived by the owner on Dec 17, 2018. It is now read-only.

Commit

Permalink
Merge pull request #52 from cleentfaar/team.info
Browse files Browse the repository at this point in the history
Team.info (rebased)
  • Loading branch information
cleentfaar committed Jan 18, 2016
2 parents 33bf56e + a9d5559 commit 8dcbdd7
Show file tree
Hide file tree
Showing 12 changed files with 369 additions and 0 deletions.
85 changes: 85 additions & 0 deletions src/CL/Slack/Model/Team.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*
* @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 array
*/
private $icon;

/**
* @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 array of icons
*/
public function getIcon()
{
return $this->icon;
}
}
28 changes: 28 additions & 0 deletions src/CL/Slack/Payload/TeamInfoPayload.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*
* @link Official documentation at https://api.slack.com/methods/team.info
*/
class TeamInfoPayload extends AbstractPayload
{
/**
* {@inheritdoc}
*/
public function getMethod()
{
return 'team.info';
}
}
33 changes: 33 additions & 0 deletions src/CL/Slack/Payload/TeamInfoPayloadResponse.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*/
class TeamInfoPayloadResponse extends AbstractPayloadResponse
{
/**
* @var Team|null
*/
private $team;

/**
* @return Team|null
*/
public function getTeam()
{
return $this->team;
}
}
13 changes: 13 additions & 0 deletions src/CL/Slack/Resources/config/serializer/CL.Slack.Model.Team.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
CL\Slack\Model\Team:
properties:
id:
type: string
name:
type: string
domain:
type: string
emailDomain:
type: string
serialized_name: email_domain
icon:
type: array<string, string>
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CL\Slack\Payload\TeamInfoPayload:
properties:
error:
type: string
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
CL\Slack\Payload\TeamInfoPayloadResponse:
properties:
team:
type: CL\Slack\Model\Team
1 change: 1 addition & 0 deletions src/CL/Slack/Resources/doc/methods/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -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!)
31 changes: 31 additions & 0 deletions src/CL/Slack/Resources/doc/methods/team-info.md
Original file line number Diff line number Diff line change
@@ -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();
}
```
40 changes: 40 additions & 0 deletions tests/src/CL/Slack/Test/Model/ModelTrait.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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
*/
Expand Down
47 changes: 47 additions & 0 deletions tests/src/CL/Slack/Tests/Model/TeamInfoTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*/
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);
}
}
43 changes: 43 additions & 0 deletions tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadResponseTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*/
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());
}
}
40 changes: 40 additions & 0 deletions tests/src/CL/Slack/Tests/Payload/TeamInfoPayloadTest.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<?php

/*
* This file is part of the Slack API library.
*
* (c) Cas Leentfaar <[email protected]>
*
* 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 <[email protected]>
*/
class TeamInfoPayloadTest extends AbstractPayloadTest
{
/**
* {@inheritdoc}
*/
protected function createPayload()
{
$payload = new TeamInfoPayload();
return $payload;
}

/**
* {@inheritdoc}
*
* @param TeamInfoPayload $payload
*/
protected function getExpectedPayloadData(PayloadInterface $payload)
{
return [];
}
}

0 comments on commit 8dcbdd7

Please sign in to comment.