Class: Dadata::SuggestClient

Inherits:
ClientBase show all
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

Methods inherited from ClientBase

#close, #submit

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

Parameters:

  • query (String)

    Company identifier

  • count (Integer) (defaults to: Dadata.suggestions_count)

    Maximum number of results

  • kwargs (Hash)

    Additional parameters (e.g., scope, type)

Returns:

  • (Array<Hash>, nil)

    List of affiliated companies or nil if not found



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

Parameters:

  • query (String)

    Email address

Returns:

  • (Array<Hash>, nil)

    List of companies or nil if not found



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

Parameters:

  • name (String)

    Type of entity to search for

  • query (String)

    Entity identifier

  • count (Integer) (defaults to: Dadata.suggestions_count)

    Maximum number of results

  • kwargs (Hash)

    Additional parameters (e.g., language)

Returns:

  • (Array<Hash>, nil)

    List of suggestions or nil if not found



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

Parameters:

  • name (String)

    Type of entity to search for (e.g., ‘address’, ‘postal_unit’)

  • lat (Numeric)

    Latitude

  • lon (Numeric)

    Longitude

  • radius_meters (Integer) (defaults to: 100)

    Search radius in meters (default: 100, max: 1000)

  • kwargs (Hash)

    Additional parameters (e.g., language, count)

Returns:

  • (Array<Hash>, nil)

    List of suggestions or nil if not found



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

Parameters:

  • query (String)

    IP address

  • kwargs (Hash)

    Additional parameters (e.g., language)

Returns:

  • (Hash, nil)

    Location data or nil if not found



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

Parameters:

  • name (String)

    Type of entity to search for

  • query (String)

    Search query

  • count (Integer) (defaults to: Dadata.suggestions_count)

    Maximum number of results

  • kwargs (Hash)

    Additional parameters (e.g., language, constraints)

Returns:

  • (Array<Hash>, nil)

    List of suggestions or nil if not found



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