You are here

class Locations in Instagram API 8

Class Locations.

@package Drupal\instagram_api\Service

Hierarchy

  • class \Drupal\instagram_api\Service\Locations

Expanded class hierarchy of Locations

1 string reference to 'Locations'
instagram_api.services.yml in ./instagram_api.services.yml
instagram_api.services.yml
1 service uses Locations
instagram_api.locations in ./instagram_api.services.yml
Drupal\instagram_api\Service\Locations

File

src/Service/Locations.php, line 12

Namespace

Drupal\instagram_api\Service
View source
class Locations {

  /**
   * Client.
   *
   * @var \Drupal\instagram_api\Service\Client
   */
  protected $client;

  /**
   * Logger Factory.
   *
   * @var \Drupal\Core\Logger\LoggerChannelFactoryInterface
   */
  protected $loggerFactory;

  /**
   * Media constructor.
   *
   * @param \Drupal\instagram_api\Service\Client $client
   *   Client.
   * @param \Drupal\Core\Logger\LoggerChannelFactoryInterface $loggerFactory
   *   LoggerChannelFactory.
   */
  public function __construct(Client $client, LoggerChannelFactoryInterface $loggerFactory) {

    // Instagram API Client.
    $this->client = $client;
    $this->loggerFactory = $loggerFactory;
  }

  /**
   * Get information about a location.
   *
   * @param string $locationId
   *   Location ID.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response array.
   *   https://api.instagram.com/v1/locations/{location-id}?access_token=ACCESS-TOKEN
   *
   * @see https://www.instagram.com/developer/endpoints/locations/
   */
  public function getLocation($locationId, $cacheable = TRUE) {
    $response = $this->client
      ->request('locations/' . $locationId, [], $cacheable);
    if ($response) {
      return $response;
    }
    return FALSE;
  }

  /**
   * Get a list of recent media objects from a given location.
   *
   * @param string $locationId
   *   Location ID.
   * @param array $args
   *   Args, see API docs for options.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response array.
   *   https://api.instagram.com/v1/locations/{location-id}?access_token=ACCESS-TOKEN
   *
   * @see https://www.instagram.com/developer/endpoints/locations/
   */
  public function getLocationMediaRecent($locationId, array $args = [], $cacheable = TRUE) {
    $response = $this->client
      ->request('locations/' . $locationId . '/media/recent', $args, $cacheable);
    if ($response) {
      return $response;
    }
    return FALSE;
  }

  /**
   * Search for a location by geographic coordinate.
   *
   * @param string $lat
   *   Lat.
   * @param string $lng
   *   Lng.
   * @param string $distance
   *   Dist.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response array.
   *   https://api.instagram.com/v1/locations/search?lat=48.858844&lng=2.294351&access_token=ACCESS-TOKEN
   *
   * @see https://www.instagram.com/developer/endpoints/locations/
   */
  public function searchLocation($lat, $lng, $distance = 500, $cacheable = TRUE) {
    $response = $this->client
      ->request('locations/search', [
      'lat' => $lat,
      'lng' => $lng,
      'distance' => $distance,
    ], $cacheable);
    if ($response) {
      return $response;
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Locations::$client protected property Client.
Locations::$loggerFactory protected property Logger Factory.
Locations::getLocation public function Get information about a location.
Locations::getLocationMediaRecent public function Get a list of recent media objects from a given location.
Locations::searchLocation public function Search for a location by geographic coordinate.
Locations::__construct public function Media constructor.