You are here

class Photos in Flickr API Integration 8

Class Photos.

@package Drupal\flickr_api\Service

Hierarchy

  • class \Drupal\flickr_api\Service\Photos

Expanded class hierarchy of Photos

1 string reference to 'Photos'
flickr_api.services.yml in ./flickr_api.services.yml
flickr_api.services.yml
1 service uses Photos
flickr_api.photos in ./flickr_api.services.yml
Drupal\flickr_api\Service\Photos

File

src/Service/Photos.php, line 10

Namespace

Drupal\flickr_api\Service
View source
class Photos {

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

  /**
   * Photos constructor.
   *
   * @param \Drupal\flickr_api\Service\Client $client
   *   Client.
   */
  public function __construct(Client $client) {

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

  /**
   * Get information about a photo.
   *
   * @param string $photo_id
   *   ID of the photo to get info about.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response from the flickr method flickr.photos.getInfo..
   *   (https://www.flickr.com/services/api/flickr.photos.getInfo.html)
   */
  public function photosGetInfo($photo_id, $cacheable = TRUE) {
    $args = [
      'photo_id' => $photo_id,
    ];
    $response = $this->client
      ->request('flickr.photos.getInfo', $args, $cacheable);
    if ($response) {
      return $response['photo'];
    }
    return FALSE;
  }

  /**
   * Returns the available sizes for a photo.
   *
   * @param string $photo_id
   *   ID of the photo to get the available sizes of.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response from the flickr method flickr.photos.getSizes..
   *   (https://www.flickr.com/services/api/flickr.photos.getSizes.html)
   */
  public function photosGetSizes($photo_id, $cacheable = TRUE) {
    $args = [
      'photo_id' => $photo_id,
    ];
    $response = $this->client
      ->request('flickr.photos.getSizes', $args, $cacheable);
    if ($response) {
      return $response['sizes']['size'];
    }
    return FALSE;
  }

  /**
   * Return a list of photos matching some criteria.
   *
   * @param string $nsid
   *   NSID of the user whose photoset tags will be returned.
   * @param int $page
   *   Page of results to return.
   * @param array $otherArgs
   *   Other args.
   * @param bool $cacheable
   *   Cacheable.
   *
   * @return array|bool
   *   Response from the flickr method flickr.photos.search.
   *   (https://www.flickr.com/services/api/flickr.photos.search.html)
   */
  public function photosSearch($nsid, $page = 1, array $otherArgs = [], $cacheable = TRUE) {
    $args = [
      'page' => $page,
      'user_id' => $nsid,
    ];
    $args = array_merge($args, $otherArgs);

    // Set per_page to flickr_api module default if not specified in $args.
    if (!isset($args['per_page'])) {

      // TODO Expose pager as a setting.
      $args['per_page'] = 6;
    }
    $response = $this->client
      ->request('flickr.photos.search', $args, $cacheable);
    if ($response) {
      return $response['photos'];
    }
    return FALSE;
  }

}

Members

Namesort descending Modifiers Type Description Overrides
Photos::$client protected property Client.
Photos::photosGetInfo public function Get information about a photo.
Photos::photosGetSizes public function Returns the available sizes for a photo.
Photos::photosSearch public function Return a list of photos matching some criteria.
Photos::__construct public function Photos constructor.