genderapi 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 155c4030fa35e5b879f2592488e408b6484ee8e1cbe8a9e85b5f512d426812bd
4
+ data.tar.gz: a6fbdbd6375727517f101e8d29b6bbbe9806e38b277e3ecdb3c161d948726972
5
+ SHA512:
6
+ metadata.gz: 92b8a497590017a17a41d11cf453c4100b976ff098f4ea02503c9ae49a52268e205e1fc3b59ff5c6141d27a947ff6567dcc4f7cfa02caf6b7bce6c934c409601
7
+ data.tar.gz: 24008cc417d0780a7d4e2befe0924c231ade721c99719e8945a063c45f97810241fa3b797837e7b3b4033526e07be3aa34bd30e435e1efed6090000ae9dd228f
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2025 Gender Api
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,208 @@
1
+ # genderapi-ruby
2
+
3
+ Official Ruby SDK for [GenderAPI.io](https://www.genderapi.io) — determine gender from **names**, **emails**, and **usernames** using AI.
4
+
5
+ ---
6
+
7
+ Get your Free API Key: [https://app.genderapi.io](https://app.genderapi.io)
8
+
9
+ ---
10
+
11
+ ## 🚀 Installation
12
+
13
+ Add this line to your Gemfile:
14
+
15
+ ```ruby
16
+ gem 'genderapi'
17
+ ```
18
+
19
+ Then execute:
20
+
21
+ ```bash
22
+ bundle install
23
+ ```
24
+
25
+ Or install it manually:
26
+
27
+ ```bash
28
+ gem install genderapi
29
+ ```
30
+
31
+ ---
32
+
33
+ ## 📝 Usage
34
+
35
+ ### 🔹 Get Gender by Name
36
+
37
+ ```ruby
38
+ require 'genderapi'
39
+
40
+ api = GenderAPI::Client.new("YOUR_API_KEY")
41
+
42
+ # Basic usage
43
+ result = api.get_gender_by_name(name: "Michael")
44
+ puts result
45
+
46
+ # With askToAI set to true
47
+ result = api.get_gender_by_name(name: "李雷", askToAI: true)
48
+ puts result
49
+ ```
50
+
51
+ ---
52
+
53
+ ### 🔹 Get Gender by Email
54
+
55
+ ```ruby
56
+ result = api.get_gender_by_email(email: "michael.smith@example.com")
57
+ puts result
58
+
59
+ # With askToAI set to true
60
+ result = api.get_gender_by_email(email: "michael.smith@example.com", askToAI: true)
61
+ puts result
62
+ ```
63
+
64
+ ---
65
+
66
+ ### 🔹 Get Gender by Username
67
+
68
+ ```ruby
69
+ result = api.get_gender_by_username(username: "michael_dev")
70
+ puts result
71
+
72
+ # With askToAI set to true
73
+ result = api.get_gender_by_username(username: "michael_dev", askToAI: true)
74
+ puts result
75
+ ```
76
+
77
+ ---
78
+
79
+ ## 📥 API Parameters
80
+
81
+ All API methods accept parameters as keyword arguments. All fields are optional except the primary identifier (name, email, or username).
82
+
83
+ ---
84
+
85
+ ### Name Lookup
86
+
87
+ | Parameter | Type | Required | Description |
88
+ |--------------------|----------|----------|-------------|
89
+ | name | String | Yes | Name to query. |
90
+ | country | String | No | Two-letter country code (e.g. "US"). Helps narrow down gender detection results by region. |
91
+ | askToAI | Boolean | No | Default is `false`. If `true`, sends the query directly to AI for maximum accuracy, consuming 3 credits per request. If `false`, GenderAPI first tries its internal database and uses AI only if necessary, without spending 3 credits. Recommended for non-latin characters or unusual strings. |
92
+ | forceToGenderize | Boolean | No | Default is `false`. When `true`, analyzes even nicknames, emojis, or unconventional strings like "spider man" instead of returning `null` for non-standard names. |
93
+
94
+ ---
95
+
96
+ ### Email Lookup
97
+
98
+ | Parameter | Type | Required | Description |
99
+ |-----------|--------|----------|-------------|
100
+ | email | String | Yes | Email address to query. |
101
+ | country | String | No | Two-letter country code (e.g. "US"). Helps narrow down gender detection results by region. |
102
+ | askToAI | Boolean | No | Default is `false`. If `true`, sends the query directly to AI for maximum accuracy, consuming 3 credits per request. If `false`, GenderAPI first tries its internal database and uses AI only if necessary, without spending 3 credits. Recommended for non-latin characters or unusual strings. |
103
+
104
+ ---
105
+
106
+ ### Username Lookup
107
+
108
+ | Parameter | Type | Required | Description |
109
+ |--------------------|----------|----------|-------------|
110
+ | username | String | Yes | Username to query. |
111
+ | country | String | No | Two-letter country code (e.g. "US"). Helps narrow down gender detection results by region. |
112
+ | askToAI | Boolean | No | Default is `false`. If `true`, sends the query directly to AI for maximum accuracy, consuming 3 credits per request. If `false`, GenderAPI first tries its internal database and uses AI only if necessary, without spending 3 credits. Recommended for non-latin characters or unusual strings. |
113
+ | forceToGenderize | Boolean | No | Default is `false`. When `true`, analyzes even nicknames, emojis, or unconventional strings like "spider man" instead of returning `null` for non-standard names. |
114
+
115
+ ---
116
+
117
+ ## ✅ API Response
118
+
119
+ Example JSON response for all endpoints:
120
+
121
+ ```json
122
+ {
123
+ "status": true,
124
+ "used_credits": 1,
125
+ "remaining_credits": 4999,
126
+ "expires": 1743659200,
127
+ "q": "michael.smith@example.com",
128
+ "name": "Michael",
129
+ "gender": "male",
130
+ "country": "US",
131
+ "total_names": 325,
132
+ "probability": 98,
133
+ "duration": "4ms"
134
+ }
135
+ ```
136
+
137
+ ---
138
+
139
+ ### Response Fields
140
+
141
+ | Field | Type | Description |
142
+ |-------------------|--------------------|-----------------------------------------------------|
143
+ | status | Boolean | `true` or `false`. Check errors if false. |
144
+ | used_credits | Integer | Credits used for this request. |
145
+ | remaining_credits | Integer | Remaining credits on your package. |
146
+ | expires | Integer (timestamp)| Package expiration date (in seconds). |
147
+ | q | String | Your input query (name, email, or username). |
148
+ | name | String | Found name. |
149
+ | gender | Enum[String] | `"male"`, `"female"`, or `"null"`. |
150
+ | country | Enum[String] | Most likely country (e.g. `"US"`, `"DE"`, etc.). |
151
+ | total_names | Integer | Number of samples behind the prediction. |
152
+ | probability | Integer | Likelihood percentage (50-100). |
153
+ | duration | String | Processing time (e.g. `"4ms"`). |
154
+
155
+ ---
156
+
157
+ ## ⚠️ Error Codes
158
+
159
+ When `status` is `false`, check the following error codes:
160
+
161
+ | errno | errmsg | Description |
162
+ |-------|-----------------------------|-------------------------------------------------------------------|
163
+ | 50 | access denied | Unauthorized IP Address or Referrer. Check your access privileges. |
164
+ | 90 | invalid country code | Check supported country codes. [ISO 3166-1 alpha-2](https://en.wikipedia.org/wiki/ISO_3166-1_alpha-2) |
165
+ | 91 | name not set \|\| email not set | Missing `name` or `email` parameter on your request. |
166
+ | 92 | too many names \|\| too many emails | Limit is 100 for names, 50 for emails in one request. |
167
+ | 93 | limit reached | The API key credit has been finished. |
168
+ | 94 | invalid or missing key | The API key cannot be found. |
169
+ | 99 | API key has expired | Please renew your API key. |
170
+
171
+ Example error response:
172
+
173
+ ```json
174
+ {
175
+ "status": false,
176
+ "errno": 94,
177
+ "errmsg": "invalid or missing key"
178
+ }
179
+ ```
180
+
181
+ ---
182
+
183
+ ## 🔗 Live Test Pages
184
+
185
+ You can try live gender detection directly on GenderAPI.io:
186
+
187
+ - **Determine gender from a name:**
188
+ [www.genderapi.io](https://www.genderapi.io)
189
+
190
+ - **Determine gender from an email address:**
191
+ [https://www.genderapi.io/determine-gender-from-email](https://www.genderapi.io/determine-gender-from-email)
192
+
193
+ - **Determine gender from a username:**
194
+ [https://www.genderapi.io/determine-gender-from-username](https://www.genderapi.io/determine-gender-from-username)
195
+
196
+ ---
197
+
198
+ ## 📚 Detailed API Documentation
199
+
200
+ For the complete API reference, visit:
201
+
202
+ [https://www.genderapi.io/api-documentation](https://www.genderapi.io/api-documentation)
203
+
204
+ ---
205
+
206
+ ## ⚖️ License
207
+
208
+ MIT License
@@ -0,0 +1,151 @@
1
+ # frozen_string_literal: true
2
+
3
+ require "httparty"
4
+ require "json"
5
+
6
+ module GenderAPI
7
+ ##
8
+ # Ruby SDK for GenderAPI.io
9
+ #
10
+ # This SDK allows determining gender from:
11
+ # - personal names
12
+ # - email addresses
13
+ # - social media usernames
14
+ #
15
+ # Supports advanced options like:
16
+ # - country filtering
17
+ # - direct AI queries
18
+ # - forced genderization for nicknames or unconventional strings
19
+ #
20
+ class Client
21
+ include HTTParty
22
+ base_uri "https://api.genderapi.io"
23
+
24
+ ##
25
+ # Initialize the GenderAPI client.
26
+ #
27
+ # @param api_key [String] Your API key as a Bearer token.
28
+ # @param base_url [String] Optional API base URL. Defaults to https://api.genderapi.io
29
+ #
30
+ def initialize(api_key:, base_url: nil)
31
+ @api_key = api_key
32
+ self.class.base_uri(base_url) if base_url
33
+ @headers = {
34
+ "Authorization" => "Bearer #{@api_key}",
35
+ "Content-Type" => "application/json"
36
+ }
37
+ end
38
+
39
+ ##
40
+ # Determine gender from a personal name.
41
+ #
42
+ # @param name [String] The name to analyze. (Required)
43
+ # @param country [String, nil] Optional two-letter country code (e.g. "US").
44
+ # @param ask_to_ai [Boolean] Whether to force AI lookup. Default: false
45
+ # @param force_to_genderize [Boolean] Whether to analyze nicknames or emojis. Default: false
46
+ #
47
+ # @return [Hash] JSON response as a Ruby Hash.
48
+ #
49
+ def get_gender_by_name(name:, country: nil, ask_to_ai: false, force_to_genderize: false)
50
+ payload = {
51
+ name: name,
52
+ country: country,
53
+ askToAI: ask_to_ai,
54
+ forceToGenderize: force_to_genderize
55
+ }
56
+
57
+ _post_request("/api", payload)
58
+ end
59
+
60
+ ##
61
+ # Determine gender from an email address.
62
+ #
63
+ # @param email [String] The email to analyze. (Required)
64
+ # @param country [String, nil] Optional two-letter country code (e.g. "US").
65
+ # @param ask_to_ai [Boolean] Whether to force AI lookup. Default: false
66
+ #
67
+ # @return [Hash] JSON response as a Ruby Hash.
68
+ #
69
+ def get_gender_by_email(email:, country: nil, ask_to_ai: false)
70
+ payload = {
71
+ email: email,
72
+ country: country,
73
+ askToAI: ask_to_ai
74
+ }
75
+
76
+ _post_request("/api/email", payload)
77
+ end
78
+
79
+ ##
80
+ # Determine gender from a social media username.
81
+ #
82
+ # @param username [String] The username to analyze. (Required)
83
+ # @param country [String, nil] Optional two-letter country code (e.g. "US").
84
+ # @param ask_to_ai [Boolean] Whether to force AI lookup. Default: false
85
+ # @param force_to_genderize [Boolean] Whether to analyze nicknames or emojis. Default: false
86
+ #
87
+ # @return [Hash] JSON response as a Ruby Hash.
88
+ #
89
+ def get_gender_by_username(username:, country: nil, ask_to_ai: false, force_to_genderize: false)
90
+ payload = {
91
+ username: username,
92
+ country: country,
93
+ askToAI: ask_to_ai,
94
+ forceToGenderize: force_to_genderize
95
+ }
96
+
97
+ _post_request("/api/username", payload)
98
+ end
99
+
100
+ private
101
+
102
+ ##
103
+ # Internal helper to send POST requests to the GenderAPI.io API.
104
+ #
105
+ # Handles:
106
+ # - Bearer authentication
107
+ # - Removal of nil values in payload
108
+ # - JSON parsing of responses
109
+ # - Raising errors for non-200 responses
110
+ #
111
+ # @param endpoint [String] API endpoint path (e.g. "/api")
112
+ # @param payload [Hash] Request body data.
113
+ #
114
+ # @return [Hash] JSON response as Ruby Hash.
115
+ #
116
+ def _post_request(endpoint, payload)
117
+ # Remove nil values from payload
118
+ cleaned_payload = payload.reject { |_k, v| v.nil? }
119
+
120
+ response = self.class.post(
121
+ endpoint,
122
+ headers: @headers,
123
+ body: JSON.generate(cleaned_payload)
124
+ )
125
+
126
+ case response.code
127
+ when 200
128
+ parse_json(response.body)
129
+ when 404
130
+ # GenderAPI may return useful JSON for 404 too
131
+ parse_json(response.body)
132
+ else
133
+ raise "GenderAPI Error: HTTP #{response.code} - #{response.body}"
134
+ end
135
+ rescue HTTParty::Error => e
136
+ raise "GenderAPI Request failed: #{e.message}"
137
+ rescue JSON::ParserError
138
+ raise "GenderAPI Response is not valid JSON"
139
+ end
140
+
141
+ ##
142
+ # Parse JSON response safely.
143
+ #
144
+ # @param body [String] JSON string.
145
+ # @return [Hash] Parsed Hash.
146
+ #
147
+ def parse_json(body)
148
+ JSON.parse(body)
149
+ end
150
+ end
151
+ end
@@ -0,0 +1,5 @@
1
+ # lib/genderapi/version.rb
2
+
3
+ module GenderAPI
4
+ VERSION = "1.0.0"
5
+ end
data/lib/genderapi.rb ADDED
@@ -0,0 +1,8 @@
1
+ # lib/genderapi.rb
2
+
3
+ require "genderapi/version"
4
+ require "genderapi/client"
5
+
6
+ module GenderAPI
7
+ # boş bırakabilirsin veya helper methodlar koyabilirsin
8
+ end
metadata ADDED
@@ -0,0 +1,95 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: genderapi
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Onur Ozturk
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2025-07-05 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: httparty
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '0.18'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '0.18'
27
+ - !ruby/object:Gem::Dependency
28
+ name: json
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '2.0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '2.0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.0'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.0'
55
+ description: "\n Official Ruby SDK for GenderAPI.io.\n\n This SDK allows determining
56
+ gender from:\n - personal names\n - email addresses\n - social media usernames\n\n
57
+ \ Supports:\n - country filtering\n - direct AI queries\n - forced genderization
58
+ for nicknames or unconventional strings\n\n Built with HTTParty for easy HTTP
59
+ handling.\n "
60
+ email:
61
+ - support@genderapi.io
62
+ executables: []
63
+ extensions: []
64
+ extra_rdoc_files: []
65
+ files:
66
+ - LICENSE
67
+ - README.md
68
+ - lib/genderapi.rb
69
+ - lib/genderapi/client.rb
70
+ - lib/genderapi/version.rb
71
+ homepage: https://www.genderapi.io
72
+ licenses:
73
+ - MIT
74
+ metadata: {}
75
+ post_install_message:
76
+ rdoc_options: []
77
+ require_paths:
78
+ - lib
79
+ required_ruby_version: !ruby/object:Gem::Requirement
80
+ requirements:
81
+ - - ">="
82
+ - !ruby/object:Gem::Version
83
+ version: '2.6'
84
+ required_rubygems_version: !ruby/object:Gem::Requirement
85
+ requirements:
86
+ - - ">="
87
+ - !ruby/object:Gem::Version
88
+ version: '0'
89
+ requirements: []
90
+ rubygems_version: 3.2.3
91
+ signing_key:
92
+ specification_version: 4
93
+ summary: Ruby SDK for GenderAPI.io — determine gender from names, emails, and usernames
94
+ using AI.
95
+ test_files: []