Skip to content

Laravel 8+ client for the Genderize.io API

License

Notifications You must be signed in to change notification settings

pixelpeter/laravel-genderize-api-client

Repository files navigation

Laravel 8+ Genderize.io API Client

Latest Version on PackagistTotal DownloadsSoftware LicenseCoverage StatusTestsFix PHP code style issuesPHPStandependabot-auto-merge

A simple Laravel 8+ client for the Genderize.io API. It provides a fluent interface for easy request building.

Version overview

Laravelphpuse repositoryuse branch/tag
12.x, 11.x8.4, 8.3, 8.2https://github.com/pixelpeter/laravel-genderize-api-clientmaster, v12.x
10.x8.3, 8.2, 8.1https://github.com/pixelpeter/laravel-genderize-api-clientmaster, v10.x
9.x, 8.x8.2, 8.1, 8.0https://github.com/pixelpeter/laravel-genderize-api-clientv8.x
5.7, 5.67.3, 7.2, 7.1https://github.com/pixelpeter/laravel5-genderize-api-client2.0.x
5.57.2, 7.1, 7.0https://github.com/pixelpeter/laravel5-genderize-api-client1.1.x/2.0.x

Installation

Step 1: Install Through Composer

composer require pixelpeter/laravel-genderize-api-client

Step 2: Add the Facade

Add the alias in app/config/app.php

'aliases' => [ ... 'Genderize' => Pixelpeter\Genderize\Facades\Genderize::class, ... ];

Step 3: Publish the configuration file

This is only needed when you have an API key from Genderize.io

php artisan vendor:publish --provider="Pixelpeter\Genderize\GenderizeServiceProvider"

Examples

Send requests

Single name

useGenderize; Genderize::name('Peter')->get();

Multiple names (max. 10)

useGenderize; Genderize::name(['John', 'Jane'])->get(); // or for better readability you can use the plural Genderize::names(['John', 'Jane'])->get();

Add language and country options

useGenderize; Genderize::name('John')->country('US')->lang('EN')->get();

Working with the response

For single usage

useGenderize; $response = Genderize::name('Peter')->get(); print$response->result->gender; // 'male'print$response->result->name; // 'Peter'print$response->result->probability; '0.99'print$response->result->count; 144print$response->result->isMale(); trueprint$response->result->isFemale(); falseprint$response->result->isNotMale(); falseprint$response->result->isNotFemale(); true

For batch usage

useGenderize; $response = Genderize::names(['John', 'Jane'])->country('US')->lang('EN')->get(); foreach($response->resultas$row) { print$row->name; }

Getting information about the request and limits

useGenderize; $response = Genderize::name('Peter')->get(); print$response->meta->code; // 200 - HTTP response codeprint$response->meta->limit; // 1000 - Max number of allowed requestsprint$response->meta->remaining; // 950 - Number of requests leftprint$response->meta->reset->diffInSeconds(); // Carbon\Carbon - time left till reset

More documentation

Refer to Genderize.io API Documentation for more examples and documentation.

Testing

Run the tests with:

vendor/bin/phpunit

License

The MIT License (MIT). Please see License File for more information.

About

Laravel 8+ client for the Genderize.io API

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

close