-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #22 Add method \Gietos\Dadata\Service\Suggestions::suggestEmail
- Loading branch information
Sergey Kasatkin
committed
Oct 26, 2017
1 parent
8000b40
commit d4ca33c
Showing
7 changed files
with
190 additions
and
2 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
<?php | ||
|
||
namespace Gietos\Dadata\Model\Response\Suggestions; | ||
|
||
use Gietos\Dadata\Model\AbstractModel; | ||
|
||
class Email extends AbstractModel | ||
{ | ||
/** | ||
* @var string | ||
*/ | ||
protected $local; | ||
|
||
/** | ||
* @var string | ||
*/ | ||
protected $domain; | ||
|
||
public function getLocal(): string | ||
{ | ||
return $this->local; | ||
} | ||
|
||
public function setLocal(string $local) | ||
{ | ||
$this->local = $local; | ||
} | ||
|
||
public function getDomain(): string | ||
{ | ||
return $this->domain; | ||
} | ||
|
||
public function setDomain(string $domain) | ||
{ | ||
$this->domain = $domain; | ||
} | ||
} |
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,21 @@ | ||
<?php | ||
|
||
namespace Gietos\Dadata\Model\Response\Suggestions; | ||
|
||
class EmailSuggestion extends AbstractSuggestion | ||
{ | ||
/** | ||
* @var Email | ||
*/ | ||
private $data; | ||
|
||
public function getData(): Email | ||
{ | ||
return $this->data; | ||
} | ||
|
||
public function setData(Email $data) | ||
{ | ||
$this->data = $data; | ||
} | ||
} |
24 changes: 24 additions & 0 deletions
24
src/Model/Response/Suggestions/EmailSuggestionCollection.php
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,24 @@ | ||
<?php | ||
|
||
namespace Gietos\Dadata\Model\Response\Suggestions; | ||
|
||
use Gietos\Dadata\Model\AbstractCollection; | ||
|
||
class EmailSuggestionCollection extends AbstractCollection | ||
{ | ||
/** | ||
* @param EmailSuggestion[] $elements | ||
*/ | ||
public function __construct(array $elements = []) | ||
{ | ||
parent::__construct($elements); | ||
} | ||
|
||
/** | ||
* @inheritdoc | ||
*/ | ||
protected function getClass(): string | ||
{ | ||
return EmailSuggestion::class; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/Model/Response/Suggestions/EmailSuggestionResponse.php
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,23 @@ | ||
<?php | ||
|
||
namespace Gietos\Dadata\Model\Response\Suggestions; | ||
|
||
use Gietos\Dadata\Model\AbstractModel; | ||
|
||
class EmailSuggestionResponse extends AbstractModel | ||
{ | ||
/** | ||
* @var EmailSuggestionCollection | ||
*/ | ||
private $suggestions; | ||
|
||
public function getSuggestions(): EmailSuggestionCollection | ||
{ | ||
return $this->suggestions; | ||
} | ||
|
||
public function setSuggestions(EmailSuggestionCollection $suggestions) | ||
{ | ||
$this->suggestions = $suggestions; | ||
} | ||
} |
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,57 @@ | ||
<?php | ||
|
||
namespace Gietos\Dadata\Tests; | ||
|
||
use Gietos\Dadata\Api; | ||
use Gietos\Dadata\Model\Response\Suggestions\Email; | ||
use Gietos\Dadata\Model\Response\Suggestions\EmailSuggestion; | ||
use Gietos\Dadata\Model\Response\Suggestions\EmailSuggestionCollection; | ||
use Gietos\Dadata\Service\Suggestions; | ||
use GuzzleHttp\Psr7\Response; | ||
use Http\Message\MessageFactory\DiactorosMessageFactory; | ||
use Http\Message\StreamFactory\DiactorosStreamFactory; | ||
use Http\Message\UriFactory\DiactorosUriFactory; | ||
use Http\Mock\Client; | ||
|
||
class SuggestionsTest extends BaseTestCase | ||
{ | ||
/** | ||
* @var Suggestions | ||
*/ | ||
private $suggestionsService; | ||
|
||
/** | ||
* @var Client | ||
*/ | ||
private $httpClient; | ||
|
||
public function setUp() | ||
{ | ||
$this->httpClient = new Client; | ||
$apiClient = new Api( | ||
'token', | ||
'', | ||
$this->httpClient, | ||
new DiactorosMessageFactory, | ||
new DiactorosStreamFactory, | ||
new DiactorosUriFactory | ||
); | ||
$this->suggestionsService = new Suggestions($apiClient); | ||
} | ||
|
||
public function testSuggestEmail() | ||
{ | ||
$this->httpClient->addResponse(new Response(200, [], $this->loadDataFile('suggest-email.json'))); | ||
$result = $this->suggestionsService->suggestEmail('anton@'); | ||
$this->assertInstanceOf(EmailSuggestionCollection::class, $result); | ||
/** @var EmailSuggestion $suggestion */ | ||
$suggestion = $result->current(); | ||
$this->assertInstanceOf(EmailSuggestion::class, $suggestion); | ||
$this->assertEquals('[email protected]', $suggestion->getValue()); | ||
$this->assertEquals('[email protected]', $suggestion->getUnrestrictedValue()); | ||
$data = $suggestion->getData(); | ||
$this->assertInstanceOf(Email::class, $data); | ||
$this->assertEquals('anton', $data->getLocal()); | ||
$this->assertEquals('mail.ru', $data->getDomain()); | ||
} | ||
} |
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 @@ | ||
{ | ||
"suggestions": [ | ||
{ | ||
"value": "[email protected]", | ||
"unrestricted_value": "[email protected]", | ||
"data": { | ||
"local": "anton", | ||
"domain": "mail.ru", | ||
"qc": null | ||
} | ||
} | ||
] | ||
} |