Module: Einvoicing::SiretLookup
- Defined in:
- lib/einvoicing/siret_lookup.rb
Overview
Looks up SIRET and company name from a SIREN number using the free French government API (no authentication required).
Constant Summary collapse
- API_URL =
"https://recherche-entreprises.api.gouv.fr/search"- SIREN_RE =
/\A\d{9}\z/
Class Method Summary collapse
-
.find(siren) ⇒ Hash?
Find company info for a given SIREN number.
Class Method Details
.find(siren) ⇒ Hash?
Find company info for a given SIREN number.
18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/einvoicing/siret_lookup.rb', line 18 def self.find(siren) return nil unless siren.to_s.match?(SIREN_RE) uri = URI(API_URL) uri.query = URI.encode_www_form(q: siren, mtq: "true") response = fetch(uri) return nil if response.nil? parse(response) rescue StandardError nil end |