Skip to content

Commit

Permalink
added media property to Post object
Browse files Browse the repository at this point in the history
  • Loading branch information
arnaspet committed Jun 7, 2015
1 parent e2b101c commit f68e66e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 0 deletions.
5 changes: 5 additions & 0 deletions src/DataFormatter/InstagramDataFormatter.php
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,11 @@ public function format($data)
$post->setContent($media->getCaption()->getText());
$post->setHashtags($media->getTags()->toArray());
$post->setDate(\DateTime::createFromFormat('U', $media->getCreatedTime()));
if (isset($media->getData()->videos)) {
$post->setMedia($media->getStandardResVideo());
} else {
$post->setMedia($media->getStandardResImage());
}

$result[] = $post;
}
Expand Down
19 changes: 19 additions & 0 deletions src/Post.php
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,9 @@ class Post
/** @var \DateTime */
private $date;

/** @var string image or video url */
private $media;

/**
* @return String
*/
Expand Down Expand Up @@ -97,4 +100,20 @@ public function setDate($date)
{
$this->date = $date;
}

/**
* @return string
*/
public function getMedia()
{
return $this->media;
}

/**
* @param string $media
*/
public function setMedia($media)
{
$this->media = $media;
}
}
3 changes: 3 additions & 0 deletions tests/DataFormatter/InstagramDataFormatterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@

namespace NtaCamp\SocialHashtag\Tests\DataFormatter;

use Instagram\Collection\MediaCollection;
use Instagram\Collection\TagCollection;
use Instagram\Comment;
use Instagram\Media;
Expand Down Expand Up @@ -32,6 +33,7 @@ public function testFormat()
$data->user = $userData;
$data->tags = new TagCollection($tagsData);
$data->created_time = '1429032159'; // unix timestamp
$data->images = (object)['standard_resolution' => 'standard res image'];

$media = new Media($data);

Expand All @@ -41,6 +43,7 @@ public function testFormat()
$this->assertSame('http://goo.gl/UQqqEU', current($results)->getProfileImageUrl());
$this->assertSame('hey Nintendo fans ! #nintendo', current($results)->getContent());
$this->assertSame('nintendo', current($results)->getHashtags()[0]);
$this->assertSame('standard res image', current($results)->getMedia());
$this->assertInstanceOf('\DateTime', current($results)->getDate());
}

Expand Down

0 comments on commit f68e66e

Please sign in to comment.