fix security issue
[selectricity-live] / vendor / plugins / ym4r_gm / lib / gm_plugin / key.rb
1 module Ym4r\r
2   module GmPlugin\r
3     class GMapsAPIKeyConfigFileNotFoundException < StandardError\r
4     end\r
5         \r
6     class AmbiguousGMapsAPIKeyException < StandardError\r
7     end\r
8     \r
9     #Class fo the manipulation of the API key\r
10     class ApiKey\r
11       #Read the API key config for the current ENV\r
12       unless File.exist?(RAILS_ROOT + '/config/gmaps_api_key.yml')\r
13         raise GMapsAPIKeyConfigFileNotFoundException.new("File RAILS_ROOT/config/gmaps_api_key.yml not found")\r
14       else\r
15         env = ENV['RAILS_ENV'] || RAILS_ENV\r
16         GMAPS_API_KEY = YAML.load_file(RAILS_ROOT + '/config/gmaps_api_key.yml')[env]\r
17       end\r
18       \r
19       def self.get(options = {})\r
20         if options.has_key?(:key)\r
21           options[:key]\r
22         elsif GMAPS_API_KEY.is_a?(Hash)\r
23           #For this environment, multiple hosts are possible.\r
24           #:host must have been passed as option\r
25           if options.has_key?(:host)\r
26             GMAPS_API_KEY[options[:host]]\r
27           else\r
28             raise AmbiguousGMapsAPIKeyException.new(GMAPS_API_KEY.keys.join(","))\r
29           end\r
30         else\r
31           #Only one possible key: take it and ignore the :host option if it is there\r
32           GMAPS_API_KEY\r
33         end\r
34       end\r
35     end\r
36   end\r
37 end\r

Benjamin Mako Hill || Want to submit a patch?