Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Right names for models #240

Merged
merged 1 commit into from
Dec 14, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 5 additions & 4 deletions src/InstagramScraper/Instagram.php
Original file line number Diff line number Diff line change
Expand Up @@ -12,6 +12,7 @@
use InstagramScraper\Model\Media;
use InstagramScraper\Model\Story;
use InstagramScraper\Model\Tag;
use InstagramScraper\Model\UserStories;
use phpFastCache\CacheManager;
use Unirest\Request;

Expand Down Expand Up @@ -934,12 +935,12 @@ public function getStories()

$stories = [];
foreach ($jsonResponse['data']['reels_media'] as $user) {
$Story = Story::create();
$Story->setOwner(Account::create($user['user']));
$UserStories = UserStories::create();
$UserStories->setOwner(Account::create($user['user']));
foreach ($user['items'] as $item) {
$Story->addStory(Media::create($item));
$UserStories->addStory(Story::create($item));
}
$stories[] = $Story;
$stories[] = $UserStories;
}
return $stories;
}
Expand Down
47 changes: 18 additions & 29 deletions src/InstagramScraper/Model/Story.php
Original file line number Diff line number Diff line change
Expand Up @@ -6,36 +6,25 @@
* Class Story
* @package InstagramScraper\Model
*/
class Story extends AbstractModel
class Story extends Media
{
/** @var Account */
protected $owner;

/** @var Media[] */
protected $stories;

public function setOwner($owner)
{
$this->owner = $owner;
}

public function getOwner()
{
return $this->owner;
}

public function addStory($story)
{
$this->stories[] = $story;
}

public function setStories($stories)
{
$this->stories = $stories;
}

public function getStories()
private $skip_prop = [
'owner' => true,
];

/***
* We do not need some values - do not parse it for Story,
* for example - we do not need owner object inside story
*
* @param $value
* @param $prop
* @param $arr
*/
protected function initPropertiesCustom($value, $prop, $arr)
{
return $this->stories;
if (!empty($this->skip_prop[$prop])) {
return;
}
parent::initPropertiesCustom($value, $prop, $arr);
}
}
41 changes: 41 additions & 0 deletions src/InstagramScraper/Model/UserStories.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<?php

namespace InstagramScraper\Model;

/**
* Class UserStories
* @package InstagramScraper\Model
*/
class UserStories extends AbstractModel
{
/** @var Account */
protected $owner;

/** @var Story[] */
protected $stories;

public function setOwner($owner)
{
$this->owner = $owner;
}

public function getOwner()
{
return $this->owner;
}

public function addStory($story)
{
$this->stories[] = $story;
}

public function setStories($stories)
{
$this->stories = $stories;
}

public function getStories()
{
return $this->stories;
}
}