Method: Alexandrite::GoogleAPI#search_by

Defined in:
lib/alexandrite_google.rb

#search_by(key, query, projection: 'lite', **fields) ⇒ Faraday::Response

Parameters:

  • key (Symbol)
  • query (String)
  • fields (Array<String>)

Returns:

  • (Faraday::Response)


51
52
53
54
55
56
57
58
59
60
61
# File 'lib/alexandrite_google.rb', line 51

def search_by(key, query, projection: 'lite', **fields)
  projection = "&projection=#{projection}"
  url = fields.any? ? "#{BASE_URL}#{FILTERS[key]}#{query}#{add_fields(fields)}#{projection}" : "#{BASE_URL}#{FILTERS[key]}#{query}"
  conn = Faraday.new(url) do |r|
    r.response :json
  end

  response = conn.get.body

  process_response(response)
end