Class: Dadata::SuggestClient
- Inherits:
-
ClientBase
- Object
- ClientBase
- Dadata::SuggestClient
- Defined in:
- lib/dadata/client/suggest.rb
Overview
Client for data suggestions and lookups
Constant Summary collapse
- BASE_URL =
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/'
Constants inherited from ClientBase
ClientBase::ERRORS, ClientBase::STATUS_ERRORS
Constants included from SensitiveData
Dadata::SensitiveData::SENSITIVE_HEADERS
Instance Method Summary collapse
-
#find_affiliated(query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Find affiliated companies.
-
#find_by_email(query) ⇒ Array<Hash>?
Find companies by email address.
-
#find_by_id(name, query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Find entities by identifier.
-
#geolocate(name, lat, lon, radius_meters = 100, **kwargs) ⇒ Array<Hash>?
Find addresses by geographic coordinates.
-
#initialize(token = Dadata.api_key, secret = Dadata.secret_key) ⇒ SuggestClient
constructor
A new instance of SuggestClient.
-
#iplocate(query, **kwargs) ⇒ Hash?
Get address by IP.
-
#suggest(name, query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Get suggestions for partial input.
Methods inherited from ClientBase
Methods included from SensitiveData
#sanitize_headers, #sanitize_message
Constructor Details
#initialize(token = Dadata.api_key, secret = Dadata.secret_key) ⇒ SuggestClient
Returns a new instance of SuggestClient.
10 11 12 |
# File 'lib/dadata/client/suggest.rb', line 10 def initialize(token = Dadata.api_key, secret = Dadata.secret_key) super(BASE_URL, token, secret) end |
Instance Method Details
#find_affiliated(query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Find affiliated companies
80 81 82 83 84 |
# File 'lib/dadata/client/suggest.rb', line 80 def find_affiliated(query, count = Dadata.suggestions_count, **kwargs) data = { query:, count: }.merge(kwargs) response = submit('findAffiliated/party', data, :post) response&.fetch('suggestions', nil) end |
#find_by_email(query) ⇒ Array<Hash>?
Find companies by email address
69 70 71 72 |
# File 'lib/dadata/client/suggest.rb', line 69 def find_by_email(query) response = submit('findByEmail/company', { query: }, :post) response&.fetch('suggestions', nil) end |
#find_by_id(name, query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Find entities by identifier
59 60 61 62 63 |
# File 'lib/dadata/client/suggest.rb', line 59 def find_by_id(name, query, count = Dadata.suggestions_count, **kwargs) data = { query:, count: }.merge(kwargs) response = submit("findById/#{name}", data, :post) response&.fetch('suggestions', nil) end |
#geolocate(name, lat, lon, radius_meters = 100, **kwargs) ⇒ Array<Hash>?
Find addresses by geographic coordinates
22 23 24 25 26 |
# File 'lib/dadata/client/suggest.rb', line 22 def geolocate(name, lat, lon, radius_meters = 100, **kwargs) data = { lat:, lon:, radius_meters: }.merge(kwargs) response = submit("geolocate/#{name}", data, :post) response&.fetch('suggestions', nil) end |
#iplocate(query, **kwargs) ⇒ Hash?
Get address by IP
33 34 35 36 37 |
# File 'lib/dadata/client/suggest.rb', line 33 def iplocate(query, **kwargs) data = { ip: query }.merge(kwargs) response = submit('iplocate/address', data, :get) response&.fetch('location', nil) end |
#suggest(name, query, count = Dadata.suggestions_count, **kwargs) ⇒ Array<Hash>?
Get suggestions for partial input
46 47 48 49 50 |
# File 'lib/dadata/client/suggest.rb', line 46 def suggest(name, query, count = Dadata.suggestions_count, **kwargs) data = { query:, count: }.merge(kwargs) response = submit("suggest/#{name}", data, :post) response&.fetch('suggestions', nil) end |