Class: OpenFdaApi::Endpoint

Inherits:
Object
  • Object
show all
Defined in:
lib/open_fda_api/endpoint.rb

Overview

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

Direct Known Subclasses

AnimalAndVeterinary, Device, Drugs, Food, Other, Tobacco

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(client) ⇒ Endpoint

Returns a new instance of Endpoint.



8
9
10
# File 'lib/open_fda_api/endpoint.rb', line 8

def initialize(client)
  @client = client
end

Instance Attribute Details

#clientObject (readonly)

Returns the value of attribute client.



6
7
8
# File 'lib/open_fda_api/endpoint.rb', line 6

def client
  @client
end

Instance Method Details

#build_inputs(search:, sort:, count:, skip:, limit:) ⇒ Object



16
17
18
# 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) ⇒ Object



12
13
14
# 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) ⇒ Object



20
21
22
23
24
25
26
27
# 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