Added campfire plugin to allow pushing messages
This commit is contained in:
parent
3e0f5d793c
commit
5cc9ddb068
114
PHPCI/Plugin/Campfire.php
Normal file
114
PHPCI/Plugin/Campfire.php
Normal file
|
@ -0,0 +1,114 @@
|
|||
<?php
|
||||
|
||||
namespace PHPCI\Plugin;
|
||||
/**
|
||||
* Campfire Plugin - Allows Campfire API actions.
|
||||
* strongly based on icecube (http://labs.mimmin.com/icecube)
|
||||
* @author André Cianfarani <acianfa@gmail.com>
|
||||
* @package PHPCI
|
||||
* @subpackage Plugins
|
||||
*/
|
||||
class Campfire implements \PHPCI\Plugin
|
||||
{
|
||||
private $args;
|
||||
private $config;
|
||||
private $directory;
|
||||
|
||||
private $url;
|
||||
private $authToken;
|
||||
private $userAgent;
|
||||
private $cookie;
|
||||
private $verbose;
|
||||
private $roomId;
|
||||
|
||||
public function __construct(\PHPCI\Builder $phpci, array $options = array())
|
||||
{
|
||||
$this->phpci = $phpci;
|
||||
|
||||
$this->message = $options['message'];
|
||||
$this->userAgent = "Phpci/1.0 (http://www.phptesting.org/)";
|
||||
$this->cookie = "phpcicookie";
|
||||
|
||||
$buildSettings = $phpci->getConfig('build_settings');
|
||||
if (isset($buildSettings['campfire'])) {
|
||||
$campfire = $buildSettings['campfire'];
|
||||
$this->url = $campfire['url'];
|
||||
$this->authToken = $campfire['authToken'];
|
||||
$this->roomId = $campfire['roomId'];
|
||||
} else {
|
||||
throw new \Exception("No connexion parameters given for Campfire plugin");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public function execute()
|
||||
{
|
||||
$this->joinRoom($this->roomId);
|
||||
$status = $this->speak($this->message,$this->roomId);
|
||||
$this->leaveRoom($this->roomId);
|
||||
return $status;
|
||||
|
||||
}
|
||||
public function joinRoom($roomId)
|
||||
{
|
||||
$this->_getPageByPost('/room/'.$roomId.'/join.json');
|
||||
}
|
||||
|
||||
public function leaveRoom($roomId)
|
||||
{
|
||||
$this->_getPageByPost('/room/'.$roomId.'/leave.json');
|
||||
}
|
||||
|
||||
public function logout()
|
||||
{
|
||||
// New API is stateless, no concept of logout
|
||||
}
|
||||
|
||||
public function speak($message, $roomId, $isPaste = false)
|
||||
{
|
||||
$page = '/room/'.$roomId.'/speak.json';
|
||||
if ($isPaste) {
|
||||
$type = 'PasteMessage';
|
||||
} else {
|
||||
$type = 'TextMessage';
|
||||
}
|
||||
return $this->_getPageByPost($page,
|
||||
array('message' => array('type' => $type, 'body' => $message)));
|
||||
|
||||
}
|
||||
|
||||
private function _getPageByPost($page, $data = null)
|
||||
{
|
||||
$url = $this->url . $page;
|
||||
// The new API allows JSON, so we can pass
|
||||
// PHP data structures instead of old school POST
|
||||
$json = json_encode($data);
|
||||
|
||||
// cURL init & config
|
||||
$ch = curl_init();
|
||||
curl_setopt($ch, CURLOPT_URL, $url);
|
||||
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
||||
curl_setopt($ch, CURLOPT_POST,1);
|
||||
curl_setopt($ch, CURLOPT_USERAGENT, $this->userAgent);
|
||||
curl_setopt($ch, CURLOPT_VERBOSE, $this->verbose);
|
||||
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);
|
||||
curl_setopt($ch, CURLOPT_USERPWD, $this->authToken . ':x');
|
||||
curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type: application/json"));
|
||||
curl_setopt($ch, CURLOPT_COOKIEFILE, $this->cookie);
|
||||
|
||||
curl_setopt($ch, CURLOPT_POSTFIELDS,$json);
|
||||
$output = curl_exec($ch);
|
||||
|
||||
curl_close($ch);
|
||||
|
||||
// We tend to get one space with an otherwise blank response
|
||||
$output = trim($output);
|
||||
if (strlen($output)) {
|
||||
/* Responses are JSON. Decode it to a data structure */
|
||||
return json_decode($output);
|
||||
}
|
||||
// Simple 200 OK response (such as for joining a room)
|
||||
// TODO: check for other result codes here
|
||||
return true;
|
||||
}
|
||||
}
|
11
README.md
11
README.md
|
@ -19,6 +19,7 @@ _**Please be aware that PHPCI is a beta-release project, so whilst it is very st
|
|||
* PHP Copy/Paste Detector
|
||||
* PHP Code Sniffer
|
||||
* PHP Spec
|
||||
* Atoum
|
||||
* You can mark directories for the plugins to ignore.
|
||||
* You can mark certain plugins as being allowed to fail (but still run.)
|
||||
|
||||
|
@ -80,8 +81,11 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a
|
|||
mysql:
|
||||
host: "localhost"
|
||||
user: "root"
|
||||
pass: ""
|
||||
|
||||
pass: ""
|
||||
campfire:
|
||||
url: "https://youraccount.campfirenow.com"
|
||||
authToken: "605b32dd"
|
||||
roomId: "570102"
|
||||
setup:
|
||||
mysql:
|
||||
- "DROP DATABASE IF EXISTS test;"
|
||||
|
@ -110,6 +114,9 @@ Similar to Travis CI, to support PHPCI in your project, you simply need to add a
|
|||
complete:
|
||||
mysql:
|
||||
- "DROP DATABASE IF EXISTS test;"
|
||||
failure:
|
||||
campfire:
|
||||
message: "Phpci : build failed."
|
||||
|
||||
As mentioned earlier, PHPCI is powered by plugins, there are several phases in which plugins can be run:
|
||||
|
||||
|
|
Loading…
Reference in a new issue