gmaps4rails 1.5.7 → 1.5.8
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- metadata +6 -386
- data/.gitignore +0 -17
- data/.travis.yml +0 -10
- data/Gemfile +0 -9
- data/Gemfile.lock +0 -182
- data/Guardfile +0 -24
- data/MIT-LICENSE +0 -20
- data/README.rdoc +0 -135
- data/Rakefile +0 -4
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.base.js.coffee +0 -444
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.bing.js.coffee +0 -174
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.googlemaps.js.coffee +0 -339
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.mapquest.js.coffee +0 -145
- data/app/assets/javascripts/gmaps4rails/gmaps4rails.openlayers.js.coffee +0 -261
- data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
- data/gmaps4rails.gemspec +0 -39
- data/lib/generators/gmaps4rails/install_generator.rb +0 -48
- data/lib/generators/templates/README +0 -2
- data/lib/gmaps4rails.rb +0 -26
- data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
- data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
- data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
- data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
- data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
- data/lib/gmaps4rails/base.rb +0 -119
- data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
- data/lib/gmaps4rails/extensions/hash.rb +0 -9
- data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
- data/lib/gmaps4rails/js_builder.rb +0 -157
- data/lib/gmaps4rails/json_builder.rb +0 -140
- data/lib/gmaps4rails/model_handler.rb +0 -101
- data/lib/gmaps4rails/version.rb +0 -3
- data/lib/gmaps4rails/view_helper.rb +0 -175
- data/lib/tasks/gmaps4rails_tasks.rake +0 -4
- data/lib/tasks/jasmine.rake +0 -8
- data/public/javascripts/gmaps4rails/gmaps4rails.base.js +0 -464
- data/public/javascripts/gmaps4rails/gmaps4rails.bing.js +0 -226
- data/public/javascripts/gmaps4rails/gmaps4rails.googlemaps.js +0 -430
- data/public/javascripts/gmaps4rails/gmaps4rails.mapquest.js +0 -178
- data/public/javascripts/gmaps4rails/gmaps4rails.openlayers.js +0 -265
- data/public/stylesheets/gmaps4rails.css +0 -24
- data/spec/dummy/.gitignore +0 -2
- data/spec/dummy/.rspec +0 -1
- data/spec/dummy/README.rdoc +0 -261
- data/spec/dummy/Rakefile +0 -7
- data/spec/dummy/app/assets/javascripts/application.js +0 -15
- data/spec/dummy/app/assets/stylesheets/application.css +0 -15
- data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
- data/spec/dummy/app/controllers/application_controller.rb +0 -3
- data/spec/dummy/app/controllers/users_controller.rb +0 -101
- data/spec/dummy/app/helpers/application_helper.rb +0 -2
- data/spec/dummy/app/mailers/.gitkeep +0 -0
- data/spec/dummy/app/models/.gitkeep +0 -0
- data/spec/dummy/app/models/place.rb +0 -16
- data/spec/dummy/app/models/user.rb +0 -12
- data/spec/dummy/app/views/layouts/application.html.erb +0 -16
- data/spec/dummy/app/views/users/_form.html.erb +0 -37
- data/spec/dummy/app/views/users/_map.html.erb +0 -5
- data/spec/dummy/app/views/users/edit.html.erb +0 -6
- data/spec/dummy/app/views/users/index.html.erb +0 -260
- data/spec/dummy/app/views/users/new.html.erb +0 -5
- data/spec/dummy/app/views/users/show.html.erb +0 -30
- data/spec/dummy/config.ru +0 -4
- data/spec/dummy/config/application.rb +0 -62
- data/spec/dummy/config/boot.rb +0 -10
- data/spec/dummy/config/database.yml +0 -25
- data/spec/dummy/config/environment.rb +0 -5
- data/spec/dummy/config/environments/development.rb +0 -37
- data/spec/dummy/config/environments/production.rb +0 -67
- data/spec/dummy/config/environments/test.rb +0 -37
- data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
- data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
- data/spec/dummy/config/initializers/inflections.rb +0 -15
- data/spec/dummy/config/initializers/mime_types.rb +0 -5
- data/spec/dummy/config/initializers/secret_token.rb +0 -7
- data/spec/dummy/config/initializers/session_store.rb +0 -8
- data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
- data/spec/dummy/config/locales/en.yml +0 -5
- data/spec/dummy/config/routes.rb +0 -60
- data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
- data/spec/dummy/db/schema.rb +0 -29
- data/spec/dummy/lib/assets/.gitkeep +0 -0
- data/spec/dummy/log/.gitkeep +0 -0
- data/spec/dummy/public/404.html +0 -26
- data/spec/dummy/public/422.html +0 -26
- data/spec/dummy/public/500.html +0 -25
- data/spec/dummy/public/favicon.ico +0 -0
- data/spec/dummy/public/javascripts/Player.js +0 -22
- data/spec/dummy/public/javascripts/Song.js +0 -7
- data/spec/dummy/public/logo.png +0 -0
- data/spec/dummy/script/rails +0 -6
- data/spec/factories/place_factory.rb +0 -16
- data/spec/factories/user_factory.rb +0 -23
- data/spec/fixtures/google_direction_valid.json +0 -65
- data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
- data/spec/fixtures/google_places_valid.json +0 -45
- data/spec/fixtures/google_wrong_geocoding.json +0 -4
- data/spec/javascripts/basic_methods_spec.js +0 -103
- data/spec/javascripts/helpers/.gitkeep +0 -0
- data/spec/javascripts/helpers/SpecHelper.js +0 -87
- data/spec/javascripts/map_spec.js +0 -49
- data/spec/javascripts/markers_methods_spec.js +0 -368
- data/spec/javascripts/mocks_spec.js +0 -27
- data/spec/javascripts/support/jasmine.yml +0 -10
- data/spec/javascripts/support/jasmine_config.rb +0 -23
- data/spec/javascripts/support/jasmine_runner.rb +0 -20
- data/spec/launchers/all_but_requests.rb +0 -0
- data/spec/launchers/all_specs.rb +0 -0
- data/spec/launchers/requests.rb +0 -0
- data/spec/lib/base_spec.rb +0 -59
- data/spec/lib/direction_spec.rb +0 -53
- data/spec/lib/geocoder_spec.rb +0 -46
- data/spec/lib/js_builder_spec.rb +0 -139
- data/spec/lib/json_builder_spec.rb +0 -232
- data/spec/lib/places_spec.rb +0 -25
- data/spec/models/place_spec.rb +0 -35
- data/spec/models/user_spec.rb +0 -187
- data/spec/spec_helper.rb +0 -44
- data/spec/support/geocoding.rb +0 -41
- data/spec/support/matchers.rb +0 -73
@@ -1,48 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
module Generators
|
3
|
-
class InstallGenerator < Rails::Generators::Base
|
4
|
-
source_root File.expand_path('../../templates', __FILE__)
|
5
|
-
|
6
|
-
desc 'Creates a Gmaps4rails initializer and copies the assets to the public folder.'
|
7
|
-
|
8
|
-
def copy_locale
|
9
|
-
if Rails::VERSION::MINOR >= 1
|
10
|
-
copy_file "#{source_assets_base_path}gmaps4rails.base.js.coffee", "#{destination_assets_base_path}gmaps4rails.base.js.coffee"
|
11
|
-
copy_file "#{source_assets_base_path}gmaps4rails.googlemaps.js.coffee", "#{destination_assets_base_path}gmaps4rails.googlemaps.js.coffee"
|
12
|
-
copy_file "#{source_assets_base_path}gmaps4rails.openlayers.js.coffee", "#{destination_assets_base_path}gmaps4rails.openlayers.js.coffee"
|
13
|
-
copy_file "#{source_assets_base_path}gmaps4rails.bing.js.coffee", "#{destination_assets_base_path}gmaps4rails.bing.js.coffee"
|
14
|
-
copy_file "#{source_assets_base_path}gmaps4rails.mapquest.js.coffee", "#{destination_assets_base_path}gmaps4rails.mapquest.js.coffee"
|
15
|
-
copy_file "../../../public/stylesheets/gmaps4rails.css", "app/assets/stylesheets/gmaps4rails.css"
|
16
|
-
else
|
17
|
-
#I don't copy manifests, kind of useless
|
18
|
-
copy_file "#{source_js_base_path}gmaps4rails.base.js", "#{destination_js_base_path}gmaps4rails.base.js"
|
19
|
-
copy_file "#{source_js_base_path}gmaps4rails.googlemaps.js", "#{destination_js_base_path}gmaps4rails.googlemaps.js"
|
20
|
-
copy_file "#{source_js_base_path}gmaps4rails.bing.js", "#{destination_js_base_path}gmaps4rails.bing.js"
|
21
|
-
copy_file "#{source_js_base_path}gmaps4rails.openlayers.js", "#{destination_js_base_path}gmaps4rails.openlayers.js"
|
22
|
-
copy_file "#{source_js_base_path}gmaps4rails.mapquest.js", "#{destination_js_base_path}gmaps4rails.mapquest.js"
|
23
|
-
copy_file "../../../public/stylesheets/gmaps4rails.css", "public/stylesheets/gmaps4rails.css"
|
24
|
-
end
|
25
|
-
end
|
26
|
-
|
27
|
-
def source_assets_base_path
|
28
|
-
'../../../app/assets/javascripts/gmaps4rails/'
|
29
|
-
end
|
30
|
-
|
31
|
-
def destination_assets_base_path
|
32
|
-
'app/assets/javascripts/gmaps4rails/'
|
33
|
-
end
|
34
|
-
|
35
|
-
def source_js_base_path
|
36
|
-
"../../../public/javascripts/gmaps4rails/"
|
37
|
-
end
|
38
|
-
|
39
|
-
def destination_js_base_path
|
40
|
-
"public/javascripts/gmaps4rails/"
|
41
|
-
end
|
42
|
-
|
43
|
-
def show_readme
|
44
|
-
readme 'README' if behavior == :invoke
|
45
|
-
end
|
46
|
-
end
|
47
|
-
end
|
48
|
-
end
|
data/lib/gmaps4rails.rb
DELETED
@@ -1,26 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
require 'rails'
|
3
|
-
require 'gmaps4rails/base'
|
4
|
-
|
5
|
-
class Engine < Rails::Engine
|
6
|
-
|
7
|
-
initializer "gmaps4rails view helpers" do |app|
|
8
|
-
ActionView::Base.send :include, Gmaps4railsHelper
|
9
|
-
end
|
10
|
-
|
11
|
-
end
|
12
|
-
|
13
|
-
class Railtie < Rails::Railtie
|
14
|
-
|
15
|
-
initializer "include acts_as_gmappable within ORM" do
|
16
|
-
ActiveSupport.on_load(:active_record) do
|
17
|
-
ActiveRecord::Base.send(:include, Gmaps4rails::ActsAsGmappable)
|
18
|
-
end
|
19
|
-
|
20
|
-
ActiveSupport.on_load(:mongoid) do
|
21
|
-
Mongoid::Document.send(:include, Gmaps4rails::ActsAsGmappable)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
|
25
|
-
end
|
26
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
module ActsAsGmappable
|
3
|
-
extend ActiveSupport::Concern
|
4
|
-
|
5
|
-
# This is a validation method which triggers the geocoding and save its results
|
6
|
-
def process_geocoding
|
7
|
-
Gmaps4rails::ModelHandler.new(self, gmaps4rails_options).retrieve_coordinates
|
8
|
-
end
|
9
|
-
|
10
|
-
# creates json for one instance
|
11
|
-
def to_gmaps4rails(&block)
|
12
|
-
json = "["
|
13
|
-
object_json = Gmaps4rails.create_json(self, &block)
|
14
|
-
json << object_json.to_s unless object_json.nil?
|
15
|
-
json << "]"
|
16
|
-
end
|
17
|
-
|
18
|
-
module ClassMethods
|
19
|
-
|
20
|
-
def acts_as_gmappable args = {}
|
21
|
-
|
22
|
-
validate :process_geocoding
|
23
|
-
|
24
|
-
#instance method containing all the options to configure the behaviour of the gem regarding the current Model
|
25
|
-
define_method "gmaps4rails_options" do
|
26
|
-
{
|
27
|
-
:process_geocoding => args[:process_geocoding].nil? ? true : args[:process_geocoding],
|
28
|
-
:check_process => args[:check_process].nil? ? true : args[:check_process],
|
29
|
-
:checker => args[:checker] || "gmaps",
|
30
|
-
|
31
|
-
:lat_column => args[:lat] || "latitude",
|
32
|
-
:lng_column => args[:lng] || "longitude",
|
33
|
-
|
34
|
-
# purposefully no default.
|
35
|
-
# Leaving out the :position arg means we are using the default lat/lng to store coordinates
|
36
|
-
:position => args[:position],
|
37
|
-
|
38
|
-
:msg => args[:msg] || "Address invalid",
|
39
|
-
:validation => args[:validation].nil? ? true : args[:validation],
|
40
|
-
|
41
|
-
:language => args[:language] || "en",
|
42
|
-
:protocol => args[:protocol] || "http",
|
43
|
-
|
44
|
-
:address => args[:address] || "gmaps4rails_address",
|
45
|
-
:callback => args[:callback],
|
46
|
-
:normalized_address => args[:normalized_address]
|
47
|
-
}
|
48
|
-
end
|
49
|
-
|
50
|
-
end
|
51
|
-
end
|
52
|
-
|
53
|
-
end
|
54
|
-
end
|
@@ -1,40 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
module BaseNetMethods
|
4
|
-
|
5
|
-
def checked_google_response(&block)
|
6
|
-
raise_net_status unless valid_response?
|
7
|
-
|
8
|
-
raise_query_error unless valid_parsed_response?
|
9
|
-
|
10
|
-
yield
|
11
|
-
end
|
12
|
-
|
13
|
-
def base_url
|
14
|
-
URI.escape base_request
|
15
|
-
end
|
16
|
-
|
17
|
-
def response
|
18
|
-
@response ||= get_response
|
19
|
-
end
|
20
|
-
|
21
|
-
def valid_response?
|
22
|
-
response.is_a?(Net::HTTPSuccess)
|
23
|
-
end
|
24
|
-
|
25
|
-
def valid_parsed_response?
|
26
|
-
parsed_response["status"] == "OK"
|
27
|
-
end
|
28
|
-
|
29
|
-
def parsed_response
|
30
|
-
@parsed_response ||= JSON.parse(response.body)
|
31
|
-
end
|
32
|
-
|
33
|
-
def get_response
|
34
|
-
url = URI.parse(base_url)
|
35
|
-
http = Gmaps4rails.http_agent
|
36
|
-
http.get_response(url)
|
37
|
-
end
|
38
|
-
|
39
|
-
end
|
40
|
-
end
|
@@ -1,87 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
class Direction
|
4
|
-
|
5
|
-
include BaseNetMethods
|
6
|
-
|
7
|
-
attr_reader :ride, :output, :protocol, :options, :polylines, :language
|
8
|
-
attr_accessor :legs
|
9
|
-
|
10
|
-
def initialize(start_end, options= {}, output = "pretty")
|
11
|
-
@ride = OpenStruct.new start_end
|
12
|
-
@output = output
|
13
|
-
@protocol = options.delete(:protocol) || "http"
|
14
|
-
@language = options.delete(:language) || "en"
|
15
|
-
@options = options
|
16
|
-
raise_invalid unless valid?
|
17
|
-
self.legs = []
|
18
|
-
end
|
19
|
-
|
20
|
-
def get
|
21
|
-
checked_google_response do
|
22
|
-
#Each element in the legs array specifies a single leg of the journey from the origin to the destination in the calculated route
|
23
|
-
parsed_response["routes"].first["legs"].each do |leg|
|
24
|
-
extract_polylines(leg) if remove_polylines?
|
25
|
-
self.legs << {
|
26
|
-
"duration" => { "text" => leg["duration"]["text"], "value" => leg["duration"]["value"].to_f },
|
27
|
-
"distance" => { "text" => leg["distance"]["text"], "value" => leg["distance"]["value"].to_f },
|
28
|
-
"steps" => leg["steps"]
|
29
|
-
}
|
30
|
-
merge_polylines_with_leg if output == "pretty"
|
31
|
-
end
|
32
|
-
legs
|
33
|
-
end
|
34
|
-
end
|
35
|
-
|
36
|
-
private
|
37
|
-
|
38
|
-
def extract_polylines(leg)
|
39
|
-
@polylines = leg["steps"].map {|step| step.delete("polyline")}
|
40
|
-
end
|
41
|
-
|
42
|
-
def polylines_json
|
43
|
-
polylines.map{ |poly| {"coded_array" => poly["points"]} }.to_json
|
44
|
-
end
|
45
|
-
|
46
|
-
def remove_polylines?
|
47
|
-
output == "pretty" || output == "clean"
|
48
|
-
end
|
49
|
-
|
50
|
-
def merge_polylines_with_leg
|
51
|
-
self.legs.last.merge!({ "polylines" => polylines_json })
|
52
|
-
end
|
53
|
-
|
54
|
-
def format_options_for_url
|
55
|
-
return "" if options.empty?
|
56
|
-
"&" + options.map do |k,v|
|
57
|
-
if v.is_a?(Array)
|
58
|
-
k + "=" + v * ("|")
|
59
|
-
else
|
60
|
-
k + "=" + v
|
61
|
-
end
|
62
|
-
end * ("&")
|
63
|
-
end
|
64
|
-
|
65
|
-
def base_request
|
66
|
-
"#{protocol}://maps.googleapis.com/maps/api/directions/json?language=#{language}&origin=#{ride.from}&destination=#{ride.to}&sensor=false" + format_options_for_url
|
67
|
-
end
|
68
|
-
|
69
|
-
def valid?
|
70
|
-
!(ride.from.empty? || ride.to.empty?)
|
71
|
-
end
|
72
|
-
|
73
|
-
def raise_net_status
|
74
|
-
raise Gmaps4rails::DirectionNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
75
|
-
end
|
76
|
-
|
77
|
-
def raise_query_error
|
78
|
-
raise raise Gmaps4rails::DirectionStatus, "The query you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
79
|
-
end
|
80
|
-
|
81
|
-
def raise_invalid
|
82
|
-
raise Gmaps4rails::DirectionInvalidQuery, "Origin and destination must be provided in a hash as first argument"
|
83
|
-
end
|
84
|
-
|
85
|
-
end
|
86
|
-
|
87
|
-
end
|
@@ -1,54 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
class Geocoder
|
4
|
-
include BaseNetMethods
|
5
|
-
|
6
|
-
attr_reader :address, :language, :raw, :protocol
|
7
|
-
|
8
|
-
def initialize(address, options = {})
|
9
|
-
raise Gmaps4rails::GeocodeInvalidQuery, "You must provide an address" if address.empty?
|
10
|
-
|
11
|
-
@address = address
|
12
|
-
@language = options[:language] || "en"
|
13
|
-
@raw = options[:raw] || false
|
14
|
-
@protocol = options[:protocol] || "http"
|
15
|
-
end
|
16
|
-
|
17
|
-
# returns an array of hashes with the following keys:
|
18
|
-
# - lat: mandatory for acts_as_gmappable
|
19
|
-
# - lng: mandatory for acts_as_gmappable
|
20
|
-
# - matched_address: facultative
|
21
|
-
# - bounds: facultative
|
22
|
-
# - full_data: facultative
|
23
|
-
def get_coordinates
|
24
|
-
checked_google_response do
|
25
|
-
return parsed_response if raw
|
26
|
-
parsed_response["results"].inject([]) do |memo, result|
|
27
|
-
memo << {
|
28
|
-
:lat => result["geometry"]["location"]["lat"],
|
29
|
-
:lng => result["geometry"]["location"]["lng"],
|
30
|
-
:matched_address => result["formatted_address"],
|
31
|
-
:bounds => result["geometry"]["bounds"],
|
32
|
-
:full_data => result
|
33
|
-
}
|
34
|
-
end
|
35
|
-
end
|
36
|
-
end
|
37
|
-
|
38
|
-
private
|
39
|
-
|
40
|
-
def base_request
|
41
|
-
"#{protocol}://maps.googleapis.com/maps/api/geocode/json?language=#{language}&address=#{address}&sensor=false"
|
42
|
-
end
|
43
|
-
|
44
|
-
def raise_net_status
|
45
|
-
raise Gmaps4rails::GeocodeNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
46
|
-
end
|
47
|
-
|
48
|
-
def raise_query_error
|
49
|
-
raise Gmaps4rails::GeocodeStatus, "The address you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
50
|
-
end
|
51
|
-
|
52
|
-
end
|
53
|
-
|
54
|
-
end
|
@@ -1,74 +0,0 @@
|
|
1
|
-
module Gmaps4rails
|
2
|
-
|
3
|
-
class Places
|
4
|
-
|
5
|
-
include BaseNetMethods
|
6
|
-
|
7
|
-
attr_reader :lat, :lng
|
8
|
-
delegate :key, :keyword, :radius, :lang, :raw, :protocol, :to => :@options
|
9
|
-
|
10
|
-
def initialize(lat, lng, options = {})
|
11
|
-
@lat, @lng = lat, lng
|
12
|
-
raise_invalid unless valid_position?
|
13
|
-
raise_missing_key unless options[:key]
|
14
|
-
options[:radius] ||= 7500
|
15
|
-
options[:lang] ||= "en"
|
16
|
-
options[:raw] ||= false
|
17
|
-
options[:protocol]||= "http"
|
18
|
-
@options = OpenStruct.new options
|
19
|
-
end
|
20
|
-
|
21
|
-
def get
|
22
|
-
checked_google_response do
|
23
|
-
return parsed_response if raw
|
24
|
-
parsed_response["results"].inject([]) do |memo, result|
|
25
|
-
memo << {
|
26
|
-
:lat => result["geometry"]["location"]["lat"],
|
27
|
-
:lng => result["geometry"]["location"]["lng"],
|
28
|
-
:name => result["name"],
|
29
|
-
:reference => result["reference"],
|
30
|
-
:vicinity => result["vicinity"],
|
31
|
-
:full_data => result
|
32
|
-
}
|
33
|
-
end
|
34
|
-
end
|
35
|
-
end
|
36
|
-
|
37
|
-
private
|
38
|
-
|
39
|
-
def base_request
|
40
|
-
req = "#{protocol}://maps.googleapis.com/maps/api/place/search/json?language=#{lang}&location=#{lat},#{lng}&sensor=false&radius=#{radius}&key=#{key}"
|
41
|
-
req += "&keyword=#{keyword}" unless keyword.nil?
|
42
|
-
req
|
43
|
-
end
|
44
|
-
|
45
|
-
def valid_position?
|
46
|
-
!(lat.nil? || lng.nil?)
|
47
|
-
end
|
48
|
-
|
49
|
-
def raise_invalid
|
50
|
-
raise Gmaps4rails::PlacesInvalidQuery, "You must provide at least a lat/lon for a Google places query"
|
51
|
-
end
|
52
|
-
|
53
|
-
def raise_missing_key
|
54
|
-
raise "Google Places API requires an API key"
|
55
|
-
end
|
56
|
-
|
57
|
-
def raise_net_status
|
58
|
-
raise Gmaps4rails::PlacesNetStatus, "The request sent to google was invalid (not http success): #{base_request}.\nResponse was: #{response}"
|
59
|
-
end
|
60
|
-
|
61
|
-
def raise_query_error
|
62
|
-
raise Gmaps4rails::PlacesStatus, "The address you passed seems invalid, status was: #{parsed_response["status"]}.\nRequest was: #{base_request}"
|
63
|
-
end
|
64
|
-
|
65
|
-
def get_response
|
66
|
-
uri = URI.parse(base_url)
|
67
|
-
http = Net::HTTP.new(uri.host, uri.port)
|
68
|
-
http.use_ssl = true # Places API wants https
|
69
|
-
http.verify_mode = OpenSSL::SSL::VERIFY_NONE # to avoid any cert issues
|
70
|
-
http.request(Net::HTTP::Get.new(uri.request_uri))
|
71
|
-
end
|
72
|
-
|
73
|
-
end
|
74
|
-
end
|
data/lib/gmaps4rails/base.rb
DELETED
@@ -1,119 +0,0 @@
|
|
1
|
-
require 'net/http'
|
2
|
-
require 'uri'
|
3
|
-
require 'json'
|
4
|
-
require 'ostruct'
|
5
|
-
|
6
|
-
module Gmaps4rails
|
7
|
-
|
8
|
-
require 'gmaps4rails/extensions/enumerable'
|
9
|
-
require 'gmaps4rails/extensions/hash'
|
10
|
-
|
11
|
-
autoload :ModelHandler, 'gmaps4rails/model_handler'
|
12
|
-
autoload :ActsAsGmappable, 'gmaps4rails/acts_as_gmappable'
|
13
|
-
|
14
|
-
autoload :JsBuilder, 'gmaps4rails/js_builder'
|
15
|
-
autoload :JsonBuilder, 'gmaps4rails/json_builder'
|
16
|
-
autoload :ViewHelper, 'gmaps4rails/view_helper'
|
17
|
-
autoload :Gmaps4railsHelper,'gmaps4rails/helper/gmaps4rails_helper'
|
18
|
-
|
19
|
-
autoload :BaseNetMethods, 'gmaps4rails/api_wrappers/base_net_methods'
|
20
|
-
autoload :Geocoder, 'gmaps4rails/api_wrappers/geocoder'
|
21
|
-
autoload :Direction, 'gmaps4rails/api_wrappers/direction'
|
22
|
-
autoload :Places, 'gmaps4rails/api_wrappers/places'
|
23
|
-
autoload :ObjectAccessor, 'gmaps4rails/object_accessor'
|
24
|
-
|
25
|
-
mattr_accessor :http_proxy, :escape_js_url
|
26
|
-
|
27
|
-
self.escape_js_url = true
|
28
|
-
|
29
|
-
# This method geocodes an address using the GoogleMaps webservice
|
30
|
-
# options are:
|
31
|
-
# * address: string, mandatory
|
32
|
-
# * lang: to set the language one wants the result to be translated (default is english)
|
33
|
-
# * raw: to get the raw response from google, default is false
|
34
|
-
def Gmaps4rails.geocode(address, lang="en", raw = false, protocol = "http")
|
35
|
-
::Gmaps4rails::Geocoder.new(address, {
|
36
|
-
:language => lang,
|
37
|
-
:raw => raw,
|
38
|
-
:protocol => protocol
|
39
|
-
}).get_coordinates
|
40
|
-
end
|
41
|
-
|
42
|
-
def Gmaps4rails.create_json(object, &block)
|
43
|
-
::Gmaps4rails::JsonBuilder.new(object).process(&block)
|
44
|
-
end
|
45
|
-
|
46
|
-
def Gmaps4rails.create_js_from_hash(hash)
|
47
|
-
::Gmaps4rails::JsBuilder.new(hash).create_js
|
48
|
-
end
|
49
|
-
|
50
|
-
# This method retrieves destination results provided by GoogleMaps webservice
|
51
|
-
# options are:
|
52
|
-
# * start_end: Hash { "from" => string, "to" => string}, mandatory
|
53
|
-
# * options: details given in the github's wiki
|
54
|
-
# * output: could be "pretty", "raw" or "clean"; filters the output from google
|
55
|
-
#output could be raw, pretty or clean
|
56
|
-
def Gmaps4rails.destination(start_end, options={}, output="pretty")
|
57
|
-
Gmaps4rails::Direction.new(start_end, options, output).get
|
58
|
-
end
|
59
|
-
|
60
|
-
# does two things... 1) gecode the given address string and 2) triggers a a places query around that geo location
|
61
|
-
# optionally a keyword can be given for a filter over all places fields (e.g. "Bungy" to give all Bungy related places)
|
62
|
-
# IMPORTANT: Places API calls require an API key (param "key")
|
63
|
-
|
64
|
-
def Gmaps4rails.places_for_address(address, key, keyword = nil, radius = 7500, lang="en", raw = false)
|
65
|
-
raise Gmaps4rails::GeocodeInvalidQuery, "you must provide an address for a places_for_address query" if address.nil?
|
66
|
-
raise "Google Places API requires an API key" if key.nil?
|
67
|
-
res = Gmaps4rails.geocode(address) # will throw exception if nothing could be geocoded
|
68
|
-
Gmaps4rails.places(res.first[:lat], res.first[:lng], key, keyword, radius, lang, raw)
|
69
|
-
end
|
70
|
-
|
71
|
-
# does a places query around give geo location (lat/lng)
|
72
|
-
# optionally a keyword can be given for a filter over all places fields (e.g. "Bungy" to give all Bungy related places)
|
73
|
-
# IMPORTANT: Places API calls require an API key (param "key")
|
74
|
-
def Gmaps4rails.places(lat, lng, key, keyword = nil, radius = 7500, lang="en", raw = false, protocol = "https")
|
75
|
-
Gmaps4rails::Places.new(lat, lng, {
|
76
|
-
:key => key,
|
77
|
-
:keyword => keyword,
|
78
|
-
:radius => radius,
|
79
|
-
:lang => lang,
|
80
|
-
:raw => raw,
|
81
|
-
:protocol => protocol
|
82
|
-
}).get
|
83
|
-
end
|
84
|
-
|
85
|
-
private
|
86
|
-
|
87
|
-
class GeocodeStatus < StandardError; end
|
88
|
-
class GeocodeNetStatus < StandardError; end
|
89
|
-
class GeocodeInvalidQuery < StandardError; end
|
90
|
-
|
91
|
-
class DirectionStatus < StandardError; end
|
92
|
-
class DirectionNetStatus < StandardError; end
|
93
|
-
class DirectionInvalidQuery < StandardError; end
|
94
|
-
|
95
|
-
class PlacesStatus < StandardError; end
|
96
|
-
class PlacesNetStatus < StandardError; end
|
97
|
-
class PlacesInvalidQuery < StandardError; end
|
98
|
-
|
99
|
-
def Gmaps4rails.condition_eval(object, condition)
|
100
|
-
case condition
|
101
|
-
when Symbol, String then object.send condition
|
102
|
-
when Proc then condition.call(object)
|
103
|
-
when TrueClass, FalseClass then condition
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
# looks for proxy settings and returns a Net::HTTP or Net::HTTP::Proxy class
|
108
|
-
def Gmaps4rails.http_agent
|
109
|
-
proxy = ENV['HTTP_PROXY'] || ENV['http_proxy'] || self.http_proxy
|
110
|
-
if proxy
|
111
|
-
proxy = URI.parse(proxy)
|
112
|
-
http_agent = Net::HTTP::Proxy(proxy.host,proxy.port)
|
113
|
-
else
|
114
|
-
http_agent = Net::HTTP
|
115
|
-
end
|
116
|
-
http_agent
|
117
|
-
end
|
118
|
-
|
119
|
-
end
|