-
Notifications
You must be signed in to change notification settings - Fork 39
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Connor S. Parks
authored and
Connor S. Parks
committed
Sep 28, 2014
0 parents
commit afb2e4b
Showing
9 changed files
with
649 additions
and
0 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,46 @@ | ||
PHP Slack | ||
========= | ||
|
||
> A lightweight PHP implementation of Slack's API. | ||
### Provides | ||
|
||
* Frlnc\Slack\Contracts | ||
|
||
A small set of contracts to allow for the consumption of the Slack API. **Interactor**, **Response** and **ResponseFactory**. | ||
|
||
* **Interactor** is in charge of providing the Http GET/POST methods. | ||
* **Response** is in charge of providing a simple Http response wrapper for holding the body, headers and status code. | ||
* **ResponseFactory** is in charge of providing a factory to instantiate and build the **Response**. | ||
|
||
To use this package, it's simple. Though _please note_ that this implementation is very lightweight meaning you'll need to do some more work than usual. This package doesn't provide methods such as `Chat::postMessage(string message)`, it literally provides one method (`Commander::execute(string command, array parameters = [])`). | ||
|
||
Here is a very simple example of using this package: | ||
```php | ||
<?php | ||
|
||
use Frlnc\Slack\Http\SlackResponseFactory; | ||
use Frlnc\Slack\Http\CurlInteractor; | ||
use Frlnc\Slack\Core\Commander; | ||
|
||
$interactor = new CurlInteractor; | ||
$interactor->setResponseFactory(new SlackResponseFactory); | ||
|
||
$commander = new Commander('xoxp-some-token-for-slack', $interactor); | ||
|
||
$response = $commander->execute('chat.postMessage', [ | ||
'channel' => '#general', | ||
'text' => 'Hello, world!' | ||
]); | ||
|
||
if ($response['ok']) | ||
{ | ||
// Command worked | ||
} | ||
else | ||
{ | ||
// Command didn't work | ||
} | ||
``` | ||
|
||
Note that Commander will automatically format most inputs to Slack's requirements but attachments are not supported - you will need to manually call `$text = Commander::format($text)` to convert it. |
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,25 @@ | ||
{ | ||
"name": "frlnc/php-slack", | ||
"description": "A lightweight PHP implementation of Slack's API.", | ||
"keywords": ["slack"], | ||
"license": "MIT", | ||
"authors": [ | ||
{ | ||
"name": "Connor Parks", | ||
"email": "[email protected]" | ||
} | ||
], | ||
"require": { | ||
"php": ">=5.4.0" | ||
}, | ||
"require-dev": { | ||
"mockery/mockery": "~0.9", | ||
"phpunit/phpunit": "~4.0" | ||
}, | ||
"autoload": { | ||
"psr-4": { | ||
"Frlnc\\Slack\\": "src/" | ||
} | ||
}, | ||
"minimum-stability": "dev" | ||
} |
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,34 @@ | ||
<?php namespace Frlnc\Slack\Contracts\Http; | ||
|
||
interface Interactor { | ||
|
||
/** | ||
* Send a get request to a URL. | ||
* | ||
* @param string $url | ||
* @param array $parameters | ||
* @param array $headers | ||
* @return \Frlnc\Slack\Contracts\Http\Response | ||
*/ | ||
public function get($url, array $parameters = [], array $headers = []); | ||
|
||
/** | ||
* Send a post request to a URL. | ||
* | ||
* @param string $url | ||
* @param array $urlParameters | ||
* @param array $postParameters | ||
* @param array $headers | ||
* @return \Frlnc\Slack\Contracts\Http\Response | ||
*/ | ||
public function post($url, array $urlParameters = [], array $postParameters = [], array $headers = []); | ||
|
||
/** | ||
* Sets the response factory to use. | ||
* | ||
* @param \Frlnc\Slack\Contracts\Http\ResponseFactory $factory | ||
* @return void | ||
*/ | ||
public function setResponseFactory(ResponseFactory $factory); | ||
|
||
} |
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,26 @@ | ||
<?php namespace Frlnc\Slack\Contracts\Http; | ||
|
||
interface Response { | ||
|
||
/** | ||
* Gets the body of the response. | ||
* | ||
* @return string | ||
*/ | ||
public function getBody(); | ||
|
||
/** | ||
* Gets the headers of the response. | ||
* | ||
* @return array | ||
*/ | ||
public function getHeaders(); | ||
|
||
/** | ||
* Gets the status code of the response. | ||
* | ||
* @return integer | ||
*/ | ||
public function getStatusCode(); | ||
|
||
} |
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,15 @@ | ||
<?php namespace Frlnc\Slack\Contracts\Http; | ||
|
||
interface ResponseFactory { | ||
|
||
/** | ||
* Builds the response. | ||
* | ||
* @param string $body | ||
* @param array $headers | ||
* @param integer $statusCode | ||
* @return \Frlnc\Slack\Contracts\Http\Response | ||
*/ | ||
public function build($body, array $headers, $statusCode); | ||
|
||
} |
Oops, something went wrong.