You are here

public function StatusTwitter::sendRequest in Heartbeat 8

File

modules/statusmessage/src/StatusTwitter.php, line 121

Class

StatusTwitter

Namespace

Drupal\statusmessage

Code

public function sendRequest() {
  if ($response = $this
    ->generateRequest($this->parameter)
    ->performRequest()) {
    $data = json_decode($response);
    $tweetNode = $this
      ->setNodeData($data);
    $media = $this
      ->getTweetMedia($data);
    if ($media->images) {
      $tweetNode
        ->set('field_tweet_images', $media->images);
    }
    if ($media->video) {
      $tweetNode
        ->set('field_video', $media->video);
    }
    if ($media->userImage) {
      $tweetNode
        ->set('field_user_image', $media->userImage);
    }
    if ($tweetNode
      ->save()) {
      return $tweetNode
        ->id();
    }
    return null;
  }
}