class OpenFdaApi::Endpoint

Base class for all endpoints to share behavior like building queries and making requests

Attributes

client[R]

Public Class Methods

new(client) click to toggle source
# File lib/open_fda_api/endpoint.rb, line 8
def initialize(client)
  @client = client
end

Public Instance Methods

build_inputs(search:, sort:, count:, skip:, limit:) click to toggle source
# File lib/open_fda_api/endpoint.rb, line 16
def build_inputs(search:, sort:, count:, skip:, limit:)
  QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit, api_key: client.api_key)
end
build_query(query_input, valid_search_fields) click to toggle source
# File lib/open_fda_api/endpoint.rb, line 12
def build_query(query_input, valid_search_fields)
  QueryBuilder.new(query_input: query_input, valid_search_fields: valid_search_fields).build_query
end
make_request(endpoint, query) click to toggle source
# File lib/open_fda_api/endpoint.rb, line 20
def make_request(endpoint, query)
  url = "#{endpoint_path}/#{endpoint}"
  if query.empty?
    client.connection.get(url)
  else
    client.connection.get(url, query)
  end.body
end