You are here

protected function InstagramRequest::request in Instagram Block 7

Performs a request.

Parameters

string $url:

array $params:

string $method:

Throws

\Exception

2 calls to InstagramRequest::request()
InstagramRequest::requestTagMedia in ./instagram_block.lib.php
Builds a request for {tag} media
InstagramRequest::requestUserMedia in ./instagram_block.lib.php
Builds a request for {user} media.

File

./instagram_block.lib.php, line 71
Instagram classes to integrate with the Instagram API.

Class

InstagramRequest
@file Instagram classes to integrate with the Instagram API.

Code

protected function request($url, $params = array(), $method = 'GET') {
  $data = '';
  if (count($params) > 0) {
    if ($method == 'GET') {
      $url .= '?' . http_build_query($params, '', '&');
    }
    else {
      $data = http_build_query($params, '', '&');
    }
  }
  $headers = array();
  $headers['Authorization'] = 'Oauth';
  $headers['Content-type'] = 'application/x-www-form-urlencoded';
  $response = $this
    ->doRequest($url, $headers, $method, $data);
  if (!isset($response->error)) {
    return $response->data;
  }
  else {
    $error = $response->error;
    if (!empty($response->data)) {
      $data = $this
        ->parse_response($response->data);
      if (isset($data->error)) {
        $error = $data->error;
      }
      elseif (isset($data->meta)) {
        $error = new Exception($data->meta->error_type . ': ' . $data->meta->error_message, $data->meta->code);
      }
    }
    watchdog('instagram_block', $error);
  }
}