Class: SearchApi::Client

Inherits:
Object
  • Object
show all
Defined in:
lib/searchapi/client.rb

Instance Method Summary collapse

Constructor Details

#initialize(config = SearchApi.configuration) ⇒ Client

Returns a new instance of Client.



8
9
10
11
# File 'lib/searchapi/client.rb', line 8

def initialize(config = SearchApi.configuration)
  @config = config
  @connection = build_connection
end

Instance Method Details

#get(path, params = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/searchapi/client.rb', line 13

def get(path, params = {})
  params[:api_key] = @config.api_key
  response = @connection.get(path.delete_prefix("/"), params)
  Response.new(response)
rescue Faraday::TooManyRequestsError => e
  raise RateLimitError, e.message
rescue Faraday::UnauthorizedError => e
  raise AuthenticationError, e.message
rescue Faraday::TimeoutError, Faraday::ConnectionFailed => e
  raise SearchApi::TimeoutError, e.message
rescue Faraday::ResourceNotFound => e
  raise NotFoundError, e.message
rescue Faraday::ServerError => e
  raise SearchApi::ServerError, e.message
end