Esempio n. 1
0
 /**
  * Builds token object from raw data
  *
  * @param array $tokenData
  * @return TokenInterface
  */
 public function buildToken(array $tokenData)
 {
     if (empty($tokenData['access_token']) || empty($tokenData['refresh_token']) || empty($tokenData['expires_in']) || empty($tokenData['account_id'])) {
         throw new \InvalidArgumentException();
     }
     $tokenClass = $this->objectMapper->getTokenClass();
     /** @var TokenInterface $token */
     $token = new $tokenClass();
     $token->setAccessToken($tokenData['access_token'])->setRefreshToken($tokenData['refresh_token'])->setExpiresAt($tokenData['expires_in'] + time())->setAccountId($tokenData['account_id']);
     return $token;
 }
Esempio n. 2
0
 /**
  * Builds Image object from raw data
  *
  * @param array $imageData
  * @return ImageInterface
  */
 public function buildImage(array $imageData)
 {
     if (empty($imageData['id'])) {
         throw new \InvalidArgumentException();
     }
     $uploadedAt = new \DateTime();
     $uploadedAt->setTimestamp((int) $imageData['datetime']);
     $imageClass = $this->objectMapper->getImageClass();
     /** @var ImageInterface $image */
     $image = new $imageClass();
     $image->setImageId($imageData['id'])->setTitle($imageData['title'])->setDescription($imageData['description'])->setUploadedAt($uploadedAt)->setType($imageData['type'])->setAnimated($imageData['animated'])->setWidth($imageData['width'])->setHeight($imageData['height'])->setSize($imageData['size'])->setViews($imageData['views'])->setBandwith(!empty($imageData['bandwith']) ? $imageData['bandwith'] : null)->setDeleteHash(!empty($imageData['deletehash']) ? $imageData['deletehash'] : null)->setName(!empty($imageData['name']) ? $imageData['name'] : null)->setSection(!empty($imageData['section']) ? $imageData['section'] : null)->setLink($imageData['link'])->setGifv(!empty($imageData['gifv']) ? $imageData['gifv'] : null)->setMp4(!empty($imageData['mp4']) ? $imageData['mp4'] : null)->setWebm(!empty($imageData['webm']) ? $imageData['webm'] : null)->setLooping(!empty($imageData['looping']) ? $imageData['looping'] : null)->setFavorite($imageData['favorite'])->setNsfw($imageData['nsfw'])->setVote($imageData['vote']);
     return $image;
 }
Esempio n. 3
0
 /**
  * Build Album object from raw data
  * @param array $albumData
  * @return AlbumInterface
  */
 public function buildAlbum(array $albumData)
 {
     if (empty($albumData['id'])) {
         throw new \InvalidArgumentException();
     }
     $insertedIntoGallery = null;
     if (!empty($albumData['datetime'])) {
         $insertedIntoGallery = new \DateTime();
         $insertedIntoGallery->setTimestamp((int) $albumData['datetime']);
     }
     $albumClass = $this->objectMapper->getAlbumClass();
     /** @var AlbumInterface $album */
     $album = new $albumClass();
     $album->setAlbumId($albumData['id'])->setTitle(!empty($albumData['title']) ? $albumData['title'] : null)->setDescription(!empty($albumData['description']) ? $albumData['description'] : null)->setInsertedIntoGallery($insertedIntoGallery)->setCover(!empty($albumData['cover']) ? $albumData['cover'] : null)->setCoverWidth(!empty($albumData['cover_width']) ? $albumData['cover_width'] : null)->setCoverHeight(!empty($albumData['cover_height']) ? $albumData['cover_height'] : null)->setAccountUsername(!empty($albumData['account_url']) ? $albumData['account_url'] : null)->setAccountId(!empty($albumData['account_id']) ? $albumData['account_id'] : null)->setPrivacy(!empty($albumData['privacy']) ? $albumData['privacy'] : null)->setLayout(!empty($albumData['layout']) ? $albumData['layout'] : null)->setViews(!empty($albumData['views']) ? $albumData['views'] : null)->setLink(!empty($albumData['link']) ? $albumData['link'] : null)->setFavorite(!empty($albumData['favorite']) ? $albumData['favorite'] : null)->setNsfw(!empty($albumData['nsfw']) ? $albumData['nsfw'] : null)->setSection(!empty($albumData['section']) ? $albumData['section'] : null)->setOrder(!empty($albumData['order']) ? $albumData['order'] : null)->setDeleteHash(!empty($albumData['deletehash']) ? $albumData['deletehash'] : null)->setImagesCount(!empty($albumData['images_count']) ? $albumData['images_count'] : null);
     $images = [];
     if (!empty($albumData['images'])) {
         foreach ($albumData['images'] as $imageData) {
             $image = $this->imageMapper->buildImage($imageData);
             $images[] = $image;
         }
     }
     $album->setImages($images);
     return $album;
 }