namegender 0.3.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 (5) hide show
  1. checksums.yaml +7 -0
  2. data/LICENSE +1 -0
  3. data/README.md +40 -0
  4. data/lib/namegender.rb +65 -0
  5. metadata +52 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: 5a2b603dfdf3aa0427b5522c68d48ac4d0fcf706991d86b09abad77405e0fdd2
4
+ data.tar.gz: ec8a07ad241d2c98a6f2dce29f874e22799b42a80ee133ec8db329fb2c844722
5
+ SHA512:
6
+ metadata.gz: f64cf15e7174a98e7ae334d4efc1f62f961ae8dfe0849308e53af49e37d2a07740d45b669a87e5123f86377a7eaa160bdd7856f9fc40a2918bc64db5389d21ae
7
+ data.tar.gz: b812e005bd8304610ccf7ece873bbf4d2933923fe53c5b4821fa8d55837545e3337094856e42ea34a3e56fd3cff58304d6f53ce94fc2756b473f7cd77de002d0
data/LICENSE ADDED
@@ -0,0 +1 @@
1
+ MIT License. Copyright (c) 2026 NameGender. Permission is granted to use, copy, modify, merge, publish, distribute, sublicense, and/or sell this Software, provided this notice is included. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND.
data/README.md ADDED
@@ -0,0 +1,40 @@
1
+ # NameGender Ruby
2
+
3
+ ```sh
4
+ gem install namegender
5
+ ```
6
+
7
+ ```ruby
8
+ client = NameGender::Client.new("YOUR_API_KEY")
9
+ result = client.name("Ayşe", country: "TR")
10
+ puts result["gender"], result["probability"], result["sample_size"]
11
+ ```
12
+
13
+ ## Options and response
14
+
15
+ `name`, `email`, `username` and `bulk` accept `country:`, `ai_fallback:` and
16
+ `best_guess:`:
17
+
18
+ ```ruby
19
+ result = client.name("Andrea", country: "IT", best_guess: true)
20
+ ```
21
+
22
+ A result carries `query`, `name`, `gender`, `country`, `probability`,
23
+ `sample_size`, `took_ms`, `source`, `confidence` and `matched_as`, alongside
24
+ `credits_charged`, `credits_remaining`, `data_version` and `request_id`.
25
+ Success is the HTTP status: any non-2xx response raises `NameGender::Error`
26
+ with `status` and `body` (`{"error", "message", "request_id", "docs"}`).
27
+ Branch on `body["error"]`, not on the message.
28
+
29
+ ## Country distribution
30
+
31
+ Which countries a name is recorded in. This is not a country-of-origin or
32
+ ethnicity inference: `registrations` is counted volume, comparable only among
33
+ the countries that publish counted birth statistics, and `attested_in` is
34
+ presence with no weight attached. Show `basis["note"]` next to any percentage.
35
+
36
+ ```ruby
37
+ result = client.countries("Mehmet", limit: 10)
38
+ result["registrations"].each { |r| puts "#{r["country"]} #{r["share"]}%" }
39
+ puts result["attested_in"].join(", ")
40
+ ```
data/lib/namegender.rb ADDED
@@ -0,0 +1,65 @@
1
+ require "json"
2
+ require "net/http"
3
+ require "uri"
4
+
5
+ module NameGender
6
+ class Error < StandardError
7
+ attr_reader :status, :body
8
+ def initialize(message, status = 0, body = nil)
9
+ super(message); @status = status; @body = body
10
+ end
11
+ end
12
+
13
+ class Client
14
+ def initialize(api_key, base_url: "https://namegender.com/api/v1")
15
+ raise ArgumentError, "api_key is required" if api_key.to_s.empty?
16
+ @api_key, @base_url = api_key, base_url.sub(%r{/$}, "")
17
+ end
18
+
19
+ # `options` are sent as-is: `ai_fallback: true` falls back to a language
20
+ # model for names not in the database (needs AI consent on the account),
21
+ # `best_guess: true` returns the most likely gender even below the
22
+ # probability threshold. Any non-2xx response raises NameGender::Error.
23
+ def name(value, country: nil, **options)
24
+ post("/gender", { name: value, country: country }.merge(options).compact)
25
+ end
26
+ def email(value, country: nil, **options)
27
+ post("/gender/email", { email: value, country: country }.merge(options).compact)
28
+ end
29
+ def username(value, country: nil, **options)
30
+ post("/gender/username", { username: value, country: country }.merge(options).compact)
31
+ end
32
+ def bulk(values, country: nil, type: "name", **options)
33
+ post("/gender/bulk", { names: values, country: country, type: type }.merge(options).compact)
34
+ end
35
+ # Country distribution of a name. Not a country-of-origin or ethnicity
36
+ # inference: "registrations" is counted volume, comparable only among the
37
+ # countries that publish counted birth statistics; "attested_in" is
38
+ # presence with no weight attached. `limit` caps "registrations" (1-100,
39
+ # server default 25).
40
+ def countries(value, limit: nil)
41
+ post("/gender/countries", { name: value, limit: limit }.compact)
42
+ end
43
+ def account
44
+ request(Net::HTTP::Get, "/me")
45
+ end
46
+
47
+ private
48
+ def post(path, body)
49
+ request(Net::HTTP::Post, path, body)
50
+ end
51
+ def request(klass, path, body = nil)
52
+ uri = URI(@base_url + path)
53
+ req = klass.new(uri)
54
+ req["Accept"] = req["Content-Type"] = "application/json"
55
+ req["Authorization"] = "Bearer #{@api_key}"
56
+ req.body = JSON.generate(body) if body
57
+ response = Net::HTTP.start(uri.host, uri.port, use_ssl: uri.scheme == "https") { |http| http.request(req) }
58
+ parsed = JSON.parse(response.body)
59
+ raise Error.new(parsed["message"] || "HTTP #{response.code}", response.code.to_i, parsed) unless response.is_a?(Net::HTTPSuccess)
60
+ parsed
61
+ rescue JSON::ParserError
62
+ raise Error.new("NameGender returned invalid JSON", response&.code.to_i)
63
+ end
64
+ end
65
+ end
metadata ADDED
@@ -0,0 +1,52 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: namegender
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.0
5
+ platform: ruby
6
+ authors:
7
+ - NameGender
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2026-09-16 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: A dependency-free Ruby client for name, email, username, bulk and country
14
+ distribution lookups through NameGender.
15
+ email:
16
+ - support@namegender.com
17
+ executables: []
18
+ extensions: []
19
+ extra_rdoc_files: []
20
+ files:
21
+ - LICENSE
22
+ - README.md
23
+ - lib/namegender.rb
24
+ homepage: https://namegender.com
25
+ licenses:
26
+ - MIT
27
+ metadata:
28
+ homepage_uri: https://namegender.com
29
+ source_code_uri: https://github.com/anpekesen/namegender-ruby
30
+ bug_tracker_uri: https://github.com/anpekesen/namegender-ruby/issues
31
+ documentation_uri: https://namegender.com/docs
32
+ rubygems_mfa_required: 'true'
33
+ post_install_message:
34
+ rdoc_options: []
35
+ require_paths:
36
+ - lib
37
+ required_ruby_version: !ruby/object:Gem::Requirement
38
+ requirements:
39
+ - - ">="
40
+ - !ruby/object:Gem::Version
41
+ version: '3.0'
42
+ required_rubygems_version: !ruby/object:Gem::Requirement
43
+ requirements:
44
+ - - ">="
45
+ - !ruby/object:Gem::Version
46
+ version: '0'
47
+ requirements: []
48
+ rubygems_version: 3.5.22
49
+ signing_key:
50
+ specification_version: 4
51
+ summary: Official Ruby client for the NameGender API
52
+ test_files: []