Skip to content

Commit

Permalink
Added Keyords and Orginal Response Getter.
Browse files Browse the repository at this point in the history
  • Loading branch information
tzsk committed Nov 8, 2017
1 parent 46dc7ac commit 7d8ee2a
Show file tree
Hide file tree
Showing 8 changed files with 77 additions and 3 deletions.
5 changes: 5 additions & 0 deletions src/Contracts/VendorInterface.php
Original file line number Diff line number Diff line change
Expand Up @@ -42,4 +42,9 @@ public function setLimit($limit);
* @return array
*/
public function buildFeed(SimpleXMLElement $feed);

/**
* @return void
*/
public function original();
}
10 changes: 10 additions & 0 deletions src/PodcastScraper.php
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ public function limit($limit)
return $this;
}

/**
* @return PodcastScraper
*/
public function original()
{
$this->vendor->original();

return $this;
}

/**
* @param Request $request
* @param string $feedUrl
Expand Down
19 changes: 18 additions & 1 deletion src/ScrapePodcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,11 @@ class ScrapePodcast
*/
protected $count = 15;

/**
* @var bool
*/
protected $isOrginal = false;

/**
* ScrapePodcast constructor.
*/
Expand Down Expand Up @@ -87,11 +92,23 @@ public function feed($feed)
return $this->engine()->find($feed);
}

/**
* @return ScrapePodcast
*/
public function original()
{
$this->isOrginal = true;

return $this;
}

/**
* @return PodcastScraper
*/
protected function engine()
{
return (new PodcastScraper($this->vendor))->limit($this->count);
$engine = (new PodcastScraper($this->vendor))->limit($this->count);

return $this->isOrginal ? $engine->original() : $engine;
}
}
14 changes: 14 additions & 0 deletions src/Vendors/AbstractVendor.php
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,11 @@

abstract class AbstractVendor
{
/**
* @var bool
*/
protected $isOrginal = false;

/**
* @param SimpleXMLElement $feed
*
Expand Down Expand Up @@ -45,6 +50,7 @@ protected function getEpisodes($channel)
'size' => $this->getEpisodeSize($value),
'duration' => $this->getEpisodeDuration($value),
'description' => (string) $value->description,
'keywords' => $this->getKeywords($value),
'link' => (string) $value->link,
'image' => $this->getEpisodeImage($value, $channel),
'published_at' => $this->getPublishedDate($value),
Expand All @@ -54,6 +60,14 @@ protected function getEpisodes($channel)
return $items;
}

/**
* @return array
*/
protected function getKeywords($item)
{
return array_map('trim', explode(",", $this->getValueByPath($item, 'keywords')));
}

/**
* @param SimpleXMLElement $value
*
Expand Down
8 changes: 8 additions & 0 deletions src/Vendors/DigitalPodcast.php
Original file line number Diff line number Diff line change
Expand Up @@ -101,4 +101,12 @@ public function build(array $response)

return $output;
}

/**
* @return void
*/
public function original()
{
$this->isOrginal = true;
}
}
13 changes: 12 additions & 1 deletion src/Vendors/Itunes.php
Original file line number Diff line number Diff line change
Expand Up @@ -90,6 +90,9 @@ public function generateUrl($value)
public function build(array $response)
{
$response = json_decode($response['search']);
if ($this->isOrginal) {
return $response;
}
$output['result_count'] = $response->resultCount;

foreach ($response->results as $value) {
Expand All @@ -98,7 +101,7 @@ public function build(array $response)
'author' => $value->artistName,
'title' => $value->collectionName,
'episodes' => $value->trackCount,
'image' => $value->artworkUrl100,
'image' => $value->artworkUrl600,
'rss' => $value->feedUrl,
'itunes' => $value->collectionViewUrl,
'genre' => $value->primaryGenreName,
Expand All @@ -107,4 +110,12 @@ public function build(array $response)

return $output;
}

/**
* @return void
*/
public function original()
{
$this->isOrginal = true;
}
}
2 changes: 1 addition & 1 deletion tests/SearchDigitalPodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ class SearchDigitalPodcastTest extends TestCase
protected function setUp()
{
parent::setUp();
$this->result = $this->scraper->digitalPodcast()->search("laravel");
$this->result = $this->scraper->search("laravel");
$this->failedResult = $this->scraper->search("");
}
}
9 changes: 9 additions & 0 deletions tests/SearchItunesPodcastTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -8,17 +8,26 @@ class SearchItunesPodcastTest extends TestCase
protected $result;
protected $itunesResult;
protected $failedResult;
protected $itunesOriginal;

protected function setUp()
{
parent::setUp();
$this->result = $this->scraper->search("laravel");
$this->itunesResult = $this->scraper->itunes()->search("laravel");
$this->itunesOriginal = $this->scraper->original()->search("laravel");
$this->failedResult = $this->scraper->search("");
}

public function testDefaultVendorIsItunes()
{
$this->assertSame($this->result, $this->itunesResult);
}

public function testOriginalItunesResponse()
{
$this->assertCount(2, $this->itunesOriginal);
$data = $this->itunesOriginal['data'];
$this->assertCount($data->resultCount, $data->results);
}
}

0 comments on commit 7d8ee2a

Please sign in to comment.