googleapi_manager 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/MIT-LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 [name of plugin creator]
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.markdown ADDED
@@ -0,0 +1,22 @@
1
+ GoogleapiManager
2
+ ================
3
+
4
+ Manage your google api keys for different hosts.
5
+ Rails 3 only.
6
+
7
+ Usage
8
+ -----
9
+ # sample config/google_api_keys.yml
10
+ # read the source for alternative config files
11
+ development:
12
+ ABQIAAA....
13
+ test:
14
+ ABQIAAA....
15
+ production:
16
+ skroutz.gr: ABQIAAAA...
17
+ merchants.skroutz.gr: ABQIAAAA...
18
+
19
+ # template.erb
20
+ <%= google_api_js :host => request.host %>
21
+ # outputs:
22
+ <script type="text/javascript" src="http://www.google.com/jsapi?key=<key>"></script>
data/Rakefile ADDED
@@ -0,0 +1,23 @@
1
+ require 'rake'
2
+ require 'rake/testtask'
3
+ require 'rake/rdoctask'
4
+
5
+ desc 'Default: run unit tests.'
6
+ task :default => :test
7
+
8
+ desc 'Test the googleapi_manager plugin.'
9
+ Rake::TestTask.new(:test) do |t|
10
+ t.libs << 'lib'
11
+ t.libs << 'test'
12
+ t.pattern = 'test/**/*_test.rb'
13
+ t.verbose = true
14
+ end
15
+
16
+ desc 'Generate documentation for the googleapi_manager plugin.'
17
+ Rake::RDocTask.new(:rdoc) do |rdoc|
18
+ rdoc.rdoc_dir = 'rdoc'
19
+ rdoc.title = 'GoogleapiManager'
20
+ rdoc.options << '--line-numbers' << '--inline-source'
21
+ rdoc.rdoc_files.include('README')
22
+ rdoc.rdoc_files.include('lib/**/*.rb')
23
+ end
@@ -0,0 +1,55 @@
1
+ require 'rails'
2
+
3
+ module GoogleApiManager
4
+
5
+ class Railtie < Rails::Railtie
6
+ initializer :after_initialize do
7
+ ActionView::Base.send :include, GoogleApiManager::ApiKeyHelper
8
+ end
9
+ end
10
+
11
+ class GoogleAPIKeyConfigFileNotFoundException < StandardError; end
12
+ class AmbiguousGoogleAPIKeyException < StandardError; end
13
+
14
+ module ApiKey
15
+ extend self
16
+
17
+ def google_api_key
18
+ config_file = File.join(Rails.root, 'config', 'google_api_keys.yml')
19
+ unless File.exist? config_file
20
+ raise GoogleAPIKeyConfigFileNotFoundException.new("File #{config_file} not found")
21
+ else
22
+ YAML.load_file(config_file)[Rails.env]
23
+ end
24
+ end
25
+
26
+ def get(options = {})
27
+ if options.has_key?(:key)
28
+ options[:key]
29
+ elsif google_api_key.is_a?(Hash)
30
+ #For this environment, multiple hosts are possible.
31
+ #:host must have been passed as option
32
+ if options.has_key?(:host)
33
+ google_api_key[options[:host]]
34
+ else
35
+ raise AmbiguousGoogleAPIKeyException.new(google_api_key.keys.join(","))
36
+ end
37
+ else
38
+ google_api_key
39
+ end
40
+ end
41
+
42
+ end
43
+
44
+ module ApiKeyHelper
45
+ def google_api_js(options={})
46
+ key = GoogleApiManager::ApiKey.get(options)
47
+ html = <<-HTML
48
+ <script type="text/javascript" src="http://www.google.com/jsapi?key=#{key}">
49
+ </script>
50
+ HTML
51
+ html.html_safe
52
+ end
53
+ end
54
+
55
+ end
metadata ADDED
@@ -0,0 +1,65 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: googleapi_manager
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 0
8
+ - 1
9
+ version: 0.0.1
10
+ platform: ruby
11
+ authors:
12
+ - Christos Trochalakis
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-07-05 00:00:00 +03:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: " Manage your google api keys for various hosts. Rails 3 only.\n"
22
+ email: yatiohi@ideopolis.gr
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files: []
28
+
29
+ files:
30
+ - README.markdown
31
+ - Rakefile
32
+ - MIT-LICENSE
33
+ - lib/googleapi_manager.rb
34
+ has_rdoc: true
35
+ homepage: http://github.com/ctrochalakis/googleapi_manager
36
+ licenses: []
37
+
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ segments:
48
+ - 0
49
+ version: "0"
50
+ required_rubygems_version: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - ">="
53
+ - !ruby/object:Gem::Version
54
+ segments:
55
+ - 0
56
+ version: "0"
57
+ requirements: []
58
+
59
+ rubyforge_project:
60
+ rubygems_version: 1.3.6
61
+ signing_key:
62
+ specification_version: 3
63
+ summary: Rails 3 helper for managing google api keys.
64
+ test_files: []
65
+