namegender 0.4.0 → 0.5.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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/README.md +18 -4
  3. data/lib/namegender.rb +19 -12
  4. metadata +2 -2
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 6579682547f30f447af4b578719b7ea7d4f907be742b6a51359f6ddf0d9732d7
4
- data.tar.gz: a851e53689d40ec42beeffb8c4b71ffb826280b8e51935d0491994481f87e62a
3
+ metadata.gz: 5350923af9d635c3f939d1f25538c60b6accc0defeb05cf22039573ff89e10fe
4
+ data.tar.gz: 39dcaef2b09d1357e6a6bab9d47f4ac5136e936e4b3a1d1a66bea68ae315f583
5
5
  SHA512:
6
- metadata.gz: c9dc314525be03ffaff2506f922e6529b6383dfff4c98a14270a525a8c5a5af157fb43d2aa2bcc41daa37845d71a59802dc19cdc7ed47ee73ef03ca1bfc6c55f
7
- data.tar.gz: fc58d715c4215caefe358e9c726702e11621d717d7cf6dfd2c814a80488f9627d7ea01eea571979d2a4d142405147ec0b27b28e797c62082ceb62401a667e3d5
6
+ metadata.gz: fe4b4f3e318ebb9f6ff60ff3d8492cfd83d2e1fb068208563a966c3a5fc5dad1e84289956d31c47b9cd2edddadace69f6a216074922276e284689ba5c2ae3d97
7
+ data.tar.gz: 036b301d1b82c4443657cbaa9a38351de62bb15c47c7621741475a0e7fcc3c46c1085c7f2b3fde0ae0ff558de84383645341e5f35f0a78f8b2f7a36cdd3dbe4a
data/README.md CHANGED
@@ -12,19 +12,33 @@ puts result["gender"], result["probability"], result["sample_size"]
12
12
 
13
13
  ## Options and response
14
14
 
15
- `name`, `email`, `username` and `bulk` accept `country:`, `ai_fallback:` and
16
- `best_guess:`:
15
+ `name`, `email`, `username` and `bulk` accept `country:`, `locale:`, `ip:`,
16
+ `ai_fallback:` and `best_guess:`:
17
17
 
18
18
  ```ruby
19
19
  result = client.name("Andrea", country: "IT", best_guess: true)
20
20
  ```
21
21
 
22
+ When you do not know the country, pass what you have and the API works it out:
23
+ `locale:` is a language tag such as `"it-IT"` or `"pt_BR"` (its region is used;
24
+ a tag without one, `"en"`, sets no country), and `ip:` is your end user's IP
25
+ address (looked up, not stored). `country:` wins over `locale:`, which wins
26
+ over `ip:`. The response's `country_source` says which one was used:
27
+ `"country"`, `"locale"`, `"ip"` or `nil`.
28
+
29
+ ```ruby
30
+ result = client.name("Andrea", locale: request.env["HTTP_ACCEPT_LANGUAGE"].to_s[/\A[^,;]+/], ip: request.ip)
31
+ puts result["country"], result["country_source"]
32
+ ```
33
+
22
34
  A result carries `query`, `name`, `first_name`, `middle_name`, `last_name`, `name_type`, `gender`, `country`, `probability`,
23
- `sample_size`, `took_ms`, `source`, `confidence` and `matched_as`, alongside
35
+ `sample_size`, `took_ms`, `source`, `confidence`, `matched_as` and `country_source`, alongside
24
36
  `credits_charged`, `credits_remaining`, `data_version` and `request_id`.
25
37
  Success is the HTTP status: any non-2xx response raises `NameGender::Error`
26
38
  with `status` and `body` (`{"error", "message", "request_id", "docs"}`).
27
- Branch on `body["error"]`, not on the message.
39
+ Branch on `body["error"]`, not on the message. A `bulk` response carries
40
+ `country_source` once, at the top level next to `summary`, not on each item
41
+ in `results`.
28
42
 
29
43
  ## Country distribution
30
44
 
data/lib/namegender.rb CHANGED
@@ -21,21 +21,28 @@ module NameGender
21
21
  @api_key, @base_url = api_key, base_url.sub(%r{/$}, "")
22
22
  end
23
23
 
24
- # `options` are sent as-is: `ai_fallback: true` falls back to a language
25
- # model for names not in the database (needs AI consent on the account),
26
- # `best_guess: true` returns the most likely gender even below the
27
- # probability threshold. Any non-2xx response raises NameGender::Error.
28
- def name(value, country: nil, **options)
29
- post("/gender", { name: value, country: country }.merge(options).compact)
24
+ # `country` is an ISO 3166-1 alpha-2 code. Without it, `locale` (a
25
+ # language tag such as "it-IT" or "pt_BR"; a tag without a region, "en",
26
+ # sets no country) and then `ip` (the end user's IP address, not stored by
27
+ # the API) supply one: country > locale > ip. The result's
28
+ # "country_source" says which was used ("country", "locale", "ip" or nil).
29
+ #
30
+ # Other `options` are sent as-is: `ai_fallback: true` falls back to a
31
+ # language model for names not in the database (needs AI consent on the
32
+ # account), `best_guess: true` returns the most likely gender even below
33
+ # the probability threshold. Any non-2xx response raises NameGender::Error.
34
+ def name(value, country: nil, locale: nil, ip: nil, **options)
35
+ post("/gender", { name: value, country: country, locale: locale, ip: ip }.merge(options).compact)
30
36
  end
31
- def email(value, country: nil, **options)
32
- post("/gender/email", { email: value, country: country }.merge(options).compact)
37
+ def email(value, country: nil, locale: nil, ip: nil, **options)
38
+ post("/gender/email", { email: value, country: country, locale: locale, ip: ip }.merge(options).compact)
33
39
  end
34
- def username(value, country: nil, **options)
35
- post("/gender/username", { username: value, country: country }.merge(options).compact)
40
+ def username(value, country: nil, locale: nil, ip: nil, **options)
41
+ post("/gender/username", { username: value, country: country, locale: locale, ip: ip }.merge(options).compact)
36
42
  end
37
- def bulk(values, country: nil, type: "name", **options)
38
- post("/gender/bulk", { names: Array(values), country: country, type: type }.merge(options).compact)
43
+ # `country`, `locale` and `ip` apply to every name in the list.
44
+ def bulk(values, country: nil, locale: nil, ip: nil, type: "name", **options)
45
+ post("/gender/bulk", { names: Array(values), country: country, locale: locale, ip: ip, type: type }.merge(options).compact)
39
46
  end
40
47
  # Country distribution of a name. Not a country-of-origin or ethnicity
41
48
  # inference: "registrations" is counted volume, comparable only among the
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: namegender
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - NameGender
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2026-09-24 00:00:00.000000000 Z
11
+ date: 2026-10-06 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: A dependency-free Ruby client for name, email, username, bulk and country
14
14
  distribution lookups through NameGender.