module Echowrap::Configurable
Attributes
api_key[W]
connection_options[RW]
consumer_key[W]
endpoint[RW]
middleware[RW]
Public Class Methods
keys()
click to toggle source
# File lib/echowrap/configurable.rb, line 13 def keys @keys ||= [ :api_key, :consumer_key, :shared_secret, :endpoint, :connection_options, :middleware, ] end
Public Instance Methods
configure() { |self| ... }
click to toggle source
Convenience method to allow configuration options to be set in a block
@raise [Echowrap::Error::ConfigurationError] Error
is raised when supplied
echonest credentials are not a String or Symbol.
# File lib/echowrap/configurable.rb, line 29 def configure yield self validate_credential_type! self end
credentials?()
click to toggle source
@return [Boolean]
# File lib/echowrap/configurable.rb, line 36 def credentials? credentials.values.all? end
reset!()
click to toggle source
# File lib/echowrap/configurable.rb, line 40 def reset! Echowrap::Configurable.keys.each do |key| instance_variable_set(:"@#{key}", Echowrap::Default.options[key]) end self end
Also aliased as: setup
Private Instance Methods
application_only_auth?()
click to toggle source
# File lib/echowrap/configurable.rb, line 50 def application_only_auth? true end
credentials()
click to toggle source
@return [Hash]
# File lib/echowrap/configurable.rb, line 55 def credentials { :api_key => @api_key, :consumer_key => @consumer_key, :consumer_secret => @shared_secret, } end
options()
click to toggle source
@return [Hash]
# File lib/echowrap/configurable.rb, line 64 def options Hash[Echowrap::Configurable.keys.map{|key| [key, instance_variable_get(:"@#{key}")]}] end
validate_credential_type!()
click to toggle source
Ensures that all credentials set during configuration are of a valid type. Valid types are String and Symbol.
@raise [Echowrap::Error::ConfigurationError] Error
is raised when
supplied echonest credentials are not a String or Symbol.
# File lib/echowrap/configurable.rb, line 73 def validate_credential_type! credentials.each do |credential, value| next if value.nil? unless value.is_a?(String) || value.is_a?(Symbol) raise(Error::ConfigurationError, "Invalid #{credential} specified: #{value} must be a string or symbol.") end end end