Skip to content

Commit

Permalink
Merge pull request #240 from rusan/right_model_names
Browse files Browse the repository at this point in the history
Right names for models
  • Loading branch information
raiym authored Dec 14, 2017
2 parents d94449c + 8fe6d6c commit 8892265
Show file tree
Hide file tree
Showing 3 changed files with 64 additions and 33 deletions.
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 @@ -950,12 +951,12 @@ public function getStories($reel_ids = null)

$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;
}
}

0 comments on commit 8892265

Please sign in to comment.