Module: Vidalo::API::Search

Included in:
Connection
Defined in:
lib/vidalo/api/search.rb

Instance Method Summary collapse

Instance Method Details

#search(type: nil, query: nil, start_page: 1, page_size: 10) ⇒ Array

Get result of a set of Nokogiri Objects

Returns:

  • (Array)


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

def search(type: nil, query: nil, start_page: 1, page_size: 10)
  if type.nil?
    raise ArgumentError.new 'Error: You need to define "type" at least (eg. "products")'
  end
  @res = send_api_request(type, {'q' => query, 'start-page' => start_page, 'page-size' => page_size })
  @res.search('entry').to_a if @res
end

#search_product(id: nil, aggregate: [], all_info: nil) ⇒ Nokogiri

Get result of a product’s information

Example: api.search_product(id: 45, aggregate: [‘UCD’]) api.search_product(id: 45, all_info: true)

Returns:

  • (Nokogiri)


26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vidalo/api/search.rb', line 26

def search_product(id: nil, aggregate: [], all_info: nil)
  raise %{
  
    Need a Vidal Product ID.

  } unless id.is_a? Fixnum || id.to_i.to_s == id
  aggregate = %w(
  molecules
  indications
  ald_detail
  smr_asmr
  atc_classification
  VIDAL_CLASSIFICATION
  product_range
  document
  reco
  UCDS
  UNITS
  ) if all_info == true
  @res = send_api_request("product/#{id}", { 'aggregate' => aggregate })
end