Class: Dadata::Suggestion
- Inherits:
-
Object
- Object
- Dadata::Suggestion
- Defined in:
- lib/dadata/suggestion.rb
Overview
Suggestion API
Constant Summary collapse
- BASE_URL =
'https://suggestions.dadata.ru/suggestions/api/4_1/rs/suggest/'
Instance Method Summary collapse
-
#initialize(config) ⇒ Suggestion
constructor
A new instance of Suggestion.
- #organization(term) ⇒ Object
Constructor Details
#initialize(config) ⇒ Suggestion
Returns a new instance of Suggestion.
11 12 13 |
# File 'lib/dadata/suggestion.rb', line 11 def initialize(config) @config = config end |
Instance Method Details
#organization(term) ⇒ Object
15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/dadata/suggestion.rb', line 15 def organization(term) url = URI(URI.join(BASE_URL, 'party')) req = Net::HTTP::Post.new(url) req['Content-Type'] = 'application/json' req['Accept'] = 'application/json' req['Authorization'] = "Token #{@config[:api_key]}" req.body = { query: term }.to_json resp = perform_request(url, req) if resp.code == '200' [true, JSON.parse(resp.body, symbolize_names: true)] else [false, code: resp.code.to_i, message: resp.body] end end |