Sha256: e599ab4fc4032067b0f7090bf8542ad92925a8cbffdb3f983f5936c4e67d7b5e
Contents?: true
Size: 1.3 KB
Versions: 2
Compression:
Stored size: 1.3 KB
Contents
# frozen_string_literal: true require "net/http" require "json" require "open_fda_api/query_builder" module OpenFdaApi # Interact with the Drugs API Endpoint: # - Adverse Events # - Product Labeling # - NDC Directory # - Recall Enforcement Reports # - Drugs@FDA) class Drugs def initialize @host = "api.fda.gov" @path_base = "/drug" end # The openFDA drug adverse event API returns data that has been collected from the # FDA Adverse Event Reporting System (FAERS), a database that contains information on # adverse event and medication error reports submitted to FDA. # # @param search_arguments [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/ # @return Response from the API parsed as JSON def adverse_events(search_arguments: []) endpoint = "/event.json" query = build_query(search_arguments) url = build_url(endpoint, query) make_request(url) end private def build_url(endpoint, query) URI::HTTPS.build(host: @host, path: @path_base + endpoint, query: query) end def build_query(search_arguments) QueryBuilder.new(search: search_arguments).build_query end def make_request(url) JSON.parse(Net::HTTP.get(url)) end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
open_fda_api-0.0.4 | lib/open_fda_api/drugs.rb |
open_fda_api-0.0.3 | lib/open_fda_api/drugs.rb |