public function post(Post $post) { $path = 'blog/' . $this->options['base_hostname'] . '/post'; $method = 'POST'; $params = []; if (!empty($post->tags)) { $params['tags'] = $post->tags; } if (empty($post->media)) { $body = '<p>' . $post->body . '</p>'; $body .= '<strong>' . $post->url . '</strong>'; $params['type'] = 'text'; $params['title'] = $post->title; $params['body'] = $body; } else { $caption = '<h2>' . $post->title . '</h2>'; $caption .= '<p>' . $post->body . '</p>'; $caption .= '<strong>' . $post->url . '</strong>'; $params['type'] = 'photo'; $params['caption'] = $caption; $params['source'] = $post->media[0]; } $result = $this->request($path, $method, $params); $response = new Response(); $response->setRawResponse(json_encode($result)); $result_json = json_decode($result); $response->setProvider('Tumblr'); $response->setPostId($result_json->response->id); return $response; }
public function post(Post $post) { $msg = $post->title; $msg .= "\n\n"; $msg .= $post->body; $msg = trim($msg); if (empty($post->media)) { $path = '/' . $this->getUid() . '/feed'; $params = ['description' => '', 'link' => $post->url, 'message' => $msg]; } else { $path = '/' . $this->getUid() . '/photos'; $msg .= "\n"; $msg .= $post->url; $params = ['url' => $post->media[0], 'caption' => $msg]; } $method = 'POST'; $result = $this->request($path, $method, $params); $json_result = json_decode($result, true); // If there's no ID, the post didn't go through if (!isset($json_result['id'])) { $msg = "Unknown error posting to Facebook profile."; throw new GenericPostingException($msg, 1); } $response = new Response(); $response->setRawResponse($result); // This is already JSON. $response->setProvider('Facebook'); $response->setPostId($json_result['id']); return $response; }
public function post(Post $post) { $page_id = $post->options['page_id']; $path = '/companies/' . $page_id . '/shares?format=json'; $method = 'POST'; $params = ['visibility' => ['code' => 'anyone'], 'comment' => '', 'content' => ['title' => $post->title, 'submitted-url' => $post->url, 'description' => $post->body]]; if (!empty($post->media)) { $params['content']['submitted-image-url'] = $post->media[0]; } $params = json_encode($params); // Linkedin API requires the Content-Type header set to application/json $header = ['Content-Type' => 'application/json']; $result = $this->request($path, $method, $params, $header); // The response comes in JSON $json_result = json_decode($result, true); if (isset($json_result['status']) && $json_result['status'] != 200) { $msg = "Error posting to Linkedin page. Error code from Linkedin: %s. Error message from Linkedin: %s"; $msg = sprintf($msg, $json_result['errorCode'], $json_result['message']); if ($json_result['status'] == '401') { throw new ExpiredTokenException($msg); } else { throw new GenericPostingException($msg, $json_result['status']); } } $response = new Response(); $response->setRawResponse(json_encode($result)); $response->setProvider(static::$provider); $result_json = json_decode($result); $response->setPostId($result_json->updateKey); $response->setPostUrl($result_json->updateUrl); return $response; }
public function post(Post $post) { $path = '/statuses/update.json'; $method = 'POST'; $params = ['status' => $post->body]; if (!empty($post->media)) { $params['media_ids'] = implode(',', $post->media); } $result = $this->request($path, $method, $params); $response = new Response(); $response->setRawResponse(json_encode($result)); $result_json = json_decode($result); $response->setProvider('Twitter'); $response->setPostId($result_json->id_str); return $response; }
public function post(Post $post) { $path = '/people/~/shares?format=json'; $method = 'POST'; $params = ['visibility' => ['code' => 'anyone'], 'comment' => '', 'content' => ['title' => $post->title, 'submitted-url' => $post->url, 'description' => $post->body]]; if (!empty($post->media)) { $params['content']['submitted-image-url'] = $post->media[0]; } $params = json_encode($params); $result = $this->request($path, $method, $params); $response = new Response(); $response->setRawResponse($result); // This is already JSON. $response->setProvider(static::$provider); $result_json = json_decode($result); $response->setPostId($result_json->updateKey); $response->setPostUrl($result_json->updateUrl); return $response; }