Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
94 changes: 94 additions & 0 deletions custom/Action/Multipost.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,94 @@
<?php

/**
* Action Unreadsync
*
* Sync unread message status
*
* @link http://getfrapi.com
* @author Frapi <frapi@getfrapi.com>
* @link /sync
*/
class Action_Multipost extends Frapi_Action implements Frapi_Action_Interface
{

/**
* Required parameters
*
* @var An array of required parameters.
*/
protected $requiredParams = array('username', 'content', 'services');

/**
* The data container to use in toArray()
*
* @var A container of data to fill and return in toArray()
*/
private $data = array();

/**
* To Array
*
* This method returns the value found in the database
* into an associative array.
*
* @return array
*/
public function toArray()
{
return $this->data;
}

/**
* Default Call Method
*
* This method is called when no specific request handler has been found
*
* @return array
*/
public function executeAction()
{
throw new Frapi_Error('NOT_IMPLEMENTED');
}

/**
* Get Request Handler
*
* This method is called when a request is a GET
*
* @return array
*/
public function executeGet()
{
throw new Frapi_Error('NOT_IMPLEMENTED');
}

/**
* Post Request Handler
*
*
*
* @return array
*/
public function executePost()
{
$valid = $this->hasRequiredParameters($this->requiredParams);
if ($valid instanceof Frapi_Error) {
return $valid;
}
$message = $this->getParam('content', self::TYPE_STRING);
foreach ($this->getParam('services') as $service => $authData) {
$serviceHandlerClass = 'Spaz' . $service;
$serviceHandler = new $serviceHandlerClass;
try {
$data[] = $serviceHandler->send($message, $authData);
} catch (Exception $e) {
throw new Frapi_Error($e->getMessage());
}
}

return $this->toArray();
}

}

18 changes: 18 additions & 0 deletions custom/Config/actions.xml
Original file line number Diff line number Diff line change
Expand Up @@ -118,5 +118,23 @@
</parameter>
</parameters>
</action>
<action>
<name>multi_post</name>
<enabled>1</enabled>
<public>1</public>
<description>Post a new message to multiple services</description>
<route>/:userid/messages</route>
<hash>d31eba41d3c31653ae1b26d18e8a10dd7d266253</hash>
<parameters>
<parameter>
<name>content</name>
<required>1</required>
</parameter>
<parameter>
<name>services</name>
<required>1</required>
</parameter>
</parameters>
</action>
</actions>
</frapi-config>
87 changes: 87 additions & 0 deletions custom/Model/Spaz/LinkedIn.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,87 @@
<?php

/**
* Implements pass-through posting to LinkedIn API from the Spaz web API.
*
* @author Brian Fenton
*/
class SpazLinkedIn implements SpazMultiPost_Interface
{
/**
* Visibility settings for comments
*/
const VISIBLE_ANYONE = 'anyone';
const VISIBLE_CONNECTIONS = 'connections-only';

/**
* Curl handler. Will eventually replace with pecl_http
* @var resource
*/
protected $curl;
/**
* API resource URI for posts on LinkedIn
* @var string
*/
protected $apiUrl = 'http://api.linkedin.com/v1/people/~/shares';

public function __construct()
{
$this->curl = curl_init();
}

/**
* Adds a new Share to the user's LinkedIn account.
*
* Allowed metadata:
* visibility (boolean) - Whether share is visible to everyone. Default: true
* title (string) - must also include url if this is set
* url (string) - URL to share
* image_url (string) - URL of image to share along with title/url
* description (string) - description of share (optional). Max 400 chars.
*
* @param string $message
* @param array $metaData
* @param array $authData Required OAuth credentials
* @return string
*
*/
public function send($message, $metaData, $authData)
{
$postData = array(
'comment' => $message,
'visibility' => array(
'code' => ($metaData['visibility']) ? self::VISIBLE_ANYONE : self::VISIBLE_CONNECTIONS,
),
);
if (!empty($metaData['title']) && !empty($metaData['url'])) {
$postData['content'] = array(
'title' => $metaData['title'],
'submitted-url' => $metaData['url'],
);
if (!empty($metaData['image_url'])) {
$postData['content']['submitted-image-url'] = $metaData['image_url'];
}
if (!empty($metaData['description'])) {
$postData['content']['description'] = $metaData['description'];
}
}
$curlOpts = array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => json_encode($postData),
CURLOPT_URL => $this->apiUrl,
CURLOPT_HTTPHEADER => 'Content-Type: application/json',
);
curl_setopt_array($this->curl, $curlOpts);
$data = curl_exec($this->curl);
curl_close($this->curl);
return $data;

/*$http = new HttpRequest($this->apiUrl, HttpRequest::METH_POST);
$http->setContentType('application/json');
$http->setRawPostData(json_encode($postData));
$http->send();
return $http->getResponseData();*/
}

}
81 changes: 81 additions & 0 deletions custom/Model/Spaz/Posterous.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,81 @@
<?php

class SpazPosterous implements SpazMultiPost_Interface
{

/**
* Curl handler. Will eventually replace with pecl_http
* @var resource
*/
protected $curl;
/**
* API resource URI for uploads on Posterous
* @var string
*/
protected $apiUrl = 'https://posterous.com/api2/upload.json';

public function __construct()
{
$this->curl = curl_init();
}

/**
* Adds a new upload to the user's Posterous account.
*
* Allowed metadata:
* title (string) - title for post/upload
* media (array) - one or more paths of files to post (audio, images, video, docs, etc...)
*
* @param string $message
* @param array $metaData
* @param array $authData Required OAuth credentials (passed to Twitter)
* @return string
*
* @todo add mime type guessing
*/
public function send($message, $metaData, $authData)
{
$postData = array(
'message' => $metaData['title'],
'body' => $message,
'source' => 'Spaz',
'sourceLink' => 'http://www.getspaz.com',
);
if (!empty($metaData['media']) && is_array($metaData['media'])) {
//append @ so curl knows to treat them as files
foreach ($metaData['media'] as &$path) {
$path = '@' . $path;
}
$postData['media'] = $metaData['media'];
}
$headers = array(
'X-Auth-Service-Provider: https://api.twitter.com/1/account/verify_credentials.json',
'X-Verify-Credentials-Authorization: ' . $authData, //signed OAuth "Authorization" header typically used to call the verify_credentials.json endpoint',
);
$curlOpts = array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => $postData,
CURLOPT_URL => $this->apiUrl,
CURLOPT_HTTPHEADER => $headers,
);
curl_setopt_array($this->curl, $curlOpts);
$data = curl_exec($this->curl);
curl_close($this->curl);
return $data;

/*$headers = array(
'X-Auth-Service-Provider' => 'https://api.twitter.com/1/account/verify_credentials.json',
'X-Verify-Credentials-Authorization' => $authData,
);
$media = $postData['media'];
unset($postData['media']);
$http = new HttpRequest($this->apiUrl, HttpRequest::METH_POST);
$http->setPostFields($postData);
$http->setPostFiles($media);
$http->setHeaders($headers);
$http->send();
return $http->getResponseData();*/
}

}
10 changes: 10 additions & 0 deletions custom/Model/Spaz/SpazMultiPost_Interface.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
<?php

/**
*
* @author brianfenton
*/
interface SpazMultiPost_Interface
{
function send($message, $metaData, $authData);
}
39 changes: 39 additions & 0 deletions custom/Model/Spaz/Tumblr.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
<?php

class SpazTumblr implements SpazMultiPost_Interface
{
const POST_TYPE_REGULAR = 'regular';
const FORMAT_MARKDOWN = 'markdown';
const FORMAT_HTML = 'html';

protected $curl;
protected $apiUrl = 'http://www.tumblr.com/api/write';

public function __construct()
{
$this->curl = curl_init();
}

public function send($message, $metaData, $authData)
{
$postData = array(
'email' => $authData['email'],
'password' => $authData['password'],
'type' => self::POST_TYPE_REGULAR,
'title' => $metaData['title'],
'body' => $message,
'format' => self::FORMAT_MARKDOWN,
);
$curlOpts = array(
CURLOPT_POST => true,
CURLOPT_RETURNTRANSFER => true,
CURLOPT_POSTFIELDS => urlencode(implode('&', $postData)),
CURLOPT_URL => $this->apiUrl,
);
curl_setopt_array($this->curl, $curlOpts);
$data = curl_exec($this->curl);
curl_close($this->curl);
return $data;
}

}