This repository has been archived by the owner on Jul 5, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 18
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #8 from DZunke/feature/users-service
Implement new users service to get detailed infos about the users on …
- Loading branch information
Showing
8 changed files
with
188 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
<?php | ||
|
||
namespace DZunke\SlackBundle\Slack\Client\Actions; | ||
|
||
use DZunke\SlackBundle\Slack\Client\Actions; | ||
|
||
/** | ||
* @see https://api.slack.com/methods/users.list | ||
*/ | ||
class UsersList implements ActionsInterface | ||
{ | ||
|
||
/** | ||
* @var array | ||
*/ | ||
protected $parameter = [ | ||
'presence' => 1 | ||
]; | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getRenderedRequestParams() | ||
{ | ||
return $this->parameter; | ||
} | ||
|
||
/** | ||
* @param array $parameter | ||
* @return $this | ||
*/ | ||
public function setParameter(array $parameter) | ||
{ | ||
foreach ($parameter as $key => $value) { | ||
if (array_key_exists($key, $this->parameter)) { | ||
$this->parameter[$key] = $value; | ||
} | ||
} | ||
|
||
return $this; | ||
} | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getAction() | ||
{ | ||
return Actions::ACTION_USERS_LIST; | ||
} | ||
|
||
/** | ||
* @param array $response | ||
* @return array | ||
*/ | ||
public function parseResponse(array $response) | ||
{ | ||
$users = []; | ||
foreach ($response['members'] as $user) { | ||
$users[$user['name']] = [ | ||
'id' => $user['id'], | ||
'name' => $user['name'], | ||
'deleted' => (bool)$user['deleted'], | ||
'real_name' => $user['real_name'], | ||
'is_bot' => (bool)$user['is_bot'], | ||
'presence' => isset($user['presence']) ? $user['presence'] : null | ||
]; | ||
} | ||
|
||
return $users; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,74 @@ | ||
<?php | ||
|
||
namespace DZunke\SlackBundle\Slack; | ||
|
||
use DZunke\SlackBundle\Slack\Client\Actions; | ||
|
||
class Users | ||
{ | ||
/** | ||
* @var Client | ||
*/ | ||
protected $client; | ||
|
||
/** | ||
* @param Client $client | ||
*/ | ||
public function __construct(Client $client) | ||
{ | ||
$this->client = $client; | ||
} | ||
|
||
/** | ||
* @return Client | ||
*/ | ||
public function getClient() | ||
{ | ||
return $this->client; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getUsers() | ||
{ | ||
return $this->client->send(Actions::ACTION_USERS_LIST)->getData(); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getActiveUsers() | ||
{ | ||
return array_filter( | ||
$this->getUsers(), | ||
function ($user) { | ||
return $user['deleted'] === false; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getDeletedUsers() | ||
{ | ||
return array_filter( | ||
$this->getUsers(), | ||
function ($user) { | ||
return $user['deleted'] === true; | ||
} | ||
); | ||
} | ||
|
||
/** | ||
* @param string $name | ||
* @return null|array | ||
*/ | ||
public function getId($name) | ||
{ | ||
$users = $this->getUsers(); | ||
|
||
return array_key_exists($name, $users) ? $users[$name]['id'] : null; | ||
} | ||
} |