You are here

public function TwitterAPIExchange::setPostfields in Twitter Profile Widget 8.2

Same name and namespace in other branches
  1. 8 src/Resources/j7mbo/twitter_api_php/TwitterAPIExchange.php \Drupal\twitter_profile_widget\Resources\j7mbo\twitter_api_php\TwitterAPIExchange::setPostfields()

Set postfields array, example: ['screen_name' => 'J7mbo']

Parameters

array $array Array of parameters to send to API:

Return value

TwitterAPIExchange Instance of self for method chaining

Throws

\Exception When you are trying to set both get and post fields

1 call to TwitterAPIExchange::setPostfields()
TwitterAPIExchange::request in src/Resources/j7mbo/twitter_api_php/TwitterAPIExchange.php
Helper method to perform our request

File

src/Resources/j7mbo/twitter_api_php/TwitterAPIExchange.php, line 112

Class

TwitterAPIExchange
Twitter-API-PHP : Simple PHP wrapper for the v1.1 API

Namespace

Drupal\twitter_profile_widget\Resources\j7mbo\twitter_api_php

Code

public function setPostfields(array $array) {
  if (!is_null($this
    ->getGetfield())) {
    throw new Exception('You can only choose get OR post fields.');
  }
  if (isset($array['status']) && substr($array['status'], 0, 1) === '@') {
    $array['status'] = sprintf("\0%s", $array['status']);
  }
  foreach ($array as $key => &$value) {
    if (is_bool($value)) {
      $value = $value === true ? 'true' : 'false';
    }
  }
  $this->postfields = $array;

  // rebuild oAuth
  if (isset($this->oauth['oauth_signature'])) {
    $this
      ->buildOauth($this->url, $this->requestMethod);
  }
  return $this;
}