Class: GenderAPI::Client
- Inherits:
-
Object
- Object
- GenderAPI::Client
- Includes:
- HTTParty
- Defined in:
- lib/genderapi/client.rb
Overview
Ruby SDK for GenderAPI.io
This SDK allows determining gender from:
- personal names
- email addresses
- social media usernames
Supports advanced options like:
- country filtering
- direct AI queries
- forced genderization for nicknames or unconventional strings
Instance Method Summary collapse
-
#get_gender_by_email(email:, country: nil, ask_to_ai: false) ⇒ Hash
Determine gender from an email address.
-
#get_gender_by_email_bulk(data:) ⇒ Hash
Bulk determine gender from multiple email addresses.
-
#get_gender_by_name(name:, country: nil, ask_to_ai: false, force_to_genderize: false) ⇒ Hash
Determine gender from a personal name.
-
#get_gender_by_name_bulk(data:) ⇒ Hash
Bulk determine gender from multiple personal names.
-
#get_gender_by_username(username:, country: nil, ask_to_ai: false, force_to_genderize: false) ⇒ Hash
Determine gender from a social media username.
-
#get_gender_by_username_bulk(data:) ⇒ Hash
Bulk determine gender from multiple social media usernames.
-
#initialize(api_key:, base_url: nil) ⇒ Client
constructor
Initialize the GenderAPI client.
Constructor Details
#initialize(api_key:, base_url: nil) ⇒ Client
Initialize the GenderAPI client.
30 31 32 33 34 35 36 37 |
# File 'lib/genderapi/client.rb', line 30 def initialize(api_key:, base_url: nil) @api_key = api_key self.class.base_uri(base_url) if base_url @headers = { "Authorization" => "Bearer #{@api_key}", "Content-Type" => "application/json" } end |
Instance Method Details
#get_gender_by_email(email:, country: nil, ask_to_ai: false) ⇒ Hash
Determine gender from an email address.
69 70 71 72 73 74 75 76 77 |
# File 'lib/genderapi/client.rb', line 69 def get_gender_by_email(email:, country: nil, ask_to_ai: false) payload = { email: email, country: country, askToAI: ask_to_ai } _post_request("/api/email", payload) end |
#get_gender_by_email_bulk(data:) ⇒ Hash
Bulk determine gender from multiple email addresses.
Allows sending up to 50 email records in a single request. This method is designed for scenarios such as bulk database cleaning, analytics, or personalization tasks where email data is available and high throughput is required.
Each email object can contain:
- email [String] The email address to analyze. (Required)
- country [String, nil] Optional two-letter country code (e.g. "US").
- id [String, Integer, nil] Optional custom identifier to correlate input and output.
138 139 140 141 |
# File 'lib/genderapi/client.rb', line 138 def get_gender_by_email_bulk(data:) payload = { data: data } _post_request("/api/email/multi/country", payload) end |
#get_gender_by_name(name:, country: nil, ask_to_ai: false, force_to_genderize: false) ⇒ Hash
Determine gender from a personal name.
49 50 51 52 53 54 55 56 57 58 |
# File 'lib/genderapi/client.rb', line 49 def get_gender_by_name(name:, country: nil, ask_to_ai: false, force_to_genderize: false) payload = { name: name, country: country, askToAI: ask_to_ai, forceToGenderize: force_to_genderize } _post_request("/api", payload) end |
#get_gender_by_name_bulk(data:) ⇒ Hash
Bulk determine gender from multiple personal names.
Allows sending up to 100 name records in a single request. Useful for high-volume batch processing where performance and cost efficiency are critical.
Each name object can contain:
- name [String] The personal name to analyze. (Required)
- country [String, nil] Optional two-letter country code (e.g. "US").
- id [String, Integer, nil] Optional custom identifier to correlate input and output.
116 117 118 119 |
# File 'lib/genderapi/client.rb', line 116 def get_gender_by_name_bulk(data:) payload = { data: data } _post_request("/api/name/multi/country", payload) end |
#get_gender_by_username(username:, country: nil, ask_to_ai: false, force_to_genderize: false) ⇒ Hash
Determine gender from a social media username.
89 90 91 92 93 94 95 96 97 98 |
# File 'lib/genderapi/client.rb', line 89 def get_gender_by_username(username:, country: nil, ask_to_ai: false, force_to_genderize: false) payload = { username: username, country: country, askToAI: ask_to_ai, forceToGenderize: force_to_genderize } _post_request("/api/username", payload) end |
#get_gender_by_username_bulk(data:) ⇒ Hash
Bulk determine gender from multiple social media usernames.
Allows sending up to 50 username records in a single request. Useful for bulk social media analytics, profiling, or marketing segmentation tasks where usernames are the primary identifier and high performance is required.
Each username object can contain:
- username [String] The social media username to analyze. (Required)
- country [String, nil] Optional two-letter country code (e.g. "US").
- id [String, Integer, nil] Optional custom identifier to correlate input and output.
160 161 162 163 |
# File 'lib/genderapi/client.rb', line 160 def get_gender_by_username_bulk(data:) payload = { data: data } _post_request("/api/username/multi/country", payload) end |