open_fda_api 0.0.12 → 0.0.13

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: 3f55d1b8140f12ed25ecf99fd227e0c053a50455abcc2153e03ba7a5f5d724bb
4
- data.tar.gz: 74f2219cfd2812e2576e9e748132332f049d9925b5afd763609528f0fa1a049e
3
+ metadata.gz: ea876aa2b2ba1588293e37e59f95271ec0361215a5fa68ce1cbfb447eba764d0
4
+ data.tar.gz: 1c19caa9c5e140dcefa5cbeee8acaa1fd1c48d6553b36f55b86505664ef10301
5
5
  SHA512:
6
- metadata.gz: '06953c4682f9bd4948c23a24035094452b85ee73bcb9c3a37f5e16151c39bedb90afab6b11881f73d9106cdf052dcc4d3bb98747b4126409fcbf9fb57eb59082'
7
- data.tar.gz: acbddbb9dc475a1243ef8415e411d1c365de227509d3dc7ceddd3221136b96329dea226acad155b4d87269dd754fcf59166ea880f2a053acccfc987b2374dc37
6
+ metadata.gz: 73786ceb0a046b754ad438c67393f3c7baa5c8205266d21df276be6e69ba06bbd5ed94488941364347bbccf0e69ca93874f7db1ad7f1c2bb942a5ae81798413c
7
+ data.tar.gz: 2f5b335ae39a62f77d72e436caf06a9b7304e02c3c0c81057a082ceb416ad2dff936003c98b7ac36c57fef47a3d64c58b6c4c215c0cbf7acc2ad6e2ecf33798c
data/CHANGELOG.md CHANGED
@@ -1,4 +1,7 @@
1
- ## [Unreleased]
1
+ ## openFDA API
2
+
3
+ ## [0.0.13] - 2022-01-27
4
+ - Set API key if it is available and send it in with every request
2
5
 
3
6
  ## [0.0.12] - 2022-01-24
4
7
  - Animal & Veterinary Endpoint
data/README.md CHANGED
@@ -19,7 +19,9 @@ bundle install
19
19
  ## Usage
20
20
 
21
21
  ```ruby
22
- client = OpenFdaApi.client
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.premarket_501ks(args)
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
- search = [{"patient.drug.openfda.pharm_class_epc" => "nonsteroidal+anti-inflammatory+drug" }]
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
- # patient.drug.openfda.pharm_class_epc:"nonsteroidal+anti-inflammatory+drug"&count=patient.reaction.reactionmeddrapt.exact
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 [QueryInput] query_input
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 = 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
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 = params[:search] || []
10
- @sort = params[:sort] || []
11
- @count = params[:count] || []
12
- @skip = params[:skip] || 0
13
- @limit = params[:limit] || nil
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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module OpenFdaApi
4
- VERSION = "0.0.12"
4
+ VERSION = "0.0.13"
5
5
  end
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.12
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-24 00:00:00.000000000 Z
11
+ date: 2022-01-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: faraday