Skip to content
This repository has been archived by the owner on Jul 5, 2022. It is now read-only.

Commit

Permalink
Release v2.2 (#23)
Browse files Browse the repository at this point in the history
* Notice: Undefined index: email (#22)

email may be undefined

* Add support to send Requests as POST

* Fix channel history output
  • Loading branch information
DZunke authored Jan 16, 2017
1 parent 711972e commit 6d83fb1
Show file tree
Hide file tree
Showing 9 changed files with 70 additions and 15 deletions.
6 changes: 6 additions & 0 deletions CHANGELOG
Original file line number Diff line number Diff line change
@@ -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
Expand Down
3 changes: 3 additions & 0 deletions DependencyInjection/Configuration.php
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,9 @@ public function getConfigTreeBuilder()
->booleanNode('verify_ssl')
->defaultTrue()
->end()
->booleanNode('use_http_post')
->defaultFalse()
->end()
->end();

$rootNode->append($this->addIdentities());
Expand Down
4 changes: 4 additions & 0 deletions DependencyInjection/DZunkeSlackExtension.php
Original file line number Diff line number Diff line change
Expand Up @@ -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');
}
}

}
3 changes: 3 additions & 0 deletions Resources/doc/basic-usage.md
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
1 change: 1 addition & 0 deletions Resources/doc/configuration.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
2 changes: 1 addition & 1 deletion Slack/Channels.php
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}
Expand Down
2 changes: 1 addition & 1 deletion Slack/Client.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}
}
2 changes: 1 addition & 1 deletion Slack/Client/Actions/UsersList.php
Original file line number Diff line number Diff line change
Expand Up @@ -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
];
Expand Down
62 changes: 50 additions & 12 deletions Slack/Client/Connection.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

namespace DZunke\SlackBundle\Slack\Client;

use Symfony\Component\HttpFoundation\Request;

class Connection
{
/**
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -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)
Expand All @@ -74,11 +92,11 @@ public function setLimitRetries($retries)
}

/**
* @return int
* @return bool
*/
public function getLimitRetries()
public function getVerifySsl()
{
return $this->limitRetries;
return $this->verifySsl;
}

/**
Expand All @@ -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;
}

/**
Expand Down

0 comments on commit 6d83fb1

Please sign in to comment.