Class: NDB::Search

Inherits:
Object
  • Object
show all
Defined in:
lib/ndb/search.rb

Constant Summary collapse

PERMITTED_PARAMS =
%w(q fg sort max offset api_key)

Class Method Summary collapse

Class Method Details

.base_uriObject



15
16
17
# File 'lib/ndb/search.rb', line 15

def self.base_uri
  NDB.base_uri + "/search"
end

.default_optionsObject



19
20
21
22
# File 'lib/ndb/search.rb', line 19

def self.default_options
  { q: "", fg: "", sort: "r", max: 50, offset: 0, format: "JSON",
    api_key: NDB.api_key }
end

.perform(options = {}) ⇒ Object



8
9
10
11
12
13
# File 'lib/ndb/search.rb', line 8

def self.perform(options = {})
  sanitized_options = NDB.sanitize_options(options, PERMITTED_PARAMS)
  params = NDB.params_from_hash(default_options.merge(sanitized_options))
  response = Faraday.get("#{base_uri}?#{params}")
  JSON.parse(response.body)
end