X-Git-Url: https://projects.mako.cc/source/selectricity-live/blobdiff_plain/baf9ff0ec39c13f52ee8d4f087641dc5fcc9c53b..fcc68b4dc198b7cb0cf93467d96038b0844675fe:/vendor/plugins/ym4r_gm/lib/gm_plugin/key.rb diff --git a/vendor/plugins/ym4r_gm/lib/gm_plugin/key.rb b/vendor/plugins/ym4r_gm/lib/gm_plugin/key.rb new file mode 100644 index 0000000..0de9c18 --- /dev/null +++ b/vendor/plugins/ym4r_gm/lib/gm_plugin/key.rb @@ -0,0 +1,37 @@ +module Ym4r + module GmPlugin + class GMapsAPIKeyConfigFileNotFoundException < StandardError + end + + class AmbiguousGMapsAPIKeyException < StandardError + end + + #Class fo the manipulation of the API key + class ApiKey + #Read the API key config for the current ENV + unless File.exist?(RAILS_ROOT + '/config/gmaps_api_key.yml') + raise GMapsAPIKeyConfigFileNotFoundException.new("File RAILS_ROOT/config/gmaps_api_key.yml not found") + else + env = ENV['RAILS_ENV'] || RAILS_ENV + GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[env] + end + + def self.get(options = {}) + if options.has_key?(:key) + options[:key] + elsif GMAPS_API_KEY.is_a?(Hash) + #For this environment, multiple hosts are possible. + #:host must have been passed as option + if options.has_key?(:host) + GMAPS_API_KEY[options[:host]] + else + raise AmbiguousGMapsAPIKeyException.new(GMAPS_API_KEY.keys.join(",")) + end + else + #Only one possible key: take it and ignore the :host option if it is there + GMAPS_API_KEY + end + end + end + end +end