diff --git a/.gitignore b/.gitignore index 3e5d470..b7d3bf0 100644 --- a/.gitignore +++ b/.gitignore @@ -8,3 +8,5 @@ TODO.md .php_cs .php_cs.cache + +.idea/ diff --git a/src/Client/Features/FeedFeaturesTrait.php b/src/Client/Features/FeedFeaturesTrait.php index d4faec1..c14cf14 100644 --- a/src/Client/Features/FeedFeaturesTrait.php +++ b/src/Client/Features/FeedFeaturesTrait.php @@ -11,6 +11,7 @@ use Instagram\SDK\Response\Responses\Feed\FeedResponse; use Instagram\SDK\Response\Responses\Feed\TimelineResponse; use const Instagram\SDK\TYPE_HASHTAG; +use const Instagram\SDK\TYPE_LOCATION; use const Instagram\SDK\TYPE_USER; /** @@ -34,6 +35,17 @@ public function feedByHashtag(string $hashTag): PromiseInterface return $this->feed(TYPE_HASHTAG, $hashTag); } + /** + * Retrieve feed by hashtag. + * + * @param string $locationId + * @return PromiseInterface + */ + public function feedByLocation(string $locationId): PromiseInterface + { + return $this->feed(TYPE_LOCATION, $locationId); + } + /** * Retrieve feed by user id. * @@ -62,6 +74,9 @@ public function feed(int $type, string $query, ?string $maxId = null): PromiseIn case TYPE_USER: $result = $this->queryFeed($type, 'feed/user/%s/', $query, $maxId); break; + case TYPE_LOCATION: + $result = $this->queryFeed($type, 'feed/location/%s/', $query, $maxId); + break; default: $result = $this->getInvalidFeedTypeError(); break; diff --git a/src/Response/DTO/General/Media/Caption.php b/src/Response/DTO/General/Media/Caption.php new file mode 100644 index 0000000..c31a846 --- /dev/null +++ b/src/Response/DTO/General/Media/Caption.php @@ -0,0 +1,185 @@ +pk; + } + + /** + * @return int + */ + public function getUserId(): int + { + return $this->user_id; + } + + /** + * @return string + */ + public function getText(): string + { + return $this->text; + } + + /** + * @return int + */ + public function getType(): int + { + return $this->type; + } + + /** + * @return int + */ + public function getCreatedAt(): int + { + return $this->created_at; + } + + /** + * @return int + */ + public function getCreatedAtUtc(): int + { + return $this->created_at_utc; + } + + /** + * @return string + */ + public function getContentType(): string + { + return $this->content_type; + } + + /** + * @return string + */ + public function getStatus(): string + { + return $this->status; + } + + /** + * @return int + */ + public function getBitFlags(): int + { + return $this->bit_flags; + } + + /** + * @return bool + */ + public function isDidReportAsSpam(): bool + { + return $this->did_report_as_spam; + } + + /** + * @return bool + */ + public function isShareEnabled(): bool + { + return $this->share_enabled; + } + + /** + * @return User + */ + public function getUser(): User + { + return $this->user; + } + + /** + * @return bool + */ + public function isIsCovered(): bool + { + return $this->is_covered; + } + + /** + * @return int + */ + public function getMediaId(): int + { + return $this->media_id; + } + + /** + * @return bool + */ + public function isHasTranslation(): bool + { + return $this->has_translation; + } + + /** + * @return int + */ + public function getPrivateReplyStatus(): int + { + return $this->private_reply_status; + } + +} diff --git a/src/Response/DTO/General/Media/CarouselMedia.php b/src/Response/DTO/General/Media/CarouselMedia.php new file mode 100644 index 0000000..c06f569 --- /dev/null +++ b/src/Response/DTO/General/Media/CarouselMedia.php @@ -0,0 +1,138 @@ +id; + } + + /** + * @return int + */ + public function getPk(): int + { + return $this->pk; + } + + /** + * @return int + */ + public function getMediaType(): int + { + return $this->media_type; + } + + /** + * @return ImageVersions2|null + */ + public function getImageVersions2(): ?ImageVersions2 + { + return $this->image_versions2; + } + + /** + * @return VideoVersion[]|null + */ + public function getVideoVersions(): ?array + { + return $this->video_versions; + } + + /** + * @return int + */ + public function getOriginalWidth(): int + { + return $this->original_width; + } + + /** + * @return int + */ + public function getOriginalHeight(): int + { + return $this->original_height; + } + + /** + * @return string + */ + public function getCarouselParentId(): string + { + return $this->carousel_parent_id; + } + + /** + * @return bool + */ + public function isCanSeeInsightsAsBrand(): bool + { + return $this->can_see_insights_as_brand; + } + + /** + * @return bool + */ + public function isIsCommercial(): bool + { + return $this->is_commercial; + } + +} diff --git a/src/Response/DTO/General/Media/ImageVersions2.php b/src/Response/DTO/General/Media/ImageVersions2.php index 61a4843..aba7c16 100644 --- a/src/Response/DTO/General/Media/ImageVersions2.php +++ b/src/Response/DTO/General/Media/ImageVersions2.php @@ -11,7 +11,6 @@ */ final class ImageVersions2 { - /** * @var Image[] */ diff --git a/src/Response/DTO/General/Media/Location.php b/src/Response/DTO/General/Media/Location.php new file mode 100644 index 0000000..9a65211 --- /dev/null +++ b/src/Response/DTO/General/Media/Location.php @@ -0,0 +1,117 @@ +pk; + } + + /** + * @return string + */ + public function getShortName(): string + { + return $this->short_name; + } + + /** + * @return int + */ + public function getFacebookPlacesId(): int + { + return $this->facebook_places_id; + } + + /** + * @return string + */ + public function getExternalSource(): string + { + return $this->external_source; + } + + /** + * @return string + */ + public function getName(): string + { + return $this->name; + } + + /** + * @return string + */ + public function getAddress(): string + { + return $this->address; + } + + /** + * @return string + */ + public function getCity(): string + { + return $this->city; + } + + /** + * @return float|null + */ + public function getLng(): ?float + { + return $this->lng; + } + + /** + * @return float|null + */ + public function getLat(): ?float + { + return $this->lat; + } + + /** + * @return bool + */ + public function isIsEligibleForGuides(): bool + { + return $this->is_eligible_for_guides; + } + +} diff --git a/src/Response/DTO/General/Media/VideoVersion.php b/src/Response/DTO/General/Media/VideoVersion.php index ed3d5f2..677257c 100644 --- a/src/Response/DTO/General/Media/VideoVersion.php +++ b/src/Response/DTO/General/Media/VideoVersion.php @@ -2,7 +2,7 @@ declare(strict_types=1); -namespace Instagram\SDK\DTO\General\Media; +namespace Instagram\SDK\Response\DTO\General\Media; /** * Class VideoVersion @@ -11,6 +11,10 @@ */ final class VideoVersion { + /** + * @var string + */ + private $id; /** * @var int @@ -18,12 +22,12 @@ final class VideoVersion private $type; /** - * @var float + * @var int */ private $width; /** - * @var float + * @var int */ private $height; @@ -32,6 +36,14 @@ final class VideoVersion */ private $url; + /** + * @return string + */ + public function getId(): string + { + return $this->id; + } + /** * @return int */ @@ -41,17 +53,17 @@ public function getType(): int } /** - * @return float + * @return int */ - public function getWidth(): float + public function getWidth(): int { return $this->width; } /** - * @return float + * @return int */ - public function getHeight(): float + public function getHeight(): int { return $this->height; } diff --git a/src/Response/DTO/General/User.php b/src/Response/DTO/General/User.php index 84c3b65..482c8fd 100644 --- a/src/Response/DTO/General/User.php +++ b/src/Response/DTO/General/User.php @@ -126,9 +126,9 @@ public function isPrivate(): bool } /** - * @return string + * @return string|null */ - public function getProfilePictureUrl(): string + public function getProfilePictureUrl(): ?string { return $this->profilePictureUrl; } diff --git a/src/Response/DTO/Hashtag/Item.php b/src/Response/DTO/Hashtag/Item.php index 364d240..864f206 100644 --- a/src/Response/DTO/Hashtag/Item.php +++ b/src/Response/DTO/Hashtag/Item.php @@ -4,7 +4,12 @@ namespace Instagram\SDK\Response\DTO\Hashtag; +use Instagram\SDK\Response\DTO\General\Media\Caption; +use Instagram\SDK\Response\DTO\General\Media\CarouselMedia; use Instagram\SDK\Response\DTO\General\Media\ImageVersions2; +use Instagram\SDK\Response\DTO\General\Media\Location; +use Instagram\SDK\Response\DTO\General\Media\VideoVersion; +use Instagram\SDK\Response\DTO\General\User; /** * Class Item @@ -13,7 +18,6 @@ */ final class Item { - /** * @var float */ @@ -55,10 +59,15 @@ final class Item private $filterType; /** - * @var ImageVersions2[] + * @var ImageVersions2|null */ private $imageVersions2; + /** + * @var CarouselMedia[]|null + */ + private $carousel_media; + /** * @var float */ @@ -70,7 +79,7 @@ final class Item private $originalHeight; /** - * @var object + * @var VideoVersion[]|null */ private $videoVersions; @@ -80,22 +89,37 @@ final class Item private $hasAudio; /** - * @var int + * @var int|null */ private $videoDuration; /** - * @var int + * @var int|null */ private $viewCount; /** - * @var object // TODO + * @var Location|null + */ + private $location; + + /** + * @var float|null + */ + private $lng; + + /** + * @var float|null + */ + private $lat; + + /** + * @var User */ private $user; /** - * @var object // TODO + * @var Caption */ private $caption; @@ -140,7 +164,7 @@ final class Item private $maxNumVisiblePreviewComments; /** - * @var int + * @var int|null */ private $commentCount; @@ -159,6 +183,11 @@ final class Item */ private $organicTrackingToken; + /** + * @var string|null + */ + private $productType; + /** * @return int */ @@ -224,13 +253,21 @@ public function getFilterType(): int } /** - * @return ImageVersions2[] + * @return ImageVersions2 */ - public function getImageVersions2(): array + public function getImageVersions2(): ?ImageVersions2 { return $this->imageVersions2; } + /** + * @return CarouselMedia[] + */ + public function getCarouselMedia(): ?array + { + return $this->carousel_media; + } + /** * @return float */ @@ -248,9 +285,9 @@ public function getOriginalHeight(): float } /** - * @return object + * @return VideoVersion[]|null */ - public function getVideoVersions(): object + public function getVideoVersions(): ?array { return $this->videoVersions; } @@ -280,17 +317,41 @@ public function getViewCount(): int } /** - * @return object + * @return Location|null + */ + public function getLocation(): ?Location + { + return $this->location; + } + + /** + * @return float|null + */ + public function getLng(): ?float + { + return $this->lng; + } + + /** + * @return float|null */ - public function getUser(): object + public function getLat(): ?float + { + return $this->lat; + } + + /** + * @return User + */ + public function getUser(): User { return $this->user; } /** - * @return object + * @return Caption|null */ - public function getCaption(): object + public function getCaption(): ?Caption { return $this->caption; } @@ -360,9 +421,9 @@ public function getMaxNumVisiblePreviewComments(): int } /** - * @return int + * @return int|null */ - public function getCommentCount(): int + public function getCommentCount(): ?int { return $this->commentCount; } @@ -390,4 +451,12 @@ public function getOrganicTrackingToken(): string { return $this->organicTrackingToken; } + + /** + * @return string|null + */ + public function getProductType(): ?string + { + return $this->productType; + } } diff --git a/src/Response/DTO/Interfaces/UserInterface.php b/src/Response/DTO/Interfaces/UserInterface.php index 4a715ec..671bc0e 100644 --- a/src/Response/DTO/Interfaces/UserInterface.php +++ b/src/Response/DTO/Interfaces/UserInterface.php @@ -43,9 +43,9 @@ public function isPrivate(): bool; /** * Returns the profile picture url. * - * @return string + * @return string|null */ - public function getProfilePictureUrl(): string; + public function getProfilePictureUrl(): ?string; /** * Returns true if the profile has a anonymous profile picture, false otherwise. diff --git a/src/Response/Responses/ResponseEnvelope.php b/src/Response/Responses/ResponseEnvelope.php index 4b8fd66..74d1185 100644 --- a/src/Response/Responses/ResponseEnvelope.php +++ b/src/Response/Responses/ResponseEnvelope.php @@ -4,6 +4,8 @@ namespace Instagram\SDK\Response\Responses; +use Psr\Http\Message\ResponseInterface as HttpResponseInterface; + /** * Class ResponseEnvelope * @@ -27,6 +29,9 @@ abstract class ResponseEnvelope implements ResponseInterface /** @var bool */ protected $invalidCredentials; + /** @var HttpResponseInterface|null */ + protected $rawResponse; + /** * @return string|null */ @@ -68,4 +73,18 @@ public function isSuccess(): bool { return $this->status === static::STATUS_SUCCESS; } + + /** @inheritdoc */ + public function getRawResponse(): HttpResponseInterface + { + return $this->rawResponse; + } + + /** @inheritdoc */ + public function setRawResponse(HttpResponseInterface $response): ResponseInterface + { + $this->rawResponse = $response; + + return $this; + } } diff --git a/src/Response/Responses/ResponseInterface.php b/src/Response/Responses/ResponseInterface.php index 0e7013c..f4090ec 100644 --- a/src/Response/Responses/ResponseInterface.php +++ b/src/Response/Responses/ResponseInterface.php @@ -4,6 +4,8 @@ namespace Instagram\SDK\Response\Responses; +use Psr\Http\Message\ResponseInterface as HttpResponseInterface; + /** * Interface ResponseInterface * @@ -11,9 +13,16 @@ */ interface ResponseInterface { - - - - - + /** + * raw http response getter, useful for debugging, using not implemented things + * + * @return HttpResponseInterface + */ + public function getRawResponse(): HttpResponseInterface; + + /** + * @param HttpResponseInterface $response + * @return ResponseInterface + */ + public function setRawResponse(HttpResponseInterface $response): ResponseInterface; } diff --git a/src/Response/Responses/User/AuthenticatedUserResponse.php b/src/Response/Responses/User/AuthenticatedUserResponse.php index a134b56..81f0146 100644 --- a/src/Response/Responses/User/AuthenticatedUserResponse.php +++ b/src/Response/Responses/User/AuthenticatedUserResponse.php @@ -6,6 +6,7 @@ use Instagram\SDK\Response\Responses\ResponseInterface; use Instagram\SDK\Session\Session; +use Psr\Http\Message\ResponseInterface as HttpResponseInterface; /** * Class AuthenticatedUserResponse @@ -18,6 +19,9 @@ class AuthenticatedUserResponse implements ResponseInterface /** @var Session */ private $session; + /** @var HttpResponseInterface */ + protected $rawResponse; + /** * AuthenticatedUserResponse constructor. * @@ -35,4 +39,18 @@ public function getSession(): Session { return $this->session; } + + /** @inheritdoc */ + public function getRawResponse(): HttpResponseInterface + { + return $this->rawResponse; + } + + /** @inheritdoc */ + public function setRawResponse(HttpResponseInterface $response): ResponseInterface + { + $this->rawResponse = $response; + + return $this; + } } diff --git a/src/Response/Serializers/AbstractResponseSerializer.php b/src/Response/Serializers/AbstractResponseSerializer.php index 8ece22d..722e7dd 100644 --- a/src/Response/Serializers/AbstractResponseSerializer.php +++ b/src/Response/Serializers/AbstractResponseSerializer.php @@ -53,7 +53,11 @@ public function decode(HttpResponseInterface $response, Client $client): Respons ->setReaderContext(new OnDecodeContext($client)) ->build(); - $gson->fromJson((string)$response->getBody(), $responseInstance); + $body = (string)$response->getBody(); + + $gson->fromJson($body, $responseInstance); + + $responseInstance->setRawResponse($response); if (!self::isValidResponse($responseInstance)) { throw $this->toException($responseInstance->getErrorType(), $responseInstance); diff --git a/src/Traits/MakeFeedRequestsAccessible.php b/src/Traits/MakeFeedRequestsAccessible.php index 9a4d535..149dc04 100644 --- a/src/Traits/MakeFeedRequestsAccessible.php +++ b/src/Traits/MakeFeedRequestsAccessible.php @@ -12,6 +12,7 @@ use Instagram\SDK\Response\Responses\Feed\TimelineResponse; use Instagram\SDK\Utils\PromiseUtils; use const Instagram\SDK\TYPE_HASHTAG; +use const Instagram\SDK\TYPE_LOCATION; use const Instagram\SDK\TYPE_USER; /** @@ -34,6 +35,18 @@ public function feedByHashtag(string $tag): FeedResponse return PromiseUtils::wait($this->feedByHashtagPromise($tag)); } + /** + * Retrieves feed by location. + * + * @param string $locationId + * @return FeedResponse + * @throws InstagramException in case of an error + */ + public function feedByLocation(string $locationId): FeedResponse + { + return PromiseUtils::wait($this->feedByLocationPromise($locationId)); + } + /** * Retrieves feed by hashtag. * @@ -45,6 +58,17 @@ public function feedByHashtagPromise(string $tag): PromiseInterface return $this->feed(TYPE_HASHTAG, $tag); } + /** + * Retrieves feed by location. + * + * @param string $locationId + * @return PromiseInterface + */ + public function feedByLocationPromise(string $locationId): PromiseInterface + { + return $this->feed(TYPE_LOCATION, $locationId); + } + /** * Retrieves feed by user. * diff --git a/src/definitions.php b/src/definitions.php index 753eb3c..2537aa3 100644 --- a/src/definitions.php +++ b/src/definitions.php @@ -9,3 +9,6 @@ /** @var int The user feed type */ const TYPE_USER = 2; + +/** @var int The hashtag feed type */ +const TYPE_LOCATION = 3;