Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Connor S. Parks authored and Connor S. Parks committed Sep 28, 2014
0 parents commit afb2e4b
Show file tree
Hide file tree
Showing 9 changed files with 649 additions and 0 deletions.
46 changes: 46 additions & 0 deletions README.md
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.
25 changes: 25 additions & 0 deletions composer.json
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"
}
34 changes: 34 additions & 0 deletions src/Contracts/Http/Interactor.php
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);

}
26 changes: 26 additions & 0 deletions src/Contracts/Http/Response.php
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();

}
15 changes: 15 additions & 0 deletions src/Contracts/Http/ResponseFactory.php
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);

}
Loading

0 comments on commit afb2e4b

Please sign in to comment.