-
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.
Merge pull request #17 from igzard/refactor/remove-search-dependency
feat: remove search dependency from init
- Loading branch information
Showing
10 changed files
with
146 additions
and
24 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
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 |
---|---|---|
|
@@ -22,20 +22,24 @@ composer require igzard/ncore | |
|
||
## Examples | ||
|
||
Searching for Toy Story in category: Film (HUN SD) | ||
Searching for Toy Story in category: Film (HUN SD). By default, without category, it searches in film hun sd. | ||
|
||
```php | ||
$ncore = new Ncore('{passkey}'); | ||
$torrents = $ncore->search( | ||
(new Search())->setSearch('Toy Story')->setCat(Category::FILM_HUN_SD) | ||
); | ||
$torrents = $ncore->search([ | ||
'search' => 'Toy Story', | ||
'category' => Category::FILM_HUN_SD | ||
]); | ||
``` | ||
|
||
Download first match for Toy Story in category: Film (HUN SD) | ||
Download first match for Toy Story in category: Film (HUN SD). By default, without category, it searches in film hun sd. | ||
```php | ||
$ncore = new Ncore('{passkey}'); | ||
$torrents = $ncore->download( | ||
(new Search())->setSearch('Toy Story')->setCat(Category::FILM_HUN_SD), | ||
[ | ||
'search' => 'Toy Story', | ||
'category' => Category::FILM_HUN_SD | ||
], | ||
'{pathToDownload}', | ||
'{filename}' | ||
); | ||
|
@@ -48,6 +52,9 @@ Thank you for considering contributing to the PHP Ncore! To contribution follow | |
```bash | ||
git clone [email protected]:igzard/ncore.git | ||
composer install | ||
|
||
cd tools/php-cs-fixer | ||
composer install | ||
``` | ||
|
||
For running tests: | ||
|
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,22 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Igzard\Ncore\Entity\Factory; | ||
|
||
use Igzard\Ncore\Entity\Search; | ||
|
||
class SearchFactory | ||
{ | ||
public function createFromArray(array $searchPayload): Search | ||
{ | ||
$search = new Search(); | ||
$search->setSearch($searchPayload['search']); | ||
|
||
if (isset($searchPayload['category'])) { | ||
$search->setCategory($searchPayload['category']); | ||
} | ||
|
||
return $search; | ||
} | ||
} |
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,13 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Igzard\Ncore\Exception; | ||
|
||
class EmptyResponseException extends \Exception | ||
{ | ||
public static function create(): self | ||
{ | ||
return new self('Empty response received'); | ||
} | ||
} |
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 |
---|---|---|
@@ -0,0 +1,60 @@ | ||
<?php | ||
|
||
declare(strict_types=1); | ||
|
||
namespace Igzard\Ncore\Tests\Entity\Factory; | ||
|
||
use Igzard\Ncore\Entity\Factory\SearchFactory; | ||
use Igzard\Ncore\Entity\Search; | ||
use Igzard\Ncore\Enum\Category; | ||
use PHPUnit\Framework\TestCase; | ||
|
||
class SearchFactoryTest extends TestCase | ||
{ | ||
protected function setUp(): void | ||
{ | ||
$this->searchFactory = new SearchFactory(); | ||
} | ||
|
||
/** | ||
* @dataProvider searchDataProvider | ||
*/ | ||
public function testFactory(array $searchPayload, Search $expectedSearch): void | ||
{ | ||
$search = $this->searchFactory->createFromArray($searchPayload); | ||
|
||
$this->assertEquals($expectedSearch, $search); | ||
} | ||
|
||
public static function searchDataProvider(): array | ||
{ | ||
return [ | ||
'case 1# - ToyStory in FILM HUN SD category' => [ | ||
'searchPayload' => [ | ||
'search' => 'Toy Story', | ||
'category' => Category::FILM_HUN_SD, | ||
], | ||
'expectedSearch' => (new Search()) | ||
->setSearch('Toy Story') | ||
->setCategory(Category::FILM_HUN_SD) | ||
], | ||
'case 2# - ToyStory without category' => [ | ||
'searchPayload' => [ | ||
'search' => 'Toy Story', | ||
], | ||
'expectedSearch' => (new Search()) | ||
->setSearch('Toy Story') | ||
->setCategory(Category::FILM_HUN_SD) | ||
], | ||
'case 3# - Spiderman in category' => [ | ||
'searchPayload' => [ | ||
'search' => 'Toy Story', | ||
'category' => Category::FILM_ENG_HD, | ||
], | ||
'expectedSearch' => (new Search()) | ||
->setSearch('Toy Story') | ||
->setCategory(Category::FILM_ENG_HD) | ||
], | ||
]; | ||
} | ||
} |
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