Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error 400 #8

Open
gleyendeker opened this issue Apr 22, 2016 · 2 comments
Open

Error 400 #8

gleyendeker opened this issue Apr 22, 2016 · 2 comments

Comments

@gleyendeker
Copy link

gleyendeker commented Apr 22, 2016

Hello, using the api I have the error:

Failed unmarshalling json object into FaultInfo

After some debuggin, I found that there is a 400 ERROR calling the api:

http://api.nameapi.org/rest/v5.0/email/disposableemailaddressdetector?emailAddress=abcdefgh%4010minutemail.com&apiKey=myapikey-user

seems like an api error.

regards

@gleyendeker
Copy link
Author

gleyendeker commented May 2, 2016

I had to make some changes to make the code work. Please correct me if I make some kind of mistake. Regards.

The host seems to be rc50-api.nameapi.org, and not api.nameapi.org like the standard() function said.

If you create the ServiceFactory without the host parameter it will use the api.nameapi.org host to make the request, and the test function user another host, so so I created the ServiceFactory in this way to use the sane host as the test:

$serviceFactory = new ServiceFactory($myApiKey, $context, Host::http('rc50-api.nameapi.org'), '5.0');

You will need to include the line use org\nameapi\client\services\Host; at the beginning

The toString() function in the DisposableEmailAddressDetectorResult Class doesn't exist, so you have to use (String) before the function to force the type conversion.

The code that works for me for a basic disposableEmailAddressDetector implementation is:

use \Exception;
use org\nameapi\client\services\Host;
use org\nameapi\client\services\ServiceFactory;
use org\nameapi\ontology\input\context\Context;
use org\nameapi\ontology\input\context\Priority;

.
.
.

    public function disposableEmail($email){
        try {            
            $context = Context::builder()->priority(Priority::REALTIME())->build();

            $apiKey = 'myApiKey-myUser';

            $serviceFactory = new ServiceFactory($apiKey, $context, Host::http('rc50-api.nameapi.org'), '5.0');

            $ping = $serviceFactory->systemServices()->ping();
            $pong = $ping->ping();

            if ($pong == 'pong' || $pong == 'PONG') {

                $deaDetector = $serviceFactory->emailServices()->disposableEmailAddressDetector();
                $result = $deaDetector->isDisposable($email);

                $respuestaOptimaize = (String)$result->getDisposable();

                if ($respuestaOptimaize == 'YES') {
                    return true;
                }   
            }

        } catch (Exception $e) {         
        }

        return false;

    }

@armenmargaryan
Copy link

Thank you @gleyendeker

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants