Class: BraveSearch::AsyncClient

Inherits:
Client
  • Object
show all
Defined in:
lib/brave_search/async_client.rb

Instance Method Summary collapse

Methods inherited from Client

#initialize, #search_and_download_pdfs, #search_and_download_pdfs_async, #search_and_export, #search_and_export_async, #spellcheck, #suggest, #summarizer

Constructor Details

This class inherits a constructor from BraveSearch::Client

Instance Method Details

#concurrent_search(queries) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/brave_search/async_client.rb', line 31

def concurrent_search(queries)
  Async do
    tasks = queries.map do |query_params|
      Async do
        if query_params.is_a?(String)
          params = build_params(q: query_params)
          response = make_request("/web/search", params)
          data = handle_response(response)
          BraveSearch::Results.new(data)
        else
          params = build_params(**query_params)
          response = make_request("/web/search", params)
          data = handle_response(response)
          BraveSearch::Results.new(data)
        end
      end
    end
    tasks.map(&:wait)
  end
end

#image_search(q:, count: 10, **options) ⇒ Object



25
26
27
28
29
# File 'lib/brave_search/async_client.rb', line 25

def image_search(q:, count: 10, **options)
  Async do
    super(q: q, count: count, **options)
  end
end

#news_search(q:, count: 10, **options) ⇒ Object



13
14
15
16
17
# File 'lib/brave_search/async_client.rb', line 13

def news_search(q:, count: 10, **options)
  Async do
    super(q: q, count: count, **options)
  end
end

#search(q:, count: 10, **options) ⇒ Object



7
8
9
10
11
# File 'lib/brave_search/async_client.rb', line 7

def search(q:, count: 10, **options)
  Async do
    super(q: q, count: count, **options)
  end
end

#video_search(q:, count: 10, **options) ⇒ Object



19
20
21
22
23
# File 'lib/brave_search/async_client.rb', line 19

def video_search(q:, count: 10, **options)
  Async do
    super(q: q, count: count, **options)
  end
end