Class: OpenFdaApi::Endpoint
- Inherits:
-
Object
- Object
- OpenFdaApi::Endpoint
- Defined in:
- lib/open_fda_api/endpoint.rb
Overview
Base class for all endpoints to share behavior like building queries and making requests
Instance Attribute Summary collapse
-
#client ⇒ Object
readonly
Returns the value of attribute client.
Instance Method Summary collapse
- #build_inputs(search:, sort:, count:, skip:, limit:) ⇒ Object
- #build_query(query_input, valid_search_fields) ⇒ Object
-
#initialize(client) ⇒ Endpoint
constructor
A new instance of Endpoint.
- #make_request(endpoint, query) ⇒ Object
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
#client ⇒ Object (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 |