From 6d83fb1fb37d214880f0e5fd63139d3f9cca36a9 Mon Sep 17 00:00:00 2001 From: Denis Zunke Date: Mon, 16 Jan 2017 20:43:28 +0100 Subject: [PATCH] Release v2.2 (#23) * Notice: Undefined index: email (#22) email may be undefined * Add support to send Requests as POST * Fix channel history output --- CHANGELOG | 6 ++ DependencyInjection/Configuration.php | 3 + DependencyInjection/DZunkeSlackExtension.php | 4 ++ Resources/doc/basic-usage.md | 3 + Resources/doc/configuration.md | 1 + Slack/Channels.php | 2 +- Slack/Client.php | 2 +- Slack/Client/Actions/UsersList.php | 2 +- Slack/Client/Connection.php | 62 ++++++++++++++++---- 9 files changed, 70 insertions(+), 15 deletions(-) diff --git a/CHANGELOG b/CHANGELOG index ee53a33..5ed86bf 100644 --- a/CHANGELOG +++ b/CHANGELOG @@ -1,3 +1,9 @@ +SlackBundle v2.2.0 +================== +- Feature: Add Support to send Requests as POST instead of GET +- Patch: Fix UsersList-Action, users email could be empty (by @mediafigaro) +- Patch: Fix channel history (found in fork by @elmpp) + SlackBundle v2.1.0 ================== - Add Support to disable SSL Verification at Guzzle Client diff --git a/DependencyInjection/Configuration.php b/DependencyInjection/Configuration.php index f546e9f..909a6bb 100644 --- a/DependencyInjection/Configuration.php +++ b/DependencyInjection/Configuration.php @@ -33,6 +33,9 @@ public function getConfigTreeBuilder() ->booleanNode('verify_ssl') ->defaultTrue() ->end() + ->booleanNode('use_http_post') + ->defaultFalse() + ->end() ->end(); $rootNode->append($this->addIdentities()); diff --git a/DependencyInjection/DZunkeSlackExtension.php b/DependencyInjection/DZunkeSlackExtension.php index 84d1c70..6f29945 100644 --- a/DependencyInjection/DZunkeSlackExtension.php +++ b/DependencyInjection/DZunkeSlackExtension.php @@ -50,6 +50,10 @@ protected function configureSlackConnection(array $config, ContainerBuilder $con $definition->addMethodCall('setToken', [$config['token']]); $definition->addMethodCall('setLimitRetries', [$config['limit_retries']]); $definition->addMethodCall('setVerifySsl', [$config['verify_ssl']]); + + if ($config['use_http_post'] === true) { + $definition->addMethodCall('isHttpPostMethod'); + } } } diff --git a/Resources/doc/basic-usage.md b/Resources/doc/basic-usage.md index af82aae..948bf42 100644 --- a/Resources/doc/basic-usage.md +++ b/Resources/doc/basic-usage.md @@ -11,6 +11,9 @@ $connection = new \DZunke\SlackBundle\Slack\Client\Connection(); $connection->setEndpoint('slack.com/api/'); $connection->setToken('YOUR API TOKEN'); +# Switch from GET to POST Method +# $connection->isHttpPostMethod(); + $client = new \DZunke\SlackBundle\Slack\Client($connection); $response = $client->send( diff --git a/Resources/doc/configuration.md b/Resources/doc/configuration.md index d92292c..b46a1f4 100644 --- a/Resources/doc/configuration.md +++ b/Resources/doc/configuration.md @@ -5,6 +5,7 @@ d_zunke_slack: endpoint: slack.com/api/ token: null # Required verify_ssl: true # ssl verification at guzzle client + use_http_post: false # give the ability to send request as HTTP POST # The amount of retries for the connection if the Rate Limits of Slack are reached limit_retries: 3 diff --git a/Slack/Channels.php b/Slack/Channels.php index d423736..eeef3db 100644 --- a/Slack/Channels.php +++ b/Slack/Channels.php @@ -133,7 +133,7 @@ public function history($channel, $from = null, $count = 10) $objMsg->setType(isset($message['subtype']) ? $message['subtype'] : $message['type']); $objMsg->setUserId(isset($message['user']) ? $message['user'] : null); $objMsg->setUsername(isset($message['username']) ? $message['username'] : null); - $objMsg->setContent($message['test']); + $objMsg->setContent($message['text']); $repository[] = $objMsg; } diff --git a/Slack/Client.php b/Slack/Client.php index 97b10c1..19ee68a 100644 --- a/Slack/Client.php +++ b/Slack/Client.php @@ -94,6 +94,6 @@ protected function executeRequest(Uri $uri) { $guzzle = new GuzzleClient(['verify' => $this->connection->getVerifySsl()]); - return $guzzle->request('GET', $uri); + return $guzzle->request($this->connection->getHttpMethod(), $uri); } } diff --git a/Slack/Client/Actions/UsersList.php b/Slack/Client/Actions/UsersList.php index 815bd94..3519603 100644 --- a/Slack/Client/Actions/UsersList.php +++ b/Slack/Client/Actions/UsersList.php @@ -61,7 +61,7 @@ public function parseResponse(array $response) 'name' => $user['name'], 'deleted' => (bool)$user['deleted'], 'real_name' => $user['profile']['real_name'], - 'email' => $user['profile']['email'], + 'email' => isset($user['profile']['email']) ? $user['profile']['email'] : null, 'is_bot' => (bool)$user['is_bot'], 'presence' => isset($user['presence']) ? $user['presence'] : null ]; diff --git a/Slack/Client/Connection.php b/Slack/Client/Connection.php index 639338b..2b4d22d 100644 --- a/Slack/Client/Connection.php +++ b/Slack/Client/Connection.php @@ -2,6 +2,8 @@ namespace DZunke\SlackBundle\Slack\Client; +use Symfony\Component\HttpFoundation\Request; + class Connection { /** @@ -24,8 +26,22 @@ class Connection */ private $verifySsl = true; + /** + * @var string + */ + private $httpMethod = Request::METHOD_GET; + + /** + * @return string + */ + public function getEndpoint() + { + return $this->endpoint; + } + /** * @param string $endpoint + * * @return $this */ public function setEndpoint($endpoint) @@ -38,13 +54,14 @@ public function setEndpoint($endpoint) /** * @return string */ - public function getEndpoint() + public function getToken() { - return $this->endpoint; + return $this->token; } /** * @param string $token + * * @return $this */ public function setToken($token) @@ -55,15 +72,16 @@ public function setToken($token) } /** - * @return string + * @return int */ - public function getToken() + public function getLimitRetries() { - return $this->token; + return $this->limitRetries; } /** * @param int $retries + * * @return $this */ public function setLimitRetries($retries) @@ -74,11 +92,11 @@ public function setLimitRetries($retries) } /** - * @return int + * @return bool */ - public function getLimitRetries() + public function getVerifySsl() { - return $this->limitRetries; + return $this->verifySsl; } /** @@ -88,17 +106,37 @@ public function getLimitRetries() */ public function setVerifySsl($verifySsl) { - $this->verifySsl = (bool) $verifySsl; + $this->verifySsl = (bool)$verifySsl; return $this; } /** - * @return bool + * @return string */ - public function getVerifySsl() + public function getHttpMethod() { - return $this->verifySsl; + return $this->httpMethod; + } + + /** + * @return $this + */ + public function isHttpGetMethod() + { + $this->httpMethod = Request::METHOD_GET; + + return $this; + } + + /** + * @return $this + */ + public function isHttpPostMethod() + { + $this->httpMethod = Request::METHOD_POST; + + return $this; } /**