forked from pgrimaud/instagram-user-feed
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
14 changed files
with
383 additions
and
23 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -2,3 +2,5 @@ | |
vendor | ||
build | ||
.php_cs.cache | ||
cache | ||
!cache/.gitkeep |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
<?php | ||
|
||
require __DIR__ . '/../vendor/autoload.php'; | ||
|
||
$api = new Instagram\Api(); | ||
$api->setUserName('pgrimaud'); | ||
|
||
/** @var \Instagram\Hydrator\Feed $feed */ | ||
$feed = $api->getFeed(); | ||
|
||
foreach ($feed->getMedias() as $media) { | ||
echo $media->getCaption() . "\n"; | ||
} | ||
|
||
$api->setEndCursor($feed->getEndCursor()); | ||
$feed = $api->getFeed(); | ||
|
||
foreach ($feed->getMedias() as $media) { | ||
echo $media->getCaption() . "\n"; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
<?php | ||
|
||
namespace Instagram\Exception; | ||
|
||
class CacheException extends \Exception | ||
{ | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace Instagram\Exception; | ||
|
||
class InstagramException extends \Exception | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,4 +1,5 @@ | ||
<?php | ||
|
||
namespace Instagram\Hydrator; | ||
|
||
class Media | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,69 @@ | ||
<?php | ||
|
||
namespace Instagram\Storage; | ||
|
||
class Cache | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
public $rhxGis; | ||
|
||
/** | ||
* @var int | ||
*/ | ||
public $userId; | ||
|
||
/** | ||
* @var array | ||
*/ | ||
public $cookie = []; | ||
|
||
/** | ||
* @return string | ||
*/ | ||
public function getRhxGis() | ||
{ | ||
return $this->rhxGis; | ||
} | ||
|
||
/** | ||
* @param string $rhxGis | ||
*/ | ||
public function setRhxGis($rhxGis) | ||
{ | ||
$this->rhxGis = $rhxGis; | ||
} | ||
|
||
/** | ||
* @return array | ||
*/ | ||
public function getCookie() | ||
{ | ||
return $this->cookie; | ||
} | ||
|
||
/** | ||
* @param array $cookie | ||
*/ | ||
public function setCookie($cookie) | ||
{ | ||
$this->cookie = $cookie; | ||
} | ||
|
||
/** | ||
* @return int | ||
*/ | ||
public function getUserId() | ||
{ | ||
return $this->userId; | ||
} | ||
|
||
/** | ||
* @param int $userId | ||
*/ | ||
public function setUserId($userId) | ||
{ | ||
$this->userId = $userId; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
<?php | ||
|
||
namespace Instagram\Storage; | ||
|
||
use Instagram\Exception\CacheException; | ||
|
||
class CacheManager | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
private $cacheDir = null; | ||
|
||
/** | ||
* CacheManager constructor. | ||
* @param null $cacheDir | ||
*/ | ||
public function __construct($cacheDir = null) | ||
{ | ||
$this->cacheDir = $cacheDir ?: $this->cacheDir; | ||
} | ||
|
||
/** | ||
* @param $userId | ||
* @return string | ||
*/ | ||
private function getCacheFile($userId) | ||
{ | ||
return ($this->cacheDir ? $this->cacheDir : __DIR__ . '/../../../cache/') . $userId . '.cache'; | ||
} | ||
|
||
/** | ||
* @param $userId | ||
* @return Cache|mixed | ||
*/ | ||
public function getCache($userId) | ||
{ | ||
if (is_file($this->getCacheFile($userId))) { | ||
$handle = fopen($this->getCacheFile($userId), 'r'); | ||
$data = fread($handle, filesize($this->getCacheFile($userId))); | ||
$cache = unserialize($data); | ||
|
||
fclose($handle); | ||
|
||
if ($cache instanceof Cache) { | ||
return $cache; | ||
} | ||
} | ||
|
||
return new Cache(); | ||
} | ||
|
||
/** | ||
* @param Cache $cache | ||
* @param $userName | ||
* @throws CacheException | ||
*/ | ||
public function set(Cache $cache, $userName) | ||
{ | ||
if (!is_writable(dirname($this->getCacheFile($userName)))) { | ||
throw new CacheException('Cache folder is not writable'); | ||
} | ||
|
||
$data = serialize($cache); | ||
$handle = fopen($this->getCacheFile($userName), 'w+'); | ||
|
||
fwrite($handle, $data); | ||
fclose($handle); | ||
} | ||
} |
Oops, something went wrong.