static-gmaps 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt ADDED
@@ -0,0 +1,5 @@
1
+ === 0.0.1 / 2008-02-25
2
+
3
+ * 1 major enhancement
4
+ * Birthday!
5
+
data/LICENSE.txt ADDED
@@ -0,0 +1,21 @@
1
+ The MIT License
2
+
3
+ Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/Manifest.txt ADDED
@@ -0,0 +1,8 @@
1
+ History.txt
2
+ LICENSE.txt
3
+ Manifest.txt
4
+ README.txt
5
+ Rakefile
6
+ lib/static_gmaps.rb
7
+ spec/static_gmaps_spec.rb
8
+ spec/test_image.gif
data/README.txt ADDED
@@ -0,0 +1,57 @@
1
+ = StaticGmaps
2
+
3
+ * http://static-gmaps.rubyforge.org/
4
+
5
+ == DESCRIPTION:
6
+
7
+ Provides an interface to the Google Static Maps API.
8
+
9
+ == FEATURES/PROBLEMS:
10
+
11
+ * See SYNOPSIS.
12
+
13
+ == SYNOPSIS:
14
+
15
+ # Get from http://code.google.com/apis/maps/signup.html
16
+ GOOGLE_MAPS_API_KEY = ''
17
+
18
+ map = StaticGmaps::Map.new :center => [ 40.714728, -73.998672 ],
19
+ :zoom => 12,
20
+ :size => [ 500, 400 ],
21
+ :map_type => :roadmap,
22
+ :key => GOOGLE_MAPS_API_KEY
23
+ map.url => 'http://maps.google.com/staticmap?center=40.714728,-73.998672&zoom=12&size=500x400&map_type=roadmap&key=KEY
24
+ map.to_blob => GIF Data
25
+
26
+ == REQUIREMENTS:
27
+
28
+ * None.
29
+
30
+ == INSTALL:
31
+
32
+ * sudo gem install static-gmaps
33
+
34
+ == LICENSE:
35
+
36
+ (The MIT License)
37
+
38
+ Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
39
+
40
+ Permission is hereby granted, free of charge, to any person obtaining
41
+ a copy of this software and associated documentation files (the
42
+ 'Software'), to deal in the Software without restriction, including
43
+ without limitation the rights to use, copy, modify, merge, publish,
44
+ distribute, sublicense, and/or sell copies of the Software, and to
45
+ permit persons to whom the Software is furnished to do so, subject to
46
+ the following conditions:
47
+
48
+ The above copyright notice and this permission notice shall be
49
+ included in all copies or substantial portions of the Software.
50
+
51
+ THE SOFTWARE IS PROVIDED 'AS IS', WITHOUT WARRANTY OF ANY KIND,
52
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
53
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.
54
+ IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY
55
+ CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT,
56
+ TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE
57
+ SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/Rakefile ADDED
@@ -0,0 +1,51 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'rubygems'
24
+ require 'hoe'
25
+ require './lib/static_gmaps.rb'
26
+ begin
27
+ require 'spec/rake/spectask'
28
+ rescue LoadError
29
+ puts 'To use rspec for testing you must install rspec gem:'
30
+ puts '$ sudo gem install rspec'
31
+ exit
32
+ end
33
+
34
+ Hoe.new('static-gmaps', StaticGmaps::VERSION) do |p|
35
+ p.rubyforge_name = 'static-gmaps'
36
+ p.author = 'John Wulff'
37
+ p.email = 'johnwulff@gmail.com'
38
+ p.summary = 'Provides an interface to the Google Static Maps API.'
39
+ p.description = p.paragraphs_of('README.txt', 2..5).join("\n\n")
40
+ p.url = p.paragraphs_of('README.txt', 0).first.split(/\n/)[1..-1]
41
+ p.changes = p.paragraphs_of('History.txt', 0..1).join("\n\n")
42
+ end
43
+
44
+ desc "Run all examples"
45
+ Spec::Rake::SpecTask.new('spec') do |t|
46
+ t.spec_files = FileList['spec/*.rb']
47
+ end
48
+
49
+ task :default => :spec
50
+
51
+ # vim: syntax=Ruby
@@ -0,0 +1,77 @@
1
+ # The MIT License
2
+ #
3
+ # Copyright (c) 2008 John Wulff <johnwulff@gmail.com>
4
+ #
5
+ # Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ # of this software and associated documentation files (the "Software"), to deal
7
+ # in the Software without restriction, including without limitation the rights
8
+ # to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ # copies of the Software, and to permit persons to whom the Software is
10
+ # furnished to do so, subject to the following conditions:
11
+ #
12
+ # The above copyright notice and this permission notice shall be included in
13
+ # all copies or substantial portions of the Software.
14
+ #
15
+ # THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ # IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ # FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ # AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ # LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ # OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ # THE SOFTWARE.
22
+
23
+ require 'net/http'
24
+
25
+ module StaticGmaps
26
+ VERSION = '0.0.1'
27
+
28
+ class Map
29
+ DEFAULT_CENTER = [ 0, 0 ]
30
+ DEFAULT_ZOOM = 1
31
+ DEFAULT_SIZE = [ 500, 400 ]
32
+ DEFAULT_MAP_TYPE = :roadmap
33
+ DEFAULT_KEY = 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA'
34
+
35
+ attr_accessor :center,
36
+ :zoom,
37
+ :size,
38
+ :map_type,
39
+ :key
40
+
41
+ def initialize(options = {})
42
+ self.center = options[:center] || DEFAULT_CENTER
43
+ self.zoom = options[:zoom] || DEFAULT_ZOOM
44
+ self.size = options[:size] || DEFAULT_SIZE
45
+ self.map_type = options[:map_type] || DEFAULT_MAP_TYPE
46
+ self.key = options[:key] || DEFAULT_KEY
47
+ end
48
+
49
+ def width
50
+ size[0]
51
+ end
52
+
53
+ def height
54
+ size[1]
55
+ end
56
+
57
+ def url
58
+ return "http://maps.google.com/staticmap?center=#{center[0]},#{center[1]}&zoom=#{zoom}&size=#{size[0]}x#{size[1]}&map_type=#{map_type}&key=#{key}"
59
+ end
60
+
61
+ def to_blob
62
+ fetch
63
+ return @blob
64
+ end
65
+
66
+ private
67
+ def fetch
68
+ if !@last_fetched_url || @last_fetched_url != url || !@blob
69
+ uri = URI.parse url
70
+ request = Net::HTTP::Get.new uri.path
71
+ response = Net::HTTP.start(uri.host, uri.port) { |http| http.request request }
72
+ @blob = response.body
73
+ @last_fetched_url = url
74
+ end
75
+ end
76
+ end
77
+ end
@@ -0,0 +1,40 @@
1
+ require 'rubygems'
2
+ require 'spec'
3
+ require File.join(File.dirname(__FILE__), '..', 'lib', 'static_gmaps')
4
+
5
+ STATIC_GOOGLE_MAP_DEFAULT_PARAMETERS_TEST_IMAGE_PATH = File.join File.dirname(__FILE__), 'test_image.gif'
6
+
7
+ describe StaticGmaps::Map, 'with no attributes set' do
8
+ before(:each) do @static_google_map = StaticGmaps::Map.new end
9
+
10
+ it 'should have a center set to default' do @static_google_map.center.should == StaticGmaps::Map::DEFAULT_CENTER end
11
+ it 'should have a zoom set to default' do @static_google_map.zoom.should == StaticGmaps::Map::DEFAULT_ZOOM end
12
+ it 'should have a size set to default' do @static_google_map.size.should == StaticGmaps::Map::DEFAULT_SIZE end
13
+ it 'should have a map_type set to default' do @static_google_map.map_type.should == StaticGmaps::Map::DEFAULT_MAP_TYPE end
14
+ it 'should have a key set to default' do @static_google_map.key.should == StaticGmaps::Map::DEFAULT_KEY end
15
+ end
16
+
17
+ describe StaticGmaps::Map, 'with all attributes set' do
18
+ before(:each) do
19
+ @static_google_map = StaticGmaps::Map.new :center => [ 40.714728, -73.998672 ],
20
+ :zoom => 12,
21
+ :size => [ 500, 400 ],
22
+ :map_type => :roadmap,
23
+ :key => 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA'
24
+ end
25
+
26
+ it 'should have a center' do @static_google_map.center.should == [ 40.714728, -73.998672 ] end
27
+ it 'should have a zoom' do @static_google_map.zoom.should == 12 end
28
+ it 'should have a size' do @static_google_map.size.should == [ 500, 400 ] end
29
+ it 'should have a map_type' do @static_google_map.map_type.should == :roadmap end
30
+ it 'should have a key' do @static_google_map.key.should == 'ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA' end
31
+ end
32
+
33
+ describe StaticGmaps::Map do
34
+ before(:each) do @static_google_map = StaticGmaps::Map.new end
35
+
36
+ it 'should have a url' do @static_google_map.url.should == 'http://maps.google.com/staticmap?center=0,0&zoom=1&size=500x400&map_type=roadmap&key=ABQIAAAAzr2EBOXUKnm_jVnk0OJI7xSosDVG8KKPE1-m51RBrvYughuyMxQ-i1QfUnH94QxWIa6N4U6MouMmBA' end
37
+ it 'should have a width' do @static_google_map.width.should == 500 end
38
+ it 'should have a height' do @static_google_map.height.should == 400 end
39
+ #it 'should respond to to_blob with an image' do @static_google_map.to_blob.should == File.read(STATIC_GOOGLE_MAP_DEFAULT_PARAMETERS_TEST_IMAGE_PATH) end
40
+ end
Binary file
metadata ADDED
@@ -0,0 +1,72 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: static-gmaps
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - John Wulff
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2008-02-25 00:00:00 -08:00
13
+ default_executable:
14
+ dependencies:
15
+ - !ruby/object:Gem::Dependency
16
+ name: hoe
17
+ version_requirement:
18
+ version_requirements: !ruby/object:Gem::Requirement
19
+ requirements:
20
+ - - ">="
21
+ - !ruby/object:Gem::Version
22
+ version: 1.5.0
23
+ version:
24
+ description: "== DESCRIPTION: Provides an interface to the Google Static Maps API. == FEATURES/PROBLEMS: * See SYNOPSIS."
25
+ email: johnwulff@gmail.com
26
+ executables: []
27
+
28
+ extensions: []
29
+
30
+ extra_rdoc_files:
31
+ - History.txt
32
+ - LICENSE.txt
33
+ - Manifest.txt
34
+ - README.txt
35
+ files:
36
+ - History.txt
37
+ - LICENSE.txt
38
+ - Manifest.txt
39
+ - README.txt
40
+ - Rakefile
41
+ - lib/static_gmaps.rb
42
+ - spec/static_gmaps_spec.rb
43
+ - spec/test_image.gif
44
+ has_rdoc: true
45
+ homepage:
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --main
49
+ - README.txt
50
+ require_paths:
51
+ - lib
52
+ required_ruby_version: !ruby/object:Gem::Requirement
53
+ requirements:
54
+ - - ">="
55
+ - !ruby/object:Gem::Version
56
+ version: "0"
57
+ version:
58
+ required_rubygems_version: !ruby/object:Gem::Requirement
59
+ requirements:
60
+ - - ">="
61
+ - !ruby/object:Gem::Version
62
+ version: "0"
63
+ version:
64
+ requirements: []
65
+
66
+ rubyforge_project: static-gmaps
67
+ rubygems_version: 1.0.1
68
+ signing_key:
69
+ specification_version: 2
70
+ summary: Provides an interface to the Google Static Maps API.
71
+ test_files: []
72
+