Class: Inferno::DSL::FHIRClientBuilder
- Inherits:
-
Object
- Object
- Inferno::DSL::FHIRClientBuilder
- Defined in:
- lib/inferno/dsl/fhir_client_builder.rb
Overview
DSL for configuring FHIR clients
Instance Attribute Summary collapse
-
#runnable ⇒ Object
Returns the value of attribute runnable.
Instance Method Summary collapse
-
#auth_info(auth_info = nil) ⇒ void
Define auth info for a client.
-
#bearer_token(bearer_token = nil) ⇒ void
Define the bearer token for a client.
- #build(runnable, block) ⇒ Object
-
#headers(headers = nil) ⇒ void
Define custom headers for a client.
- #method_missing(name) ⇒ Object
-
#oauth_credentials(oauth_credentials = nil) ⇒ void
Define OAuth credentials for a client.
- #respond_to_missing?(name) ⇒ Boolean
-
#url(url = nil) ⇒ void
Define the base FHIR url for a client.
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name) ⇒ Object
121 122 123 124 125 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 121 def method_missing(name, ...) return runnable.send(name, ...) if runnable.respond_to? name super end |
Instance Attribute Details
#runnable ⇒ Object
Returns the value of attribute runnable.
38 39 40 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 38 def runnable @runnable end |
Instance Method Details
#auth_info(auth_info = nil) ⇒ void
This method returns an undefined value.
Define auth info for a client. Auth info contains info needed for client to perform authorization and refresh access token when necessary
103 104 105 106 107 108 109 110 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 103 def auth_info(auth_info = nil) @auth_info ||= if auth_info.is_a? Symbol runnable.send(auth_info) else auth_info end end |
#bearer_token(bearer_token = nil) ⇒ void
This method returns an undefined value.
Define the bearer token for a client. A string or symbol can be provided. A string is interpreted as a token. A symbol is interpreted as the name of an input to the Runnable.
75 76 77 78 79 80 81 82 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 75 def bearer_token(bearer_token = nil) @bearer_token ||= if bearer_token.is_a? Symbol runnable.send(bearer_token) else bearer_token end end |
#build(runnable, block) ⇒ Object
41 42 43 44 45 46 47 48 49 50 51 52 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 41 def build(runnable, block) self.runnable = runnable instance_exec(self, &block) FHIR::Client.new(url).tap do |client| client.additional_headers = headers if headers client.default_json client.set_bearer_token bearer_token if bearer_token oauth_credentials&.add_to_client(client) auth_info&.add_to_client(client) end end |
#headers(headers = nil) ⇒ void
This method returns an undefined value.
Define custom headers for a client
116 117 118 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 116 def headers(headers = nil) @headers ||= headers end |
#oauth_credentials(oauth_credentials = nil) ⇒ void
This method returns an undefined value.
Define OAuth credentials for a client. These can allow a client to automatically refresh its access token when it expires.
89 90 91 92 93 94 95 96 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 89 def oauth_credentials(oauth_credentials = nil) @oauth_credentials ||= if oauth_credentials.is_a? Symbol runnable.send(oauth_credentials) else oauth_credentials end end |
#respond_to_missing?(name) ⇒ Boolean
128 129 130 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 128 def respond_to_missing?(name) runnable.respond_to?(name) || super end |
#url(url = nil) ⇒ void
This method returns an undefined value.
Define the base FHIR url for a client. A string or symbol can be provided. A string is interpreted as a url. A symbol is interpreted as the name of an input to the Runnable.
60 61 62 63 64 65 66 67 |
# File 'lib/inferno/dsl/fhir_client_builder.rb', line 60 def url(url = nil) @url ||= if url.is_a? Symbol runnable.send(url) else url end&.chomp('/') end |