You are here

protected function Instagram::fetch in Drupagram 7

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

Get an array of Instagram objects from an API endpoint

7 calls to Instagram::fetch()
Instagram::self_feed in ./drupagram.lib.php
See the authenticated user's feed. GET /users/self/feed
Instagram::self_liked in ./drupagram.lib.php
See the authenticated user's list of media they've liked. Note that this list is ordered by the order in which the user liked the media. Private media is returned as long as the authenticated user has permission to view that media. Liked…
Instagram::user_feed in ./drupagram.lib.php
Fetch a user's feed
Instagram::user_info in ./drupagram.lib.php
Get basic information about a user.
Instagram::user_lookup in ./drupagram.lib.php

... See full list

File

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

Class

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

Code

protected function fetch($key, $params = array(), $use_auth = TRUE) {
  $results = array();
  if (array_key_exists($key, $this->endpoints)) {
    $path = $this->endpoints[$key];
  }
  else {
    watchdog('drupagram', 'Endpoint key not found: !key', array(
      '!key' => $key,
    ), WATCHDOG_ERROR);
    return FALSE;
  }
  $response = $this
    ->call($path, $params, 'GET', $use_auth);

  // Determine the right class to use when returning the results for this key
  switch ($key) {
    case 'user':
    case 'user_search':
    case 'user_follows':
    case 'user_followed_by':
      $class = 'InstagramUser';
      break;
    default:
      $class = 'InstagramMedia';
      break;
  }
  if (isset($response) && is_array($response)) {
    $response = array_filter($response);
  }

  // Check on successfull call
  if (!empty($response)) {
    foreach ($response as $key => $item) {
      if ($key != 'data') {
        continue;
      }
      elseif (!empty($item) && isset($item[0])) {
        foreach ($item as $object) {
          $results[] = new $class($object);
        }
      }
      else {
        $results[] = new $class($item);
      }
    }
  }

  // Call might return FALSE , e.g. on failed authentication but an exection
  // will be raised, no need for us to do anything special here.
  return $results;
}