2017 © Pedro Peláez
 

library client

An easy to use API client for Gender-API.com

image

gender-api/client

An easy to use API client for Gender-API.com

  • Monday, May 28, 2018
  • by Gender-API.com
  • Repository
  • 1 Watchers
  • 2 Stars
  • 3,945 Installations
  • PHP
  • 0 Dependents
  • 0 Suggesters
  • 2 Forks
  • 0 Open issues
  • 6 Versions
  • 20 % Grown

The README.md

Gender-API.com PHP Client

About

PHP client for the Gender-API.com API., (*1)

Homepage: https://gender-api.com, (*2)

FAQ: https://gender-api.com/en/frequently-asked-questions, (*3)

API Docs: https://gender-api.com/en/api-docs, (*4)

Contact: https://gender-api.com/en/contact, (*5)

Installation

my-project$ composer require gender-api/client

API-Key

Get a free API key here: https://gender-api.com/en/account, (*6)

Development

Start the dockerized development machine with, (*7)

docker-compose up

Install all required packages, (*8)

bin/composer install

Run all unit tests with mock data, (*9)

bin/phpunit

Run all unit tests against the API, (*10)

API_KEY=<yourkey> bin/phpunit

Simple Usage

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');
    $name = $apiClient->getByFirstName('elisabeth');

    if ($name->genderFound()) {
        echo $name->getGender(); // will return "female" (possible values: male, female, unknown)
    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient requests left
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Advanced Usage

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');
    ````
    // Get gender by first name and country
    $name = $apiClient->getByFirstNameAndCountry('elisabeth', 'US');

    // Get gender by first name and client IP
    $name = $apiClient->getByFirstNameAndClientIpAddress('elisabeth', '178.27.52.144');

    // Get gender by first name and browser locale
    $name = $apiClient->getByFirstNameAndLocale('elisabeth', 'en_US');

    //Query multiple names with a single call
    foreach ($apiClient->getMultipleNames(array('stefan', 'elisabeth')) as $name) {
        if ($name->genderFound()) {
            echo $name->getName() . ': ' . $name->getGender(); // will return "female" (possible values: male, female, unknown)
        }
    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient requests left
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Email Address

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');

    // Get gender by email address name and country
    $name = $apiClient->getByEmailAddress('elisabeth1499@gmail.com');
    if ($name->genderFound()) {
        echo $name->getGender(); // will return "female"
    }

    // Get gender by email address name and country
    $name = $apiClient->getByEmailAddressAndCountry('elisabeth.smith776@gmail.com', 'US');
    echo $name->getGender(); // will return "female"
    if ($name->genderFound()) {
        echo $name->getGender(); // will return "female"
    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient requests left
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Split First And Last Name

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');

    // Get gender by email address name and country
    $name = $apiClient->getByFirstNameAndLastName('Frank Underwood');

    if ($name->genderFound()) {
        echo $name->getGender(); // will return "male"
        echo $name->getFirstName(); // will return "Frank"
        echo $name->getLastName(); // will return "Underwood"
    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient requests left
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Country Of Origin

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');

    // Get gender by email address name and country
    $name = $apiClient->getCountryOfOrigin('Frank');

    if ($name->genderFound()) {
        echo $name->getGender(); // will return "male"
        echo $name->getFirstName(); // will return "Frank"
        echo $name->getLastName(); // will return "Underwood"

        echo $name->getCountryOfOriginMapUrl(); // will return a link to a map that displays the result in a rendered for

        foreach ($name->getCountryOfOrigin() as $country) {
                var_dump($country); // country of origin
        }

    }

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error or insufficient requests left
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Statistics

use GenderApi\Client as GenderApiClient;

try {

    $apiClient = new GenderApiClient('insert your API key');

    $stats = $apiClient->getStats();

    // Check your query limit
    if ($stats->isLimitReached()) {
        echo "query limit reached.";
    }

    // Get remaining requests
    echo $stats->getRemainingRequests() . ' requests left.';

} catch (GenderApi\Exception $e) {
    // Name lookup failed due to a network error
    // See https://gender-api.com/en/api-docs/error-codes
    echo 'Exception: ' . $e->getMessage();
}

Proxy

If you need a proxy server to access the Internet in your company, you can set one via the setProxy command., (*11)

use GenderApi\Client as GenderApiClient;

$apiClient = new GenderApiClient('insert your API key');
$apiClient->setProxy('localhost', 3128);

The Versions

28/05 2018

dev-master

9999999-dev https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names

28/05 2018

v1.0.2

1.0.2.0 https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names

14/02 2018

v1.0.1

1.0.1.0 https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names

21/04 2017

v0.9.2

0.9.2.0 https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names

10/04 2017

v0.9.1

0.9.1.0 https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names

10/04 2017

v0.9.0

0.9.0.0 https://github.com/markus-perl/gender-api-client

An easy to use API client for Gender-API.com

  Sources   Download

MIT

The Requires

  • php >=5.6.0

 

The Development Requires

genderize gender api gender of names