open_fda_api 0.0.9 → 0.0.12

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: adc99f4c0266329d56ee1cbc6592789908b09a98580136813e3d8033e33c2328
4
- data.tar.gz: 6fc8dc376b266e216e5f263248cbae5342c655a50ba3aa1c9d37245a6b521bdf
3
+ metadata.gz: 3f55d1b8140f12ed25ecf99fd227e0c053a50455abcc2153e03ba7a5f5d724bb
4
+ data.tar.gz: 74f2219cfd2812e2576e9e748132332f049d9925b5afd763609528f0fa1a049e
5
5
  SHA512:
6
- metadata.gz: 95da4769cc677e55b92f682bc4b7f05d98543cfcfa05f2d4786c8254e52a6399235e3850a11c7d70ba63dd61ea28e42fda25fc336e8ac1fb3710e9e9a4dc29ca
7
- data.tar.gz: f93d3fa2ffc26fad6f9460333326d32f97f51f99dcd567b85ddd62b5ed4e5f868d4aff4bcc8183b37214927e7a03ff4e64fee534c8a98a1c2f5ffc3fe7ee619c
6
+ metadata.gz: '06953c4682f9bd4948c23a24035094452b85ee73bcb9c3a37f5e16151c39bedb90afab6b11881f73d9106cdf052dcc4d3bb98747b4126409fcbf9fb57eb59082'
7
+ data.tar.gz: acbddbb9dc475a1243ef8415e411d1c365de227509d3dc7ceddd3221136b96329dea226acad155b4d87269dd754fcf59166ea880f2a053acccfc987b2374dc37
data/CHANGELOG.md CHANGED
@@ -1,5 +1,17 @@
1
1
  ## [Unreleased]
2
2
 
3
+ ## [0.0.12] - 2022-01-24
4
+ - Animal & Veterinary Endpoint
5
+ - Tobacco Endpoint
6
+ - Other Endpoint
7
+
8
+ ## [0.0.11] - 2022-01-24
9
+ - Include Food endpoints
10
+
11
+ ## [0.0.10] - 2022-01-24
12
+ - Include Device endpoints
13
+ - Pull out Endpoint common behavior to a base class
14
+
3
15
  ## [0.0.9] - 2022-01-24
4
16
  - Filled out the following Drug endpoints:
5
17
  - product_labeling
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- open_fda_api (0.0.9)
4
+ open_fda_api (0.0.12)
5
5
  faraday (~> 1.9)
6
6
  faraday_middleware (~> 1.2)
7
7
 
data/README.md CHANGED
@@ -31,6 +31,9 @@ args = {
31
31
  limit: 20
32
32
  }
33
33
 
34
+ # Animal & Veterinary API
35
+ client.animal_and_veterinary.adverse_events(args)
36
+
34
37
  # Drug API
35
38
  client.drugs.adverse_events(args)
36
39
  client.drugs.product_labeling(args)
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Interact with the Animal & Veterinary API Endpoint:
5
+ # - Adverse Events
6
+ class AnimalAndVeterinary < Endpoint
7
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/animalandveterinary/event/searchable-fields/
8
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/animalandveterinary/event/searchable-fields/
9
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/animalandveterinary/event/searchable-fields/
10
+ # @param skip [Integer] Number of results to skip
11
+ # @param limit [Integer] Number of results to return
12
+ # @return Response from the API parsed as JSON
13
+ def adverse_events(search: [], sort: [], count: [], skip: 0, limit: 1)
14
+ endpoint = "event.json"
15
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
16
+ query = build_query(inputs, {}) # TODO: Upload valid fields
17
+ make_request(endpoint, query)
18
+ end
19
+
20
+ private
21
+
22
+ def endpoint_path
23
+ "/animalandveterinary"
24
+ end
25
+ end
26
+ end
@@ -20,6 +20,26 @@ module OpenFdaApi
20
20
  OpenFdaApi::Drugs.new(self)
21
21
  end
22
22
 
23
+ def device
24
+ OpenFdaApi::Device.new(self)
25
+ end
26
+
27
+ def food
28
+ OpenFdaApi::Food.new(self)
29
+ end
30
+
31
+ def animal_and_veterinary
32
+ OpenFdaApi::AnimalAndVeterinary.new(self)
33
+ end
34
+
35
+ def tobacco
36
+ OpenFdaApi::Tobacco.new(self)
37
+ end
38
+
39
+ def other
40
+ OpenFdaApi::Other.new(self)
41
+ end
42
+
23
43
  def connection
24
44
  @connection ||= Faraday.new(BASE_URL) do |conn|
25
45
  conn.request :json
@@ -0,0 +1,138 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Interact with the Device API Endpoint:
5
+ # - 501(k)
6
+ # - Classification
7
+ # - Recall Enforcement Reports
8
+ # - Adverse Events
9
+ # - Pre-market Approval
10
+ # - Recalls
11
+ # - Registrations and Listings
12
+ # - Covid19 Serological Testing Evaluations
13
+ # - Unique Device Identifier
14
+ class Device < Endpoint
15
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/event/searchable-fields/
16
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/event/searchable-fields/
17
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/event/searchable-fields/
18
+ # @param skip [Integer] Number of results to skip
19
+ # @param limit [Integer] Number of results to return
20
+ # @return Response from the API parsed as JSON
21
+ def adverse_events(search: [], sort: [], count: [], skip: 0, limit: 1)
22
+ endpoint = "event.json"
23
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
24
+ query = build_query(inputs, {})
25
+ make_request(endpoint, query)
26
+ end
27
+
28
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/classification/searchable-fields/
29
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/classification/searchable-fields/
30
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/classification/searchable-fields/
31
+ # @param skip [Integer] Number of results to skip
32
+ # @param limit [Integer] Number of results to return
33
+ # @return Response from the API parsed as JSON
34
+ def classification(search: [], sort: [], count: [], skip: 0, limit: 1)
35
+ endpoint = "classification.json"
36
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
37
+ query = build_query(inputs, {}) # TODO: Upload valid fields
38
+ make_request(endpoint, query)
39
+ end
40
+
41
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/510k/searchable-fields/
42
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/510k/searchable-fields/
43
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/510k/searchable-fields/
44
+ # @param skip [Integer] Number of results to skip
45
+ # @param limit [Integer] Number of results to return
46
+ # @return Response from the API parsed as JSON
47
+ def premarket_510ks(search: [], sort: [], count: [], skip: 0, limit: 1)
48
+ endpoint = "510k.json"
49
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
50
+ query = build_query(inputs, {}) # TODO: Upload valid fields
51
+ make_request(endpoint, query)
52
+ end
53
+
54
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/enforcement/searchable-fields/
55
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/enforcement/searchable-fields/
56
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/enforcement/searchable-fields/
57
+ # @param skip [Integer] Number of results to skip
58
+ # @param limit [Integer] Number of results to return
59
+ # @return Response from the API parsed as JSON
60
+ def recall_enforcement_reports(search: [], sort: [], count: [], skip: 0, limit: 1)
61
+ endpoint = "enforcement.json"
62
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
63
+ query = build_query(inputs, {}) # TODO: Upload valid fields
64
+ make_request(endpoint, query)
65
+ end
66
+
67
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/pma/searchable-fields/
68
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/pma/searchable-fields/
69
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/pma/searchable-fields/
70
+ # @param skip [Integer] Number of results to skip
71
+ # @param limit [Integer] Number of results to return
72
+ # @return Response from the API parsed as JSON
73
+ def premarket_approval(search: [], sort: [], count: [], skip: 0, limit: 1)
74
+ endpoint = "pma.json"
75
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
76
+ query = build_query(inputs, {}) # TODO: Upload valid fields
77
+ make_request(endpoint, query)
78
+ end
79
+
80
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/recall/searchable-fields/
81
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/recall/searchable-fields/
82
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/recall/searchable-fields/
83
+ # @param skip [Integer] Number of results to skip
84
+ # @param limit [Integer] Number of results to return
85
+ # @return Response from the API parsed as JSON
86
+ def recalls(search: [], sort: [], count: [], skip: 0, limit: 1)
87
+ endpoint = "recall.json"
88
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
89
+ query = build_query(inputs, {}) # TODO: Upload valid fields
90
+ make_request(endpoint, query)
91
+ end
92
+
93
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/registrationlisting/searchable-fields/
94
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/registrationlisting/searchable-fields/
95
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/registrationlisting/searchable-fields/
96
+ # @param skip [Integer] Number of results to skip
97
+ # @param limit [Integer] Number of results to return
98
+ # @return Response from the API parsed as JSON
99
+ def registrations_and_listings(search: [], sort: [], count: [], skip: 0, limit: 1)
100
+ endpoint = "registrationlisting.json"
101
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
102
+ query = build_query(inputs, {}) # TODO: Upload valid fields
103
+ make_request(endpoint, query)
104
+ end
105
+
106
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/covid19serology/searchable-fields/
107
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/covid19serology/searchable-fields/
108
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/covid19serology/searchable-fields/
109
+ # @param skip [Integer] Number of results to skip
110
+ # @param limit [Integer] Number of results to return
111
+ # @return Response from the API parsed as JSON
112
+ def covid19_serological_tests(search: [], sort: [], count: [], skip: 0, limit: 1)
113
+ endpoint = "covid19serology.json"
114
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
115
+ query = build_query(inputs, {}) # TODO: Upload valid fields
116
+ make_request(endpoint, query)
117
+ end
118
+
119
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/device/udi/searchable-fields/
120
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/device/udi/searchable-fields/
121
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/device/udi/searchable-fields/
122
+ # @param skip [Integer] Number of results to skip
123
+ # @param limit [Integer] Number of results to return
124
+ # @return Response from the API parsed as JSON
125
+ def unique_device_identifier(search: [], sort: [], count: [], skip: 0, limit: 1)
126
+ endpoint = "udi.json"
127
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
128
+ query = build_query(inputs, {}) # TODO: Upload valid fields
129
+ make_request(endpoint, query)
130
+ end
131
+
132
+ private
133
+
134
+ def endpoint_path
135
+ "/device"
136
+ end
137
+ end
138
+ end
@@ -1,25 +1,15 @@
1
1
  # frozen_string_literal: true
2
2
 
3
- require "net/http"
4
- require "json"
5
3
  require "yaml"
6
4
 
7
5
  module OpenFdaApi
8
6
  # Interact with the Drugs API Endpoint:
9
- # - Adverse Events
7
+ # - Adverse Events
10
8
  # - Product Labeling
11
9
  # - NDC Directory
12
10
  # - Recall Enforcement Reports
13
11
  # - Drugs@FDA)
14
- class Drugs
15
- attr_reader :client, :path_base
16
-
17
- def initialize(client)
18
- @client = client
19
- @host = "api.fda.gov"
20
- @path_base = "/drug"
21
- end
22
-
12
+ class Drugs < Endpoint
23
13
  # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
24
14
  # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/drug/event/searchable-fields/
25
15
  # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/drug/event/searchable-fields/
@@ -91,21 +81,8 @@ module OpenFdaApi
91
81
 
92
82
  private
93
83
 
94
- def build_query(query_input, valid_search_fields)
95
- QueryBuilder.new(query_input: query_input, valid_search_fields: valid_search_fields).build_query
96
- end
97
-
98
- def build_inputs(search:, sort:, count:, skip:, limit:)
99
- QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit)
100
- end
101
-
102
- def make_request(endpoint, query)
103
- url = "#{path_base}/#{endpoint}"
104
- if query.empty?
105
- client.connection.get(url)
106
- else
107
- client.connection.get(url, query)
108
- end.body
84
+ def endpoint_path
85
+ "/drug"
109
86
  end
110
87
  end
111
88
  end
@@ -0,0 +1,29 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Base class for all endpoints to share behavior like building queries and making requests
5
+ class Endpoint
6
+ attr_reader :client
7
+
8
+ def initialize(client)
9
+ @client = client
10
+ end
11
+
12
+ def build_query(query_input, valid_search_fields)
13
+ QueryBuilder.new(query_input: query_input, valid_search_fields: valid_search_fields).build_query
14
+ end
15
+
16
+ def build_inputs(search:, sort:, count:, skip:, limit:)
17
+ QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit)
18
+ end
19
+
20
+ def make_request(endpoint, query)
21
+ url = "#{endpoint_path}/#{endpoint}"
22
+ if query.empty?
23
+ client.connection.get(url)
24
+ else
25
+ client.connection.get(url, query)
26
+ end.body
27
+ end
28
+ end
29
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Interact with the Food API Endpoint:
5
+ # - Adverse Events
6
+ # - Recall Enforcement Reports
7
+ class Food < Endpoint
8
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/food/enforcement/searchable-fields/
9
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/food/enforcement/searchable-fields/
10
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/food/enforcement/searchable-fields/
11
+ # @param skip [Integer] Number of results to skip
12
+ # @param limit [Integer] Number of results to return
13
+ # @return Response from the API parsed as JSON
14
+ def adverse_events(search: [], sort: [], count: [], skip: 0, limit: 1)
15
+ endpoint = "event.json"
16
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
17
+ query = build_query(inputs, {}) # TODO: Upload valid fields
18
+ make_request(endpoint, query)
19
+ end
20
+
21
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/food/enforcement/searchable-fields/
22
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/food/enforcement/searchable-fields/
23
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/food/enforcement/searchable-fields/
24
+ # @param skip [Integer] Number of results to skip
25
+ # @param limit [Integer] Number of results to return
26
+ # @return Response from the API parsed as JSON
27
+ def recall_enforcement_reports(search: [], sort: [], count: [], skip: 0, limit: 1)
28
+ endpoint = "enforcement.json"
29
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
30
+ query = build_query(inputs, {}) # TODO: Upload valid fields
31
+ make_request(endpoint, query)
32
+ end
33
+
34
+ private
35
+
36
+ def endpoint_path
37
+ "/food"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,40 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Interact with the Other API Endpoint:
5
+ # - NSDE
6
+ # - Substance Data Reports
7
+ class Other < Endpoint
8
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/other/nsde/searchable-fields/
9
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/other/nsde/searchable-fields/
10
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/other/nsde/searchable-fields/
11
+ # @param skip [Integer] Number of results to skip
12
+ # @param limit [Integer] Number of results to return
13
+ # @return Response from the API parsed as JSON
14
+ def nsde(search: [], sort: [], count: [], skip: 0, limit: 1)
15
+ endpoint = "nsde.json"
16
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
17
+ query = build_query(inputs, {}) # TODO: Upload valid fields
18
+ make_request(endpoint, query)
19
+ end
20
+
21
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/other/substance/searchable-fields/
22
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/other/substance/searchable-fields/
23
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/other/substance/searchable-fields/
24
+ # @param skip [Integer] Number of results to skip
25
+ # @param limit [Integer] Number of results to return
26
+ # @return Response from the API parsed as JSON
27
+ def substance_data_reports(search: [], sort: [], count: [], skip: 0, limit: 1)
28
+ endpoint = "substance.json"
29
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
30
+ query = build_query(inputs, {}) # TODO: Upload valid fields
31
+ make_request(endpoint, query)
32
+ end
33
+
34
+ private
35
+
36
+ def endpoint_path
37
+ "/other"
38
+ end
39
+ end
40
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ module OpenFdaApi
4
+ # Interact with the Tobacco API Endpoint:
5
+ # - Problem Reports
6
+ class Tobacco < Endpoint
7
+ # @param search [Array<Hash>] Search fields defined in https://open.fda.gov/apis/tobacco/problem/searchable-fields/
8
+ # @param sort [Array<Hash>] Sort fields defined in https://open.fda.gov/apis/tobacco/problem/searchable-fields/
9
+ # @param count [Array<Hash>] Count fields defined https://open.fda.gov/apis/tobacco/problem/searchable-fields/
10
+ # @param skip [Integer] Number of results to skip
11
+ # @param limit [Integer] Number of results to return
12
+ # @return Response from the API parsed as JSON
13
+ def problem_reports(search: [], sort: [], count: [], skip: 0, limit: 1)
14
+ endpoint = "problem.json"
15
+ inputs = build_inputs(search: search, sort: sort, count: count, skip: skip, limit: limit)
16
+ query = build_query(inputs, {}) # TODO: Upload valid fields
17
+ make_request(endpoint, query)
18
+ end
19
+
20
+ private
21
+
22
+ def endpoint_path
23
+ "/tobacco"
24
+ end
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenFdaApi
4
- VERSION = "0.0.9"
4
+ VERSION = "0.0.12"
5
5
  end
data/lib/open_fda_api.rb CHANGED
@@ -7,7 +7,13 @@ module OpenFdaApi
7
7
  class Error < StandardError; end
8
8
 
9
9
  autoload :Client, "open_fda_api/client"
10
- autoload :Drugs, "open_fda_api/drugs"
10
+ autoload :Endpoint, "open_fda_api/endpoint"
11
+ autoload :AnimalAndVeterinary, "open_fda_api/animal_and_veterinary"
12
+ autoload :Drugs, "open_fda_api/drugs"
13
+ autoload :Device, "open_fda_api/device"
14
+ autoload :Food, "open_fda_api/food"
15
+ autoload :Other, "open_fda_api/other"
16
+ autoload :Tobacco, "open_fda_api/tobacco"
11
17
  autoload :QueryInputs, "open_fda_api/query_inputs"
12
18
  autoload :QueryBuilder, "open_fda_api/query_builder"
13
19
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: open_fda_api
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.12
5
5
  platform: ruby
6
6
  authors:
7
7
  - Hebron George
@@ -74,10 +74,16 @@ files:
74
74
  - bin/setup
75
75
  - lib/open_fda_api.rb
76
76
  - lib/open_fda_api/adverse_events_fields.yml
77
+ - lib/open_fda_api/animal_and_veterinary.rb
77
78
  - lib/open_fda_api/client.rb
79
+ - lib/open_fda_api/device.rb
78
80
  - lib/open_fda_api/drugs.rb
81
+ - lib/open_fda_api/endpoint.rb
82
+ - lib/open_fda_api/food.rb
83
+ - lib/open_fda_api/other.rb
79
84
  - lib/open_fda_api/query_builder.rb
80
85
  - lib/open_fda_api/query_inputs.rb
86
+ - lib/open_fda_api/tobacco.rb
81
87
  - lib/open_fda_api/version.rb
82
88
  - open_fda_api.gemspec
83
89
  homepage: https://github.com/hebron-george/open_fda_api