示例#1
0
 /**
  * Parse user array
  *
  * @param array $array
  *
  * @return \Evolution7\SocialApi\Entity\Post
  */
 public function parsePostArray($array)
 {
     // Create User
     if (!is_null($array) && array_key_exists('user', $array)) {
         $user = $this->parseUserArray($this->getArrayValue('user', $array));
     } else {
         $user = null;
     }
     // Create Post
     $post = new Post();
     $post->setPlatform(Config::PLATFORM_TWITTER);
     if (!is_null($user)) {
         $post->setUser($user);
     }
     $post->setId($this->getArrayValue('id_str', $array));
     $post->setCreated(new \DateTime($this->getArrayValue('created_at', $array)));
     $post->setBody($this->getArrayValue('text', $array));
     if (!is_null($user)) {
         $post->setUrl('https://twitter.com/' . $user->getHandle() . '/status/' . $post->getId());
     }
     $mediaUrl = $this->getArrayValue(array('entities', 'media', 0, 'media_url'), $array);
     if (!is_null($mediaUrl)) {
         $post->setMediaUrl(str_replace(array('http://', 'https://'), '//', $mediaUrl));
     }
     $this->posts[$post->getId()] = $post;
     return $post;
 }
示例#2
0
 /**
  * {@inheritdoc}
  */
 public function comment(Post $post, $comment)
 {
     // Get post user
     $postUser = $post->getUser();
     // Check comment not empty
     if (empty($comment)) {
         throw new \Exception('Comment invalid - cannot be empty');
     }
     // Check comment contains @mention
     if (strpos($comment, '@' . $postUser->getHandle()) === false) {
         // Invalid comment
         throw new \Exception('Comment invalid - must @mention original post user');
     }
     // Get library service
     $libService = $this->getLibService();
     // Build request url
     $postData = array('status' => $comment, 'in_reply_to_status_id' => $post->getId());
     $requestUrl = 'statuses/update.json?' . http_build_query($postData);
     // Call api
     try {
         $response = new Response($libService->request($requestUrl, 'POST'));
     } catch (\Exception $e) {
         $this->propogateException($e);
     }
     return $response;
 }
示例#3
0
 /**
  * {@inheritdoc}
  */
 public function comment(Post $post, $comment)
 {
     // Get library service
     $libService = $this->getLibService();
     // Build request url/body
     $requestUrl = 'media/' . $post->getId() . '/comments';
     $requestBody = array('text' => $comment);
     // Call api
     try {
         $response = new Response($libService->request($requestUrl, 'POST', $requestBody));
     } catch (\Exception $e) {
         $this->propogateException($e);
     }
     return $response;
 }
示例#4
0
 /**
  * Parse user array
  *
  * @param array $array
  *
  * @return \Evolution7\SocialApi\Entity\Post
  */
 public function parsePostArray($array)
 {
     // Create User
     if (!is_null($array) && array_key_exists('user', $array)) {
         $user = $this->parseUserArray($this->getArrayValue('user', $array));
     } else {
         $user = null;
     }
     // Create Post
     $post = new Post();
     $post->setPlatform(Config::PLATFORM_INSTAGRAM);
     if (!is_null($user)) {
         $post->setUser($user);
     }
     $post->setId($this->getArrayValue('id', $array));
     $post->setCreated(new \DateTime(date(DATE_ISO8601, $array['created_time'])));
     if (is_array($this->getArrayValue('caption', $array))) {
         $post->setBody($array['caption']['text']);
     } else {
         $post->setBody($array['caption']);
     }
     $post->setUrl($this->getArrayValue('link', $array));
     $post->setMediaType($this->getArrayValue('type', $array));
     $mediaUrl = $this->getArrayValue(array($post->getMediaType() . 's', 'standard_resolution', 'url'), $array);
     if (!is_null($mediaUrl)) {
         $post->setMediaUrl(str_replace(array('http://', 'https://'), '//', $mediaUrl));
     }
     $this->posts[$post->getId()] = $post;
     return $post;
 }