Class: Bart::Configuration
- Inherits:
-
Object
- Object
- Bart::Configuration
- Defined in:
- lib/bart_api/configuration.rb
Constant Summary collapse
- DEFAULT_CONFIGURATION =
The defaults to use for any configuration options that are not provided
{ adapter: :httparty, debug_output: false, base_uri: 'http://api.bart.gov', refresh_time: 30, api_key: 'MW9S-E7SL-26DU-VV8V' }
- REQUIRED_CONFIGURATION =
The options required when configuring a BART instance
[ :base_uri, :api_key, :refresh_time ]
Instance Attribute Summary collapse
-
#adapter ⇒ Object
The adapter to use for network communication.
-
#api_key ⇒ Object
The key used to make requests, defaulting to BART’s public key.
-
#base_uri ⇒ Object
The base URL of the BART system.
-
#debug_output ⇒ Object
The output stream to which debug information should be written.
-
#refresh_time ⇒ Object
The number of seconds real-time results are cached for.
-
#version ⇒ Object
The version of the BART system.
Instance Method Summary collapse
-
#initialize ⇒ Configuration
constructor
A new instance of Configuration.
-
#validate! ⇒ Object
Ensure that all required configurations have been given a value.
Constructor Details
#initialize ⇒ Configuration
Returns a new instance of Configuration.
32 33 34 35 36 37 38 |
# File 'lib/bart_api/configuration.rb', line 32 def initialize # Apply the default set of configurations before anything else to ensure # all options are initialized. DEFAULT_CONFIGURATION.each do |name, value| send("#{name}=", value) end end |
Instance Attribute Details
#adapter ⇒ Object
The adapter to use for network communication
8 9 10 |
# File 'lib/bart_api/configuration.rb', line 8 def adapter @adapter end |
#api_key ⇒ Object
The key used to make requests, defaulting to BART’s public key.
12 13 14 |
# File 'lib/bart_api/configuration.rb', line 12 def api_key @api_key end |
#base_uri ⇒ Object
The base URL of the BART system
6 7 8 |
# File 'lib/bart_api/configuration.rb', line 6 def base_uri @base_uri end |
#debug_output ⇒ Object
The output stream to which debug information should be written
10 11 12 |
# File 'lib/bart_api/configuration.rb', line 10 def debug_output @debug_output end |
#refresh_time ⇒ Object
The number of seconds real-time results are cached for.
14 15 16 |
# File 'lib/bart_api/configuration.rb', line 14 def refresh_time @refresh_time end |
#version ⇒ Object
The version of the BART system
4 5 6 |
# File 'lib/bart_api/configuration.rb', line 4 def version @version end |
Instance Method Details
#validate! ⇒ Object
Ensure that all required configurations have been given a value. Returns true if all required configuration options have been set.
42 43 44 45 46 47 |
# File 'lib/bart_api/configuration.rb', line 42 def validate! REQUIRED_CONFIGURATION.each do |name| raise "`#{name}` is a required configuration option, but was not given a value." if send("#{name}").nil? end true end |