You are here

protected function Instagram::request in Drupagram 7

Same name and namespace in other branches
  1. 6 drupagram.lib.php \Instagram::request()

Perform a request

Parameters

string $url:

array $params:

string $method. Can be one of: GET, POST, DELETE or PUT.:

bool $use_auth:

Return value

type

3 calls to Instagram::request()
Instagram::auth_request in ./drupagram.lib.php
Perform an authentication required request.
Instagram::call in ./drupagram.lib.php
Method for calling any drupagram api resource
InstagramOAuth::auth_request in ./drupagram.lib.php
Perform an authentication required request.

File

./drupagram.lib.php, line 379
Classes to implement the full Instagram API

Class

Instagram
Primary Instagram API implementation class Supports the full REST API for drupagram.

Code

protected function request($url, $params = array(), $method = 'GET', $use_auth = FALSE, $headers = array()) {

  // @TODO: GET requests could potentially be cached.
  $data = '';
  if (!is_array($params)) {
    $params = (array) $params;
  }
  if (count($params) > 0) {
    if ($method == 'GET') {
      if (is_array($params) && !empty($params)) {
        $url = format_string($url, $params);
      }
      $url = preg_replace('/&?[a-z_]*=![a-z_]*/', '', $url, -1);
    }
    else {
      $data = http_build_query($params, '', '&');
    }
  }
  if (!is_array($headers)) {
    $headers = (array) $headers;
  }

  // @TODO: implement headers when $use_auth == TRUE
  $response = drupal_http_request($url, array(
    'headers' => $headers,
    'method' => $method,
    'data' => $data,
  ));
  if (!isset($response->error)) {
    return $response->data;
  }
  else {
    throw new InstagramException($response->error);
  }
}