open_fda_api 0.0.12 → 0.0.13
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/CHANGELOG.md +4 -1
- data/README.md +32 -4
- data/lib/open_fda_api/endpoint.rb +1 -1
- data/lib/open_fda_api/query_builder.rb +8 -6
- data/lib/open_fda_api/query_inputs.rb +7 -6
- data/lib/open_fda_api/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ea876aa2b2ba1588293e37e59f95271ec0361215a5fa68ce1cbfb447eba764d0
|
4
|
+
data.tar.gz: 1c19caa9c5e140dcefa5cbeee8acaa1fd1c48d6553b36f55b86505664ef10301
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 73786ceb0a046b754ad438c67393f3c7baa5c8205266d21df276be6e69ba06bbd5ed94488941364347bbccf0e69ca93874f7db1ad7f1c2bb942a5ae81798413c
|
7
|
+
data.tar.gz: 2f5b335ae39a62f77d72e436caf06a9b7304e02c3c0c81057a082ceb416ad2dff936003c98b7ac36c57fef47a3d64c58b6c4c215c0cbf7acc2ad6e2ecf33798c
|
data/CHANGELOG.md
CHANGED
data/README.md
CHANGED
@@ -19,7 +19,9 @@ bundle install
|
|
19
19
|
## Usage
|
20
20
|
|
21
21
|
```ruby
|
22
|
-
client = OpenFdaApi.
|
22
|
+
client = OpenFdaApi::Client.new
|
23
|
+
# or if you have registered an API key
|
24
|
+
client = OpenFdaApi::Client.new(api_key: ENV['OPEN_FDA_API_KEY'])
|
23
25
|
|
24
26
|
# First 20 results where (fieldA=foo AND fieldB=bar) OR (fieldC=baz AND fieldA exists)
|
25
27
|
# Sorted by (fieldD) in descending order
|
@@ -42,7 +44,7 @@ client.drugs.recall_enforcement_reports(args)
|
|
42
44
|
client.drugs.drugs_at_fda(args)
|
43
45
|
|
44
46
|
# Device API
|
45
|
-
client.device.
|
47
|
+
client.device.premarket_510ks(args)
|
46
48
|
client.device.classification(args)
|
47
49
|
client.device.recall_enforcement_reports(args)
|
48
50
|
client.device.adverse_events(args)
|
@@ -72,9 +74,35 @@ The openFDA API can be queried with these arguments: `search`, `sort`, `count`,
|
|
72
74
|
that are ANDed together and all the elements in the array are ORed together. Here are some examples to illustrate:
|
73
75
|
|
74
76
|
```ruby
|
75
|
-
|
77
|
+
# Default arguments
|
78
|
+
args = {
|
79
|
+
search: [],
|
80
|
+
sort: [],
|
81
|
+
count: [],
|
82
|
+
skip: 0,
|
83
|
+
limit: 1,
|
84
|
+
}
|
85
|
+
|
86
|
+
# Search for a single field
|
87
|
+
args = {
|
88
|
+
search: [{ fieldA: "value" }]
|
89
|
+
}
|
90
|
+
|
91
|
+
# Search for field A AND field B
|
92
|
+
args = {
|
93
|
+
search: [{ fieldA: "value", fieldB: "other value" }]
|
94
|
+
}
|
95
|
+
|
96
|
+
# Search for field A OR field B
|
97
|
+
args = {
|
98
|
+
search: [{ fieldA: "value"}, { fieldB: "other value" }]
|
99
|
+
}
|
76
100
|
|
77
|
-
#
|
101
|
+
# Search for field A or field B, and skip the first 10 results
|
102
|
+
args = {
|
103
|
+
search: [{ fieldA: "value"}, { fieldB: "other value" }],
|
104
|
+
skip: 10
|
105
|
+
}
|
78
106
|
```
|
79
107
|
|
80
108
|
## Development
|
@@ -14,7 +14,7 @@ module OpenFdaApi
|
|
14
14
|
end
|
15
15
|
|
16
16
|
def build_inputs(search:, sort:, count:, skip:, limit:)
|
17
|
-
QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit)
|
17
|
+
QueryInputs.new(search: search, sort: sort, count: count, skip: skip, limit: limit, api_key: client.api_key)
|
18
18
|
end
|
19
19
|
|
20
20
|
def make_request(endpoint, query)
|
@@ -26,21 +26,23 @@ module OpenFdaApi
|
|
26
26
|
# is 25000. See Paging if you require paging through larger result sets.
|
27
27
|
class QueryBuilder
|
28
28
|
# @param [Hash] valid_search_fields
|
29
|
-
# @param [
|
29
|
+
# @param [QueryInputs] query_input
|
30
30
|
def initialize(query_input:, valid_search_fields:)
|
31
31
|
# TODO: Turn validations back on once we get basic functionality working; need to flex on different field types
|
32
32
|
# validate_arguments!(valid_search_fields, query_input: query_input)
|
33
33
|
warn "You've passed in a valid_search_fields arg but it isn't being used right now..." if valid_search_fields
|
34
|
-
@search
|
35
|
-
@sort
|
36
|
-
@count
|
37
|
-
@skip
|
38
|
-
@limit
|
34
|
+
@search = build_query_string(query_fields: query_input.search)
|
35
|
+
@sort = build_query_string(query_fields: query_input.sort)
|
36
|
+
@count = build_query_string(query_fields: query_input.count)
|
37
|
+
@skip = build_skip_string(query_input.skip)
|
38
|
+
@limit = query_input.limit
|
39
|
+
@api_key = query_input.api_key
|
39
40
|
end
|
40
41
|
|
41
42
|
# @return [Hash] the query string portion of a request
|
42
43
|
def build_query
|
43
44
|
{
|
45
|
+
api_key: @api_key,
|
44
46
|
search: @search,
|
45
47
|
sort: @sort,
|
46
48
|
count: @count,
|
@@ -3,14 +3,15 @@
|
|
3
3
|
module OpenFdaApi
|
4
4
|
# Group of inputs to build the query against the API with
|
5
5
|
class QueryInputs
|
6
|
-
attr_reader :search, :sort, :count, :skip, :limit
|
6
|
+
attr_reader :search, :sort, :count, :skip, :limit, :api_key
|
7
7
|
|
8
8
|
def initialize(**params)
|
9
|
-
@search
|
10
|
-
@sort
|
11
|
-
@count
|
12
|
-
@skip
|
13
|
-
@limit
|
9
|
+
@search = params[:search] || []
|
10
|
+
@sort = params[:sort] || []
|
11
|
+
@count = params[:count] || []
|
12
|
+
@skip = params[:skip] || 0
|
13
|
+
@limit = params[:limit] || nil
|
14
|
+
@api_key = params[:api_key] || nil
|
14
15
|
end
|
15
16
|
end
|
16
17
|
end
|
data/lib/open_fda_api/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: open_fda_api
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Hebron George
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-01-
|
11
|
+
date: 2022-01-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: faraday
|