Class: OpenFdaApi::Client
- Inherits:
-
Object
- Object
- OpenFdaApi::Client
- Defined in:
- lib/open_fda_api/client.rb
Overview
Gives you access to the main nouns in the openFDA API
Constant Summary collapse
- BASE_URL =
"https://api.fda.gov"
Instance Attribute Summary collapse
-
#adapter ⇒ Object
readonly
Returns the value of attribute adapter.
-
#api_key ⇒ Object
readonly
Returns the value of attribute api_key.
Instance Method Summary collapse
- #animal_and_veterinary ⇒ Object
- #connection ⇒ Object
- #device ⇒ Object
- #drugs ⇒ Object
- #food ⇒ Object
-
#initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
constructor
A new instance of Client.
- #other ⇒ Object
- #tobacco ⇒ Object
Constructor Details
#initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) ⇒ Client
Returns a new instance of Client.
13 14 15 16 17 |
# File 'lib/open_fda_api/client.rb', line 13 def initialize(api_key: nil, adapter: Faraday.default_adapter, stubs: nil) @api_key = api_key @adapter = adapter @stubs = stubs end |
Instance Attribute Details
#adapter ⇒ Object (readonly)
Returns the value of attribute adapter.
9 10 11 |
# File 'lib/open_fda_api/client.rb', line 9 def adapter @adapter end |
#api_key ⇒ Object (readonly)
Returns the value of attribute api_key.
9 10 11 |
# File 'lib/open_fda_api/client.rb', line 9 def api_key @api_key end |
Instance Method Details
#animal_and_veterinary ⇒ Object
31 32 33 |
# File 'lib/open_fda_api/client.rb', line 31 def animal_and_veterinary OpenFdaApi::AnimalAndVeterinary.new(self) end |
#connection ⇒ Object
43 44 45 46 47 48 49 50 51 52 |
# File 'lib/open_fda_api/client.rb', line 43 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 |
#device ⇒ Object
23 24 25 |
# File 'lib/open_fda_api/client.rb', line 23 def device OpenFdaApi::Device.new(self) end |
#drugs ⇒ Object
19 20 21 |
# File 'lib/open_fda_api/client.rb', line 19 def drugs OpenFdaApi::Drugs.new(self) end |
#food ⇒ Object
27 28 29 |
# File 'lib/open_fda_api/client.rb', line 27 def food OpenFdaApi::Food.new(self) end |
#other ⇒ Object
39 40 41 |
# File 'lib/open_fda_api/client.rb', line 39 def other OpenFdaApi::Other.new(self) end |
#tobacco ⇒ Object
35 36 37 |
# File 'lib/open_fda_api/client.rb', line 35 def tobacco OpenFdaApi::Tobacco.new(self) end |