google_url_signatures 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 Jack Danger Canty
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.rdoc ADDED
@@ -0,0 +1,17 @@
1
+ = google_url_signatures
2
+
3
+ Description goes here.
4
+
5
+ == Note on Patches/Pull Requests
6
+
7
+ * Fork the project.
8
+ * Make your feature addition or bug fix.
9
+ * Add tests for it. This is important so I don't break it in a
10
+ future version unintentionally.
11
+ * Commit, do not mess with rakefile, version, or history.
12
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
13
+ * Send me a pull request. Bonus points for topic branches.
14
+
15
+ == Copyright
16
+
17
+ Copyright (c) 2010 Jack Danger Canty. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,31 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+
4
+ begin
5
+ require 'jeweler'
6
+ Jeweler::Tasks.new do |gem|
7
+ gem.name = "google_url_signatures"
8
+ gem.summary = %Q{Sign your urls for Google's Places and Maps V3 APIs}
9
+ gem.description = %Q{Lets you create a signature for accessing Google's Places API and Maps V3 API}
10
+ gem.email = "gitcommit@6brand.com"
11
+ gem.homepage = "http://github.com/JackDanger/google_url_signatures"
12
+ gem.authors = ["Jack Danger Canty"]
13
+ gem.add_dependency "ruby-hmac", ">= 0"
14
+ gem.add_development_dependency "shoulda", ">= 0"
15
+ # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
16
+ end
17
+ Jeweler::GemcutterTasks.new
18
+ rescue LoadError
19
+ puts "Jeweler (or a dependency) not available. Install it with: gem install jeweler"
20
+ end
21
+
22
+ require 'rake/testtask'
23
+ Rake::TestTask.new(:test) do |test|
24
+ test.libs << 'lib' << 'test'
25
+ test.pattern = 'test/**/test_*.rb'
26
+ test.verbose = true
27
+ end
28
+
29
+ task :test => :check_dependencies
30
+
31
+ task :default => :test
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.5.0
@@ -0,0 +1,23 @@
1
+ # Based on the code at:
2
+ # http://gmaps-samples.googlecode.com/svn/trunk/urlsigning/urlsigner.rb
3
+
4
+ require 'base64'
5
+ require 'uri'
6
+ # hmac, and hmac-sha1, are from # gem install ruby-hmac
7
+ require 'hmac'
8
+ require 'hmac-sha1'
9
+
10
+ module GoogleUrlSignatures
11
+
12
+ def self.sign(key, url)
13
+ uri = URI.parse url
14
+
15
+ path_and_query = uri.path + '?' + uri.query
16
+
17
+ decoded_key = Base64.decode64(key.tr('-_','+/'))
18
+ decoded_signature = (HMAC::SHA1.new(decoded_key) << path_and_query).digest
19
+ signature = Base64.encode64(decoded_signature).tr('+/','-_')
20
+
21
+ "#{uri.scheme}://#{uri.host}#{path_and_query}&signature=#{signature}"
22
+ end
23
+ end
data/test/helper.rb ADDED
@@ -0,0 +1,10 @@
1
+ require 'rubygems'
2
+ require 'test/unit'
3
+ require 'shoulda'
4
+
5
+ $LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
6
+ $LOAD_PATH.unshift(File.dirname(__FILE__))
7
+ require 'google_url_signatures'
8
+
9
+ class Test::Unit::TestCase
10
+ end
@@ -0,0 +1,19 @@
1
+ require 'helper'
2
+
3
+ class TestGoogleUrlSignatures < Test::Unit::TestCase
4
+
5
+ context "signing" do
6
+ context "with a valid key and url" do
7
+ setup {
8
+ @url = "http://maps.google.com/maps/api/geocode/json?address=New+York&sensor=false&client=ABC123"
9
+ @key = "vNIXE0xscrmjlyV-12Nj_BvUPaw="
10
+ @signed = GoogleUrlSignatures.sign(@key, @url)
11
+ }
12
+ should "generate signed url" do
13
+ assert_equal "http://maps.google.com/maps/api/geocode/json?address=New+York&sensor=false&client=ABC123&signature=Wjm6Tt9aygtehoibWXjkD1DqEH4=\n",
14
+ @signed
15
+ end
16
+ end
17
+ end
18
+
19
+ end
metadata ADDED
@@ -0,0 +1,93 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: google_url_signatures
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 5
8
+ - 0
9
+ version: 0.5.0
10
+ platform: ruby
11
+ authors:
12
+ - Jack Danger Canty
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-10-15 00:00:00 -07:00
18
+ default_executable:
19
+ dependencies:
20
+ - !ruby/object:Gem::Dependency
21
+ name: ruby-hmac
22
+ prerelease: false
23
+ requirement: &id001 !ruby/object:Gem::Requirement
24
+ requirements:
25
+ - - ">="
26
+ - !ruby/object:Gem::Version
27
+ segments:
28
+ - 0
29
+ version: "0"
30
+ type: :runtime
31
+ version_requirements: *id001
32
+ - !ruby/object:Gem::Dependency
33
+ name: shoulda
34
+ prerelease: false
35
+ requirement: &id002 !ruby/object:Gem::Requirement
36
+ requirements:
37
+ - - ">="
38
+ - !ruby/object:Gem::Version
39
+ segments:
40
+ - 0
41
+ version: "0"
42
+ type: :development
43
+ version_requirements: *id002
44
+ description: Lets you create a signature for accessing Google's Places API and Maps V3 API
45
+ email: gitcommit@6brand.com
46
+ executables: []
47
+
48
+ extensions: []
49
+
50
+ extra_rdoc_files:
51
+ - LICENSE
52
+ - README.rdoc
53
+ files:
54
+ - LICENSE
55
+ - README.rdoc
56
+ - Rakefile
57
+ - VERSION
58
+ - lib/google_url_signatures.rb
59
+ - test/helper.rb
60
+ - test/test_google_url_signatures.rb
61
+ has_rdoc: true
62
+ homepage: http://github.com/JackDanger/google_url_signatures
63
+ licenses: []
64
+
65
+ post_install_message:
66
+ rdoc_options:
67
+ - --charset=UTF-8
68
+ require_paths:
69
+ - lib
70
+ required_ruby_version: !ruby/object:Gem::Requirement
71
+ requirements:
72
+ - - ">="
73
+ - !ruby/object:Gem::Version
74
+ segments:
75
+ - 0
76
+ version: "0"
77
+ required_rubygems_version: !ruby/object:Gem::Requirement
78
+ requirements:
79
+ - - ">="
80
+ - !ruby/object:Gem::Version
81
+ segments:
82
+ - 0
83
+ version: "0"
84
+ requirements: []
85
+
86
+ rubyforge_project:
87
+ rubygems_version: 1.3.6
88
+ signing_key:
89
+ specification_version: 3
90
+ summary: Sign your urls for Google's Places and Maps V3 APIs
91
+ test_files:
92
+ - test/helper.rb
93
+ - test/test_google_url_signatures.rb