Module: Lexile::Configuration
- Included in:
- Lexile
- Defined in:
- lib/lexile/configuration.rb
Constant Summary collapse
- VALID_CONNECTION_KEYS =
[:endpoint, :api_version, :user_agent, :testing, :timeout].freeze
- VALID_OPTIONS_KEYS =
[:username,:password].freeze
- DEFAULT_ENDPOINT =
'https://fabapi.lexile.com'
- DEFAULT_API_VERSION =
'/api/fab/v2.1'
- DEFAULT_USER_AGENT =
'Lexile API Ruby Gem by Curriculet'.freeze
- DEFAULT_TIMEOUT =
nil
- DEFAULT_TESTING =
false
- DEFAULT_USERNAME =
nil
- DEFAULT_PASSWORD =
nil
Class Method Summary collapse
-
.extended(base) ⇒ Object
Make sure we have the default values set when we get ‘extended’.
Instance Method Summary collapse
-
#api_url(path = nil) ⇒ Object
api_url Interpolate the base url for all calls return [String] the base url for all api calls.
- #config ⇒ Object
-
#configure {|_self| ... } ⇒ Object
Yields itself for use in the configuration block.
-
#options ⇒ Hash
Of all options.
-
#reset! ⇒ Object
reset! set all options to their defaults and free the client.
Class Method Details
.extended(base) ⇒ Object
Make sure we have the default values set when we get ‘extended’
21 22 23 |
# File 'lib/lexile/configuration.rb', line 21 def self.extended(base) base.reset! end |
Instance Method Details
#api_url(path = nil) ⇒ Object
api_url Interpolate the base url for all calls return [String] the base url for all api calls
47 48 49 |
# File 'lib/lexile/configuration.rb', line 47 def api_url( path = nil) [endpoint,path].compact.join('/') end |
#config ⇒ Object
51 52 53 |
# File 'lib/lexile/configuration.rb', line 51 def config self end |
#configure {|_self| ... } ⇒ Object
Yields itself for use in the configuration block
67 68 69 70 |
# File 'lib/lexile/configuration.rb', line 67 def configure yield self @client = Lexile::API::Client.new( self ) end |
#options ⇒ Hash
Returns of all options.
40 41 42 |
# File 'lib/lexile/configuration.rb', line 40 def Hash[ * VALID_CONFIG_KEYS.map { |key| [key, send(key)] }.flatten ] end |
#reset! ⇒ Object
reset! set all options to their defaults and free the client
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/lexile/configuration.rb', line 27 def reset! self.endpoint = DEFAULT_ENDPOINT self.api_version = DEFAULT_API_VERSION self.user_agent = DEFAULT_USER_AGENT self.timeout = DEFAULT_TIMEOUT self.testing = DEFAULT_TESTING self.username = DEFAULT_USERNAME self.password = DEFAULT_PASSWORD @client = nil end |