--- /dev/null
+module Ym4r\r
+ module GmPlugin\r
+ class GMapsAPIKeyConfigFileNotFoundException < StandardError\r
+ end\r
+ \r
+ class AmbiguousGMapsAPIKeyException < StandardError\r
+ end\r
+ \r
+ #Class fo the manipulation of the API key\r
+ class ApiKey\r
+ #Read the API key config for the current ENV\r
+ unless File.exist?(RAILS_ROOT + '/config/gmaps_api_key.yml')\r
+ raise GMapsAPIKeyConfigFileNotFoundException.new("File RAILS_ROOT/config/gmaps_api_key.yml not found")\r
+ else\r
+ env = ENV['RAILS_ENV'] || RAILS_ENV\r
+ GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[env]\r
+ end\r
+ \r
+ def self.get(options = {})\r
+ if options.has_key?(:key)\r
+ options[:key]\r
+ elsif GMAPS_API_KEY.is_a?(Hash)\r
+ #For this environment, multiple hosts are possible.\r
+ #:host must have been passed as option\r
+ if options.has_key?(:host)\r
+ GMAPS_API_KEY[options[:host]]\r
+ else\r
+ raise AmbiguousGMapsAPIKeyException.new(GMAPS_API_KEY.keys.join(","))\r
+ end\r
+ else\r
+ #Only one possible key: take it and ignore the :host option if it is there\r
+ GMAPS_API_KEY\r
+ end\r
+ end\r
+ end\r
+ end\r
+end\r