gmapper 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,8 @@
1
+ README.rdoc
2
+ Rakefile
3
+ gmapper.gemspec
4
+ lib/gmapper.rb
5
+ lib/google/autoload.rb
6
+ lib/google/maps/static/map.rb
7
+ lib/google/maps/static/marker.rb
8
+ Manifest
@@ -0,0 +1,60 @@
1
+ = GMapper
2
+
3
+ A version agnostic library for the Google Maps API.
4
+
5
+ Currently only supports Google Static Maps.
6
+
7
+
8
+ == Install
9
+
10
+ gem install gmapper
11
+
12
+
13
+ == Dependancies
14
+
15
+ active_support/inflector
16
+
17
+
18
+ == Usage
19
+
20
+ To create a map of a location, say the Googleplex:
21
+
22
+ map = Google::Maps::Static::Map.new :center => [37.422, 122.084]
23
+
24
+ Then, lets say we want to add a marker to point out where it is:
25
+
26
+ map.markers << Google::Maps::Static::Marker.new [37.422, 122.084], :color => :blue, :label => 'G'
27
+
28
+ To save the map to your local disk:
29
+
30
+ map.save "googleplex.jpg"
31
+
32
+
33
+ == Todo
34
+
35
+ * I still need to add some tests
36
+ * There are a few other API's that I have to refactor before I add
37
+
38
+
39
+ == Lisence
40
+
41
+ Copyright (c) 2010 TJ-Coding.com
42
+
43
+ Permission is hereby granted, free of charge, to any person obtaining
44
+ a copy of this software and associated documentation files (the
45
+ "Software"), to deal in the Software without restriction, including
46
+ without limitation the rights to use, copy, modify, merge, publish,
47
+ distribute, sublicense, and/or sell copies of the Software, and to
48
+ permit persons to whom the Software is furnished to do so, subject to
49
+ the following conditions:
50
+
51
+ The above copyright notice and this permission notice shall be
52
+ included in all copies or substantial portions of the Software.
53
+
54
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
55
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
56
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
57
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
58
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
59
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
60
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,14 @@
1
+ require 'rubygems'
2
+ require 'rake'
3
+ require 'echoe'
4
+
5
+ Echoe.new( 'gmapper', '0.1.0' ) do |p|
6
+ p.description = "A version agnostic library for the Google Maps API."
7
+ p.url = "http://github.com/tpeden/gmapper"
8
+ p.author = "TJ Peden"
9
+ p.email = "tj.peden@tj-coding.com"
10
+ p.ignore_pattern = ["tmp/*", "script/*"]
11
+ p.development_dependencies = []
12
+ end
13
+
14
+ Dir["#{File.dirname(__FILE__)}/tasks/*.rake"].sort.each { |ext| load ext }
@@ -0,0 +1,30 @@
1
+ # -*- encoding: utf-8 -*-
2
+
3
+ Gem::Specification.new do |s|
4
+ s.name = %q{gmapper}
5
+ s.version = "0.1.0"
6
+
7
+ s.required_rubygems_version = Gem::Requirement.new(">= 1.2") if s.respond_to? :required_rubygems_version=
8
+ s.authors = ["TJ Peden"]
9
+ s.date = %q{2010-09-01}
10
+ s.description = %q{A version agnostic library for the Google Maps API.}
11
+ s.email = %q{tj.peden@tj-coding.com}
12
+ s.extra_rdoc_files = ["README.rdoc", "lib/gmapper.rb", "lib/google/autoload.rb", "lib/google/maps/static/map.rb", "lib/google/maps/static/marker.rb"]
13
+ s.files = ["README.rdoc", "Rakefile", "gmapper.gemspec", "lib/gmapper.rb", "lib/google/autoload.rb", "lib/google/maps/static/map.rb", "lib/google/maps/static/marker.rb", "Manifest"]
14
+ s.homepage = %q{http://github.com/tpeden/gmapper}
15
+ s.rdoc_options = ["--line-numbers", "--inline-source", "--title", "Gmapper", "--main", "README.rdoc"]
16
+ s.require_paths = ["lib"]
17
+ s.rubyforge_project = %q{gmapper}
18
+ s.rubygems_version = %q{1.3.7}
19
+ s.summary = %q{A version agnostic library for the Google Maps API.}
20
+
21
+ if s.respond_to? :specification_version then
22
+ current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
23
+ s.specification_version = 3
24
+
25
+ if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
26
+ else
27
+ end
28
+ else
29
+ end
30
+ end
@@ -0,0 +1,27 @@
1
+ require 'uri'
2
+ require 'net/http'
3
+ require 'google/autoload'
4
+
5
+ unless [].respond_to? :extract_options!
6
+ class Array
7
+ def extract_options!
8
+ last.is_a?(::Hash) ? pop : {}
9
+ end
10
+ end
11
+ end
12
+
13
+ module Google
14
+
15
+ module Maps
16
+
17
+ module Static
18
+ extend Google::Autoload
19
+
20
+ autoload :Map
21
+ autoload :Marker
22
+
23
+ end # => Static
24
+
25
+ end # => Maps
26
+
27
+ end # => Static
@@ -0,0 +1,16 @@
1
+ require 'active_support/inflector'
2
+
3
+ module Google
4
+
5
+ module Autoload
6
+
7
+ def autoload( const_name, path = nil )
8
+ full_name = [self.name, const_name.to_s, path].compact.join('::')
9
+ location = path || ActiveSupport::Inflector.underscore( full_name )
10
+
11
+ super const_name, location
12
+ end
13
+
14
+ end
15
+
16
+ end
@@ -0,0 +1,53 @@
1
+ module Google
2
+
3
+ module Maps
4
+
5
+ module Static
6
+
7
+ class Map
8
+ attr_reader :markers
9
+
10
+ def initialize *args
11
+ @base = "http://maps.google.com/maps/api/staticmap"
12
+
13
+ @options = args.extract_options!
14
+ @options[:sensor] = false unless @options.key?(:sensor)
15
+
16
+ @markers = []
17
+ end
18
+
19
+ def save file
20
+ response = ::Net::HTTP.get( ::URI.parse( url ) )
21
+ File.open( file, 'wb' ) { |f| f.write response }
22
+ end
23
+
24
+ def url
25
+ @url ||= "#{@base}?#{parameters}"
26
+ end
27
+ alias_method :to_s, :url
28
+
29
+ private
30
+ def parameters
31
+ result = @options.map do |key, object|
32
+ value = case key
33
+ when :center
34
+ object.is_a?( Array ) ? object.join(',') : object.to_s
35
+ when :size
36
+ object.is_a?( Array ) ? object.join('x') : object.to_s
37
+ else object.to_s
38
+ end
39
+
40
+ "#{::URI.escape( key.to_s )}=#{::URI.escape( value )}"
41
+ end.join('&')
42
+
43
+ result += '&' + @markers.map(&:to_s).join('&') unless @markers.empty?
44
+
45
+ result
46
+ end
47
+ end # => Google::Maps::Static::Map
48
+
49
+ end # => Google::Maps::Static
50
+
51
+ end # => Google::Maps
52
+
53
+ end # => Google
@@ -0,0 +1,37 @@
1
+ module Google
2
+
3
+ module Maps
4
+
5
+ module Static
6
+
7
+ class Marker
8
+
9
+ def initialize *args
10
+ @options = args.extract_options!
11
+
12
+ raise "Must specify one or more points to place markers" if args.empty?
13
+
14
+ @locations = args
15
+ end
16
+
17
+ def to_s
18
+ result = "markers="
19
+
20
+ result += @options.inject('') do |output, pair|
21
+ output + "#{pair.first.to_s}:#{pair.last.to_s}|"
22
+ end
23
+
24
+ result += @locations.map do |loc|
25
+ loc.is_a?(Array) ? log.join(',') : loc.to_s
26
+ end.join('|')
27
+
28
+ ::URI.encode( result )
29
+ end
30
+
31
+ end # => Google::Maps::Static::Marker
32
+
33
+ end # => Google::Maps::Static
34
+
35
+ end # => Google::Maps
36
+
37
+ end # => Google
metadata ADDED
@@ -0,0 +1,81 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: gmapper
3
+ version: !ruby/object:Gem::Version
4
+ prerelease: false
5
+ segments:
6
+ - 0
7
+ - 1
8
+ - 0
9
+ version: 0.1.0
10
+ platform: ruby
11
+ authors:
12
+ - TJ Peden
13
+ autorequire:
14
+ bindir: bin
15
+ cert_chain: []
16
+
17
+ date: 2010-09-01 00:00:00 -04:00
18
+ default_executable:
19
+ dependencies: []
20
+
21
+ description: A version agnostic library for the Google Maps API.
22
+ email: tj.peden@tj-coding.com
23
+ executables: []
24
+
25
+ extensions: []
26
+
27
+ extra_rdoc_files:
28
+ - README.rdoc
29
+ - lib/gmapper.rb
30
+ - lib/google/autoload.rb
31
+ - lib/google/maps/static/map.rb
32
+ - lib/google/maps/static/marker.rb
33
+ files:
34
+ - README.rdoc
35
+ - Rakefile
36
+ - gmapper.gemspec
37
+ - lib/gmapper.rb
38
+ - lib/google/autoload.rb
39
+ - lib/google/maps/static/map.rb
40
+ - lib/google/maps/static/marker.rb
41
+ - Manifest
42
+ has_rdoc: true
43
+ homepage: http://github.com/tpeden/gmapper
44
+ licenses: []
45
+
46
+ post_install_message:
47
+ rdoc_options:
48
+ - --line-numbers
49
+ - --inline-source
50
+ - --title
51
+ - Gmapper
52
+ - --main
53
+ - README.rdoc
54
+ require_paths:
55
+ - lib
56
+ required_ruby_version: !ruby/object:Gem::Requirement
57
+ none: false
58
+ requirements:
59
+ - - ">="
60
+ - !ruby/object:Gem::Version
61
+ segments:
62
+ - 0
63
+ version: "0"
64
+ required_rubygems_version: !ruby/object:Gem::Requirement
65
+ none: false
66
+ requirements:
67
+ - - ">="
68
+ - !ruby/object:Gem::Version
69
+ segments:
70
+ - 1
71
+ - 2
72
+ version: "1.2"
73
+ requirements: []
74
+
75
+ rubyforge_project: gmapper
76
+ rubygems_version: 1.3.7
77
+ signing_key:
78
+ specification_version: 3
79
+ summary: A version agnostic library for the Google Maps API.
80
+ test_files: []
81
+