Sha256: 02420e62909113e7bba3c03aefa64baa8ae96f3339b4ebe1a3bc47528f23544d

Contents?: true

Size: 1.01 KB

Versions: 2

Compression:

Stored size: 1.01 KB

Contents

# frozen_string_literal: true

require "faraday"
require "faraday_middleware"

module OpenFdaApi
  # Gives you access to the main nouns in the openFDA API
  class Client
    attr_reader :api_key, :adapter

    BASE_URL = "https://api.fda.gov"

    def initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil)
      @api_key = api_key
      @adapter = adapter
      @stubs   = stubs
    end

    def drugs
      OpenFdaApi::Drugs.new(self)
    end

    def device
      OpenFdaApi::Device.new(self)
    end

    def food
      OpenFdaApi::Food.new(self)
    end

    def animal_and_veterinary
      OpenFdaApi::AnimalAndVeterinary.new(self)
    end

    def tobacco
      OpenFdaApi::Tobacco.new(self)
    end

    def other
      OpenFdaApi::Other.new(self)
    end

    def connection
      @connection ||= Faraday.new(BASE_URL) do |conn|
        conn.request :json

        conn.response :dates
        conn.response :json, content_type: "application/json"

        conn.adapter adapter, @stubs
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
open_fda_api-0.0.13 lib/open_fda_api/client.rb
open_fda_api-0.0.12 lib/open_fda_api/client.rb