Class: DnB::Direct::Plus::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/dnb/direct/plus/search.rb

Class Method Summary collapse

Class Method Details

.typeahead(params = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
# File 'lib/dnb/direct/plus/search.rb', line 4

def self.typeahead(params = {})
    started_at = Time.now
    country_code = params[:country] || 'US'
    response = DnB::Direct::Plus.connection.get do |req|
        url = "/v1/search/typeahead?searchTerm=#{params[:term]}&countryISOAlpha2Code=#{country_code}"
        req.url url
        req.headers[:authorization] = "Bearer #{DnB::Direct::Plus.api_token}"
    end
    puts "== [TYPEAHEAD] Completed in #{((Time.now - started_at)*1000).round}ms".cyan.bold

    JSON.parse(response.body)
end