overlord 0.1.1 → 0.1.2

Sign up to get free protection for your applications and to get access to all the features.
data/LICENSE CHANGED
@@ -1,4 +1,4 @@
1
- Copyright (c) 2009 Justin Ball
1
+ Copyright (c) 2009 Tatemae
2
2
 
3
3
  Permission is hereby granted, free of charge, to any person obtaining
4
4
  a copy of this software and associated documentation files (the
data/README.rdoc CHANGED
@@ -4,6 +4,8 @@ Talk to the Google ajax apis and render the results. This gem contains several
4
4
  out to the Google Ajax Apis (http://code.google.com/apis/ajax/).
5
5
 
6
6
  == Usage
7
+
8
+ === Settings
7
9
  This gem requires some configuration before it will work in your Rails application:
8
10
  You will need a global_config file with 'google_ajax_api_key' defined. You can set it up thus:
9
11
 
@@ -46,9 +48,9 @@ Then in global_config.yml:
46
48
 
47
49
  application_url: 'localhost:3000'
48
50
 
49
-
51
+ === Models
50
52
  If you want to use the methods 'convert_google_feed_json_to_feed', 'convert_google_find_feeds_json_to_feeds', and
51
- 'convert_google_feed_json_to_entries' you will also need a Feed and Entry class with specific attributes. See the rails application
53
+ 'convert_google_feed_json_to_entries' you will also need a Feed, Service and Entry class with specific attributes. See the rails application
52
54
  inside of the test directory for more information on how to create these classes.
53
55
 
54
56
  # Required attributes:
@@ -111,4 +113,4 @@ inside of the test directory for more information on how to create these classes
111
113
 
112
114
  == Copyright
113
115
 
114
- Copyright (c) 2009 Justin Ball. See LICENSE for details.
116
+ Copyright (c) 2009 Tatemae. See LICENSE for details.
data/Rakefile CHANGED
@@ -9,9 +9,9 @@ begin
9
9
  gem.name = "overlord"
10
10
  gem.summary = "Talk with our Google overlords"
11
11
  gem.description = "Code to interact with the google ajax apis on the server and the client."
12
- gem.email = "justinball@gmail.com"
12
+ gem.email = "justin@tatemae.com"
13
13
  gem.homepage = "http://github.com/jbasdf/overlord"
14
- gem.authors = ["Justin Ball"]
14
+ gem.authors = ["Justin Ball", "Joel Duffin"]
15
15
  gem.add_development_dependency "thoughtbot-shoulda"
16
16
  # gem is a Gem::Specification... see http://www.rubygems.org/read/chapter/20 for additional settings
17
17
  end
data/VERSION CHANGED
@@ -1 +1 @@
1
- 0.1.1
1
+ 0.1.2
@@ -125,6 +125,20 @@ module OverlordGoogleHelper
125
125
  render :partial => 'google/slide_show', :locals => { :feed => feed, :content_id => content_id, :options => options }
126
126
  end
127
127
 
128
+ # Generate a google map that includes the location of each item in
129
+ # mapped_objects. Each object in mapped_objects must define a lat and lng attribute.
130
+ #
131
+ # mapped_objects: Collection of objects to be mapped.
132
+ # content_id: Name of the div that will hold the widget google generates.
133
+ # If this method is called more than once on a given page then you will need to
134
+ # specify different content_ids for each call.
135
+ # options: A hash containing the values to pass to the Google widget.
136
+ def google_map(mapped_objects,
137
+ content_id = 'map_content',
138
+ options = {})
139
+ render :partial => 'google/map', :locals => { :mapped_objects => mapped_objects, :content_id => content_id, :options => options }
140
+ end
141
+
128
142
  # Given a feed attempts to assign an appropriate class
129
143
  def feed_class(feed)
130
144
  return '' if feed.service.blank?
@@ -287,6 +301,13 @@ module OverlordGoogleHelper
287
301
  google_ajax_api_scripts + '<script type="text/javascript">google.load("search", "1");</script>'
288
302
  end
289
303
 
304
+ # Output include script for google maps
305
+ def google_load_maps
306
+ return '' if defined?(@google_load_maps_included)
307
+ @google_load_maps_included = true
308
+ google_ajax_api_scripts + '<script type="text/javascript">google.load("maps", "2");</script>'
309
+ end
310
+
290
311
  # Output include script to load jquery from google
291
312
  def google_load_jquery
292
313
  return '' if defined?(@google_load_jquery_included)
@@ -0,0 +1,56 @@
1
+ <% content_for :head do -%>
2
+ <%= google_load_maps -%>
3
+ <% end -%>
4
+
5
+ <script type="text/javascript">
6
+ google.setOnLoadCallback(function() {
7
+ if (google.maps.BrowserIsCompatible()) {
8
+ var map = new google.maps.Map2(document.getElementById("<%=content_id%>"));
9
+ map.setCenter(new google.maps.LatLng(37.4419, -122.1419), 13);
10
+ map.addControl(new google.maps.SmallMapControl());
11
+ map.addControl(new google.maps.MapTypeControl());
12
+
13
+ // Create a base icon for all of our markers that specifies the
14
+ // shadow, icon dimensions, etc.
15
+ var baseIcon = new google.maps.Icon(G_DEFAULT_ICON);
16
+ baseIcon.shadow = "http://www.google.com/mapfiles/shadow50.png";
17
+ baseIcon.iconSize = new google.maps.Size(20, 34);
18
+ baseIcon.shadowSize = new google.maps.Size(37, 34);
19
+ baseIcon.iconAnchor = new google.maps.Point(9, 34);
20
+ baseIcon.infoWindowAnchor = new google.maps.Point(9, 2);
21
+
22
+ // Creates a marker whose info window displays the letter corresponding
23
+ // to the given index.
24
+ function createMarker(point, index) {
25
+ // Create a lettered icon for this point using our icon class
26
+ var letter = String.fromCharCode("A".charCodeAt(0) + index);
27
+ var letteredIcon = new google.maps.Icon(baseIcon);
28
+ letteredIcon.image = "http://www.google.com/mapfiles/marker" + letter + ".png";
29
+
30
+ // Set up our google.maps.MarkerOptions object
31
+ markerOptions = { icon:letteredIcon };
32
+ var marker = new google.maps.Marker(point, markerOptions);
33
+
34
+ google.maps.Event.addListener(marker, "click", function() {
35
+ marker.openInfoWindowHtml("Marker <b>" + letter + "</b>");
36
+ });
37
+ return marker;
38
+ }
39
+
40
+ // Add 10 markers to the map at random locations
41
+ var bounds = map.getBounds();
42
+ var southWest = bounds.getSouthWest();
43
+ var northEast = bounds.getNorthEast();
44
+ var lngSpan = northEast.lng() - southWest.lng();
45
+ var latSpan = northEast.lat() - southWest.lat();
46
+ for (var i = 0; i < 10; i++) {
47
+ var latlng = new google.maps.LatLng(southWest.lat() + latSpan * Math.random(),
48
+ southWest.lng() + lngSpan * Math.random());
49
+ map.addOverlay(createMarker(latlng, i));
50
+ }
51
+ }
52
+ });
53
+ </script>
54
+
55
+ onunload="google.maps.Unload()"
56
+ <div id="<%=content_id%>" style="width: 500px; height: 300px"></div>
@@ -0,0 +1,85 @@
1
+ module Overlord
2
+ # Google ajax search api reference:
3
+ # http://code.google.com/apis/ajaxsearch/documentation
4
+ #
5
+ # Google code playground:
6
+ # http://code.google.com/apis/ajax/playground
7
+ #
8
+ class GoogleSearchRequest
9
+ include HTTParty
10
+ format :json
11
+
12
+ # Initialize Google Request.
13
+ # Parameters:
14
+ # api_key_id: Valid Google access key (optional)
15
+ def initialize(api_key_id = nil)
16
+ @api_key_id = api_key_id
17
+ end
18
+
19
+ # Run a local search
20
+ # Google docs:
21
+ # http://code.google.com/apis/ajaxsearch/documentation/reference.html#_fonje_local
22
+ # For example:
23
+ # rsz This optional argument supplies the number of results that the application would like to recieve. A value of small
24
+ # indicates a small result set size or 4 results. A value of large indicates a large result set or 8 results.
25
+ # If this argument is not supplied, a value of small is assumed.
26
+ # start This optional argument supplies the start index of the first search result. Each successful response contains
27
+ # a cursor object (see below) which includes an array of pages. The start property for a page may be used as a
28
+ # valid value for this argument.
29
+ #
30
+ # Pass any of the standard search options:
31
+ # http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
32
+ #
33
+ # Pass any of the following options:
34
+ # sll This optional argument supplies the search center point for a local search. It's value is a comma separated latitude/longitude pair, e.g., sll=48.8565,2.3509.
35
+ # sspn This optional argument supplies a bounding box that the local search should be relative to. When using a Google Map, the sspn value can be computed using: myMap.getBounds().toSpan().toUrlValue(); (e.g., sspn=0.065169,0.194149).
36
+ # mrt This optional argument specifies which type of listing the user is interested in. Valid values include:
37
+ # * blended - request KML, Local Business Listings, and Geocode results
38
+ # * kmlonly - request KML and Geocode results
39
+ # * localonly - request Local Business Listings and Geocode results
40
+ # If this argument is not supplied, the default value of localonly is used.
41
+ #
42
+ def self.local_search(query, options = {})
43
+ get('http://ajax.googleapis.com/ajax/services/search/local', :query => build_google_query(options.merge(:q => query)))
44
+ end
45
+
46
+ # Converts json returned from google into a feed object
47
+ # Each object has the following attributes. For more details on each attribute see http://code.google.com/apis/ajaxsearch/documentation/reference.html#_intro_fonje
48
+ # viewportmode "computed"
49
+ # country "United States"
50
+ # streetAddress "300 Grove St"
51
+ # region "CA"
52
+ # titleNoFormatting "Jardiniere Restaurant"
53
+ # ddUrlFromHere "http://www.google.com/maps?source=uds&saddr=300+Grove+St%2C+San+Francisco%2C+CA+%28Jardiniere+Restaurant%29+%4037.778127%2C-122.421735&iwstate1=dir%3Afrom"
54
+ # content ""
55
+ # ddUrlToHere "http://www.google.com/maps?source=uds&daddr=300+Grove+St%2C+San+Francisco%2C+CA+%28Jardiniere+Restaurant%29+%4037.778127%2C-122.421735&iwstate1=dir%3Ato"
56
+ # url "http://www.google.com/local?source=uds&q=food&sll=37.778127%2C-122.421735&latlng=37778127%2C-122421735%2C16134753875200198327&near=37.778127%2C-122.421735"
57
+ # city "San Francisco"
58
+ # accuracy "8"
59
+ # phoneNumbers [{"number"=>"(415) 861-5555", "type"=>""}, {"number"=>"(415) 555-1212", "type"=>""}]
60
+ # listingType "local"
61
+ # maxAge 604800
62
+ # title "Jardiniere Restaurant"
63
+ # ddUrl "http://www.google.com/maps?source=uds&daddr=300+Grove+St%2C+San+Francisco%2C+CA+%28Jardiniere+Restaurant%29+%4037.778127%2C-122.421735&saddr"
64
+ # staticMapUrl "http://mt.google.com/mapdata?cc=us&tstyp=5&Point=b&Point.latitude_e6=37778127&Point.longitude_e6=-122421735&Point.iconid=15&Point=e&w=150&h=100&zl=4"
65
+ # GsearchResultClass "GlocalSearch"
66
+ # lat "37.778127"
67
+ # addressLines ["300 Grove St", "San Francisco, CA"]
68
+ # lng "-122.421735"
69
+ def self.convert_google_search_json_to_objects(json)
70
+ if json['responseStatus'] == 200
71
+ if json['responseData']['results']
72
+ json['responseData']['results'].collect{ |result| OpenStruct.new(result) }
73
+ end
74
+ end
75
+ end
76
+
77
+ # Add standard items to the google query
78
+ def self.build_google_query(query_options)
79
+ query_options[:v] = '1.0'
80
+ query_options[:key] = GlobalConfig.google_ajax_api_key if GlobalConfig.google_ajax_api_key
81
+ query_options
82
+ end
83
+
84
+ end
85
+ end
data/overlord.gemspec CHANGED
@@ -5,13 +5,13 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = %q{overlord}
8
- s.version = "0.1.1"
8
+ s.version = "0.1.2"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
- s.authors = ["Justin Ball"]
12
- s.date = %q{2009-10-31}
11
+ s.authors = ["Justin Ball", "Joel Duffin"]
12
+ s.date = %q{2009-11-30}
13
13
  s.description = %q{Code to interact with the google ajax apis on the server and the client.}
14
- s.email = %q{justinball@gmail.com}
14
+ s.email = %q{justin@tatemae.com}
15
15
  s.extra_rdoc_files = [
16
16
  "LICENSE",
17
17
  "README.rdoc"
@@ -30,10 +30,12 @@ Gem::Specification.new do |s|
30
30
  "app/views/google/_feed_search.html.erb",
31
31
  "app/views/google/_feeds_scripts.html.erb",
32
32
  "app/views/google/_hot_trends.html.erb",
33
+ "app/views/google/_map.html.erb",
33
34
  "app/views/google/_search.html.erb",
34
35
  "app/views/google/_slide_show.html.erb",
35
36
  "lib/overlord.rb",
36
37
  "lib/overlord/google_feed_request.rb",
38
+ "lib/overlord/google_search_request.rb",
37
39
  "overlord.gemspec",
38
40
  "rails/init.rb",
39
41
  "test/rails_root/.gitignore",
@@ -51,6 +53,7 @@ Gem::Specification.new do |s|
51
53
  "test/rails_root/app/views/default/google_dynamic_feeds_vertical.html.erb",
52
54
  "test/rails_root/app/views/default/google_feed_search.html.erb",
53
55
  "test/rails_root/app/views/default/google_feeds.html.erb",
56
+ "test/rails_root/app/views/default/google_map.html.erb",
54
57
  "test/rails_root/app/views/default/google_search.html.erb",
55
58
  "test/rails_root/app/views/default/google_slide_show.html.erb",
56
59
  "test/rails_root/app/views/default/index.html.erb",
@@ -577,7 +580,8 @@ Gem::Specification.new do |s|
577
580
  "test/rails_root/test/shoulda_macros/plugins.rb",
578
581
  "test/rails_root/test/test_helper.rb",
579
582
  "test/rails_root/test/unit/.keep",
580
- "test/rails_root/test/unit/google_feed_request_test.rb"
583
+ "test/rails_root/test/unit/google_feed_request_test.rb",
584
+ "test/rails_root/test/unit/google_search_request_test.rb"
581
585
  ]
582
586
  s.homepage = %q{http://github.com/jbasdf/overlord}
583
587
  s.rdoc_options = ["--charset=UTF-8"]
@@ -623,7 +627,8 @@ Gem::Specification.new do |s|
623
627
  "test/rails_root/test/shoulda_macros/pagination.rb",
624
628
  "test/rails_root/test/shoulda_macros/plugins.rb",
625
629
  "test/rails_root/test/test_helper.rb",
626
- "test/rails_root/test/unit/google_feed_request_test.rb"
630
+ "test/rails_root/test/unit/google_feed_request_test.rb",
631
+ "test/rails_root/test/unit/google_search_request_test.rb"
627
632
  ]
628
633
 
629
634
  if s.respond_to? :specification_version then
@@ -23,7 +23,11 @@ class DefaultController < ApplicationController
23
23
  def google_slide_show
24
24
  @feed = Feed.new(:uri => 'feed://api.flickr.com/services/feeds/photos_public.gne?tags=autumn&lang=en-us&format=rss_200')
25
25
  end
26
-
26
+
27
+ def google_map
28
+ @mapped_objects = []
29
+ end
30
+
27
31
  def setup
28
32
  @terms = CGI.unescape('mountain biking')
29
33
 
@@ -0,0 +1 @@
1
+ <%= google_map(@mapped_objects) %>
@@ -1,4 +1,4 @@
1
- require 'test_helper'
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
2
 
3
3
  class GoogleFeedRequestTest < ActiveSupport::TestCase
4
4
 
@@ -0,0 +1,26 @@
1
+ require File.dirname(__FILE__) + '/../test_helper'
2
+
3
+ class GoogleSearchRequestTest < ActiveSupport::TestCase
4
+
5
+ context "google search requests" do
6
+ setup do
7
+ end
8
+
9
+ context "local search" do
10
+ setup do
11
+ @results = Overlord::GoogleSearchRequest.local_search('food')
12
+ end
13
+ should "get local search results" do
14
+ assert @results.length > 0
15
+ assert_equal 200, @results['responseStatus']
16
+ end
17
+ should "convert google json into objects" do
18
+ @objects = Overlord::GoogleSearchRequest.convert_google_search_json_to_objects(@results)
19
+ assert @objects.length > 0
20
+ assert @objects[0].country
21
+ end
22
+ end
23
+
24
+ end
25
+
26
+ end
metadata CHANGED
@@ -1,15 +1,16 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: overlord
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Justin Ball
8
+ - Joel Duffin
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
12
 
12
- date: 2009-10-31 00:00:00 -06:00
13
+ date: 2009-11-30 00:00:00 -07:00
13
14
  default_executable:
14
15
  dependencies:
15
16
  - !ruby/object:Gem::Dependency
@@ -23,7 +24,7 @@ dependencies:
23
24
  version: "0"
24
25
  version:
25
26
  description: Code to interact with the google ajax apis on the server and the client.
26
- email: justinball@gmail.com
27
+ email: justin@tatemae.com
27
28
  executables: []
28
29
 
29
30
  extensions: []
@@ -45,10 +46,12 @@ files:
45
46
  - app/views/google/_feed_search.html.erb
46
47
  - app/views/google/_feeds_scripts.html.erb
47
48
  - app/views/google/_hot_trends.html.erb
49
+ - app/views/google/_map.html.erb
48
50
  - app/views/google/_search.html.erb
49
51
  - app/views/google/_slide_show.html.erb
50
52
  - lib/overlord.rb
51
53
  - lib/overlord/google_feed_request.rb
54
+ - lib/overlord/google_search_request.rb
52
55
  - overlord.gemspec
53
56
  - rails/init.rb
54
57
  - test/rails_root/.gitignore
@@ -66,6 +69,7 @@ files:
66
69
  - test/rails_root/app/views/default/google_dynamic_feeds_vertical.html.erb
67
70
  - test/rails_root/app/views/default/google_feed_search.html.erb
68
71
  - test/rails_root/app/views/default/google_feeds.html.erb
72
+ - test/rails_root/app/views/default/google_map.html.erb
69
73
  - test/rails_root/app/views/default/google_search.html.erb
70
74
  - test/rails_root/app/views/default/google_slide_show.html.erb
71
75
  - test/rails_root/app/views/default/index.html.erb
@@ -593,6 +597,7 @@ files:
593
597
  - test/rails_root/test/test_helper.rb
594
598
  - test/rails_root/test/unit/.keep
595
599
  - test/rails_root/test/unit/google_feed_request_test.rb
600
+ - test/rails_root/test/unit/google_search_request_test.rb
596
601
  has_rdoc: true
597
602
  homepage: http://github.com/jbasdf/overlord
598
603
  licenses: []
@@ -661,3 +666,4 @@ test_files:
661
666
  - test/rails_root/test/shoulda_macros/plugins.rb
662
667
  - test/rails_root/test/test_helper.rb
663
668
  - test/rails_root/test/unit/google_feed_request_test.rb
669
+ - test/rails_root/test/unit/google_search_request_test.rb