diff --git a/custom/Action/Multipost.php b/custom/Action/Multipost.php new file mode 100644 index 0000000..e61345e --- /dev/null +++ b/custom/Action/Multipost.php @@ -0,0 +1,94 @@ + + * @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(); + } + +} + diff --git a/custom/Config/actions.xml b/custom/Config/actions.xml index 035ebdb..2004791 100755 --- a/custom/Config/actions.xml +++ b/custom/Config/actions.xml @@ -118,5 +118,23 @@ + + multi_post + 1 + 1 + Post a new message to multiple services + /:userid/messages + d31eba41d3c31653ae1b26d18e8a10dd7d266253 + + + content + 1 + + + services + 1 + + + diff --git a/custom/Model/Spaz/LinkedIn.php b/custom/Model/Spaz/LinkedIn.php new file mode 100644 index 0000000..e74f1e9 --- /dev/null +++ b/custom/Model/Spaz/LinkedIn.php @@ -0,0 +1,87 @@ +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();*/ + } + +} \ No newline at end of file diff --git a/custom/Model/Spaz/Posterous.php b/custom/Model/Spaz/Posterous.php new file mode 100644 index 0000000..f370f6d --- /dev/null +++ b/custom/Model/Spaz/Posterous.php @@ -0,0 +1,81 @@ +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();*/ + } + +} \ No newline at end of file diff --git a/custom/Model/Spaz/SpazMultiPost_Interface.php b/custom/Model/Spaz/SpazMultiPost_Interface.php new file mode 100644 index 0000000..bb904e9 --- /dev/null +++ b/custom/Model/Spaz/SpazMultiPost_Interface.php @@ -0,0 +1,10 @@ +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; + } + +} \ No newline at end of file