gmaps4rails 2.0.0.pre → 2.0.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.
Files changed (184) hide show
  1. data/.travis.yml +2 -4
  2. data/Gemfile +5 -1
  3. data/Gemfile.lock +31 -113
  4. data/README.rdoc +53 -70
  5. data/Rakefile +21 -1
  6. data/gmaps4rails.gemspec +4 -19
  7. data/js_compilation/gmaps_google.js +961 -0
  8. data/lib/generators/gmaps4rails/copy_coffee_generator.rb +14 -0
  9. data/lib/generators/gmaps4rails/copy_js_generator.rb +15 -0
  10. data/lib/gmaps4rails.rb +12 -22
  11. data/lib/gmaps4rails/markers_builder.rb +74 -0
  12. data/lib/gmaps4rails/rails/engine.rb +6 -0
  13. data/lib/gmaps4rails/rails/railtie.rb +6 -0
  14. data/lib/gmaps4rails/version.rb +2 -2
  15. data/script/compile_coffee_files.rb +19 -0
  16. data/script/gmaps4rails.rake +7 -0
  17. data/spec/javascripts/google/builders/marker_spec.js +96 -0
  18. data/spec/javascripts/helpers/SpecHelper.js +101 -0
  19. data/spec/javascripts/helpers/matchers.js +12 -0
  20. data/spec/javascripts/helpers/underscore.js +6 -0
  21. data/spec/javascripts/objects/handler_spec.js +320 -0
  22. data/spec/javascripts/support/jasmine.yml +86 -0
  23. data/spec/javascripts/support/jasmine_helper.rb +11 -0
  24. data/spec/lib/base_spec.rb +10 -52
  25. data/spec/lib/markers_builder_spec.rb +49 -0
  26. data/spec/spec_helper.rb +1 -25
  27. data/vendor/assets/javascripts/gmaps/base.coffee +16 -0
  28. data/vendor/assets/javascripts/gmaps/base/base.coffee +17 -0
  29. data/vendor/assets/javascripts/gmaps/google.coffee +3 -0
  30. data/vendor/assets/javascripts/gmaps/google/builders/bound.coffee +6 -0
  31. data/vendor/assets/javascripts/gmaps/google/builders/circle.coffee +21 -0
  32. data/vendor/assets/javascripts/gmaps/google/builders/clusterer.coffee +6 -0
  33. data/vendor/assets/javascripts/gmaps/google/builders/kml.coffee +17 -0
  34. data/vendor/assets/javascripts/gmaps/google/builders/map.coffee +27 -0
  35. data/vendor/assets/javascripts/gmaps/google/builders/marker.coffee +100 -0
  36. data/vendor/assets/javascripts/gmaps/google/builders/polygon.coffee +24 -0
  37. data/vendor/assets/javascripts/gmaps/google/builders/polyline.coffee +24 -0
  38. data/vendor/assets/javascripts/gmaps/google/objects/bound.coffee +13 -0
  39. data/vendor/assets/javascripts/gmaps/google/objects/circle.coffee +9 -0
  40. data/vendor/assets/javascripts/gmaps/google/objects/clusterer.coffee +13 -0
  41. data/vendor/assets/javascripts/gmaps/google/objects/common.coffee +23 -0
  42. data/vendor/assets/javascripts/gmaps/google/objects/kml.coffee +15 -0
  43. data/vendor/assets/javascripts/gmaps/google/objects/map.coffee +19 -0
  44. data/vendor/assets/javascripts/gmaps/google/objects/marker.coffee +11 -0
  45. data/vendor/assets/javascripts/gmaps/google/objects/polygon.coffee +8 -0
  46. data/vendor/assets/javascripts/gmaps/google/objects/polyline.coffee +8 -0
  47. data/vendor/assets/javascripts/gmaps/google/primitives.coffee +43 -0
  48. data/vendor/assets/javascripts/gmaps/objects/base_builder.coffee +20 -0
  49. data/vendor/assets/javascripts/gmaps/objects/builder.coffee +12 -0
  50. data/vendor/assets/javascripts/gmaps/objects/handler.coffee +153 -0
  51. data/vendor/assets/javascripts/gmaps/objects/null_clusterer.coffee +4 -0
  52. metadata +66 -299
  53. data/Guardfile.old +0 -24
  54. data/app/views/gmaps4rails/_gmaps4rails.html.erb +0 -20
  55. data/lib/generators/gmaps4rails/install_generator.rb +0 -43
  56. data/lib/generators/templates/README +0 -2
  57. data/lib/gmaps4rails/acts_as_gmappable.rb +0 -54
  58. data/lib/gmaps4rails/api_wrappers/base_net_methods.rb +0 -40
  59. data/lib/gmaps4rails/api_wrappers/direction.rb +0 -87
  60. data/lib/gmaps4rails/api_wrappers/geocoder.rb +0 -54
  61. data/lib/gmaps4rails/api_wrappers/places.rb +0 -74
  62. data/lib/gmaps4rails/base.rb +0 -126
  63. data/lib/gmaps4rails/extensions/enumerable.rb +0 -14
  64. data/lib/gmaps4rails/extensions/hash.rb +0 -9
  65. data/lib/gmaps4rails/helper/gmaps4rails_helper.rb +0 -33
  66. data/lib/gmaps4rails/js_builder.rb +0 -154
  67. data/lib/gmaps4rails/json_builder.rb +0 -140
  68. data/lib/gmaps4rails/model_handler.rb +0 -101
  69. data/lib/gmaps4rails/view_helper.rb +0 -172
  70. data/lib/tasks/jasmine.rake +0 -8
  71. data/public/javascripts/gmaps4rails/all.js +0 -2144
  72. data/public/javascripts/gmaps4rails/base.js +0 -792
  73. data/public/javascripts/gmaps4rails/google.js +0 -556
  74. data/public/javascripts/gmaps4rails/openlayers.js +0 -377
  75. data/public/stylesheets/gmaps4rails.css +0 -24
  76. data/spec/dummy/.gitignore +0 -3
  77. data/spec/dummy/.rspec +0 -1
  78. data/spec/dummy/README.rdoc +0 -261
  79. data/spec/dummy/Rakefile +0 -7
  80. data/spec/dummy/app/assets/javascripts/application.js +0 -18
  81. data/spec/dummy/app/assets/stylesheets/application.css +0 -15
  82. data/spec/dummy/app/assets/stylesheets/gmaps4rails.css +0 -24
  83. data/spec/dummy/app/controllers/application_controller.rb +0 -3
  84. data/spec/dummy/app/controllers/users_controller.rb +0 -105
  85. data/spec/dummy/app/helpers/application_helper.rb +0 -2
  86. data/spec/dummy/app/mailers/.gitkeep +0 -0
  87. data/spec/dummy/app/models/.gitkeep +0 -0
  88. data/spec/dummy/app/models/place.rb +0 -16
  89. data/spec/dummy/app/models/user.rb +0 -12
  90. data/spec/dummy/app/views/layouts/application.html.erb +0 -17
  91. data/spec/dummy/app/views/users/_form.html.erb +0 -37
  92. data/spec/dummy/app/views/users/edit.html.erb +0 -6
  93. data/spec/dummy/app/views/users/index.html.erb +0 -268
  94. data/spec/dummy/app/views/users/new.html.erb +0 -5
  95. data/spec/dummy/app/views/users/show.html.erb +0 -30
  96. data/spec/dummy/config.ru +0 -4
  97. data/spec/dummy/config/application.rb +0 -62
  98. data/spec/dummy/config/boot.rb +0 -10
  99. data/spec/dummy/config/database.yml +0 -25
  100. data/spec/dummy/config/environment.rb +0 -5
  101. data/spec/dummy/config/environments/development.rb +0 -37
  102. data/spec/dummy/config/environments/production.rb +0 -67
  103. data/spec/dummy/config/environments/test.rb +0 -37
  104. data/spec/dummy/config/initializers/backtrace_silencers.rb +0 -7
  105. data/spec/dummy/config/initializers/gmaps4rails.rb +0 -1
  106. data/spec/dummy/config/initializers/inflections.rb +0 -15
  107. data/spec/dummy/config/initializers/mime_types.rb +0 -5
  108. data/spec/dummy/config/initializers/secret_token.rb +0 -7
  109. data/spec/dummy/config/initializers/session_store.rb +0 -8
  110. data/spec/dummy/config/initializers/wrap_parameters.rb +0 -14
  111. data/spec/dummy/config/locales/en.yml +0 -5
  112. data/spec/dummy/config/routes.rb +0 -60
  113. data/spec/dummy/db/migrate/20120408170155_create_users.rb +0 -16
  114. data/spec/dummy/db/schema.rb +0 -29
  115. data/spec/dummy/lib/assets/.gitkeep +0 -0
  116. data/spec/dummy/log/.gitkeep +0 -0
  117. data/spec/dummy/public/404.html +0 -26
  118. data/spec/dummy/public/422.html +0 -26
  119. data/spec/dummy/public/500.html +0 -25
  120. data/spec/dummy/public/favicon.ico +0 -0
  121. data/spec/dummy/public/javascripts/Player.js +0 -22
  122. data/spec/dummy/public/javascripts/Song.js +0 -7
  123. data/spec/dummy/public/logo.png +0 -0
  124. data/spec/dummy/script/rails +0 -6
  125. data/spec/factories/place_factory.rb +0 -16
  126. data/spec/factories/user_factory.rb +0 -23
  127. data/spec/fixtures/google_direction_valid.json +0 -65
  128. data/spec/fixtures/google_geocoding_toulon_france.json +0 -58
  129. data/spec/fixtures/google_places_valid.json +0 -45
  130. data/spec/fixtures/google_wrong_geocoding.json +0 -4
  131. data/spec/launchers/all_but_requests.rb +0 -0
  132. data/spec/launchers/all_specs.rb +0 -0
  133. data/spec/launchers/requests.rb +0 -0
  134. data/spec/lib/direction_spec.rb +0 -53
  135. data/spec/lib/geocoder_spec.rb +0 -46
  136. data/spec/lib/js_builder_spec.rb +0 -134
  137. data/spec/lib/json_builder_spec.rb +0 -232
  138. data/spec/lib/places_spec.rb +0 -25
  139. data/spec/models/place_spec.rb +0 -39
  140. data/spec/models/user_spec.rb +0 -187
  141. data/spec/support/geocoding.rb +0 -40
  142. data/spec/support/matchers.rb +0 -73
  143. data/todo +0 -0
  144. data/vendor/assets/javascripts/gmaps4rails/all.js +0 -1
  145. data/vendor/assets/javascripts/gmaps4rails/base.coffee +0 -1
  146. data/vendor/assets/javascripts/gmaps4rails/base/common.coffee +0 -43
  147. data/vendor/assets/javascripts/gmaps4rails/base/configuration.coffee +0 -7
  148. data/vendor/assets/javascripts/gmaps4rails/base/gmaps.coffee +0 -13
  149. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/basic_interface.coffee +0 -15
  150. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/controller_interface.coffee +0 -15
  151. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/map_interface.coffee +0 -27
  152. data/vendor/assets/javascripts/gmaps4rails/base/interfaces/marker_interface.coffee +0 -15
  153. data/vendor/assets/javascripts/gmaps4rails/base/main.coffee +0 -124
  154. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/circle_controller.coffee +0 -29
  155. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/kml_controller.coffee +0 -5
  156. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/marker_controller.coffee +0 -76
  157. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polygon_controller.coffee +0 -29
  158. data/vendor/assets/javascripts/gmaps4rails/base/main_controller_extensions/polyline_controller.coffee +0 -29
  159. data/vendor/assets/javascripts/gmaps4rails/base/objects/circle.coffee +0 -12
  160. data/vendor/assets/javascripts/gmaps4rails/base/objects/kml.coffee +0 -8
  161. data/vendor/assets/javascripts/gmaps4rails/base/objects/map.coffee +0 -62
  162. data/vendor/assets/javascripts/gmaps4rails/base/objects/marker.coffee +0 -24
  163. data/vendor/assets/javascripts/gmaps4rails/base/objects/polygon.coffee +0 -11
  164. data/vendor/assets/javascripts/gmaps4rails/base/objects/polyline.coffee +0 -11
  165. data/vendor/assets/javascripts/gmaps4rails/bing.coffee +0 -1
  166. data/vendor/assets/javascripts/gmaps4rails/bing/main.coffee +0 -29
  167. data/vendor/assets/javascripts/gmaps4rails/bing/objects/map.coffee +0 -63
  168. data/vendor/assets/javascripts/gmaps4rails/bing/objects/marker.coffee +0 -78
  169. data/vendor/assets/javascripts/gmaps4rails/bing/shared.coffee +0 -20
  170. data/vendor/assets/javascripts/gmaps4rails/google.coffee +0 -1
  171. data/vendor/assets/javascripts/gmaps4rails/google/main.coffee +0 -47
  172. data/vendor/assets/javascripts/gmaps4rails/google/objects/circle.coffee +0 -38
  173. data/vendor/assets/javascripts/gmaps4rails/google/objects/kml.coffee +0 -16
  174. data/vendor/assets/javascripts/gmaps4rails/google/objects/map.coffee +0 -71
  175. data/vendor/assets/javascripts/gmaps4rails/google/objects/marker.coffee +0 -114
  176. data/vendor/assets/javascripts/gmaps4rails/google/objects/polygon.coffee +0 -38
  177. data/vendor/assets/javascripts/gmaps4rails/google/objects/polyline.coffee +0 -49
  178. data/vendor/assets/javascripts/gmaps4rails/google/shared.coffee +0 -27
  179. data/vendor/assets/javascripts/gmaps4rails/openlayers.coffee +0 -1
  180. data/vendor/assets/javascripts/gmaps4rails/openlayers/main.coffee +0 -138
  181. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/map.coffee +0 -49
  182. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/marker.coffee +0 -68
  183. data/vendor/assets/javascripts/gmaps4rails/openlayers/objects/polyline.coffee +0 -39
  184. data/vendor/assets/javascripts/gmaps4rails/openlayers/shared.coffee +0 -19
data/Guardfile.old DELETED
@@ -1,24 +0,0 @@
1
- # guard 'spork', :rspec_env => { 'RAILS_ENV' => 'test' } do
2
- # watch('config/application.rb')
3
- # watch('config/environment.rb')
4
- # watch(%r{^config/environments/.+\.rb$})
5
- # watch(%r{^config/initializers/.+\.rb$})
6
- # watch('Gemfile')
7
- # watch('Gemfile.lock')
8
- # watch('spec/spec_helper.rb') { :rspec }
9
- # end
10
-
11
- # guard 'rspec', :cli => "-c -f d", :all_on_start => false, :all_after_pass => false do
12
- # watch(%r{^spec/.+_spec\.rb$})
13
- # watch('spec/launchers/all_specs.rb') { "spec" }
14
- # watch('spec/launchers/all_but_requests.rb') { ["spec/base", "spec/helpers", "spec/models", "spec/views", "spec/javascripts"] }
15
- # watch('spec/launchers/requests.rb') { "spec/requests" }
16
- # end
17
-
18
- # guard 'jasmine', :jasmine_url => 'http://localhost:8888/', :all_on_start => false, :all_after_pass => false do
19
- # watch(%r{spec/javascripts/spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
20
- # watch(%r{^spec/javascripts/.+_spec\.(js\.coffee|js|coffee)$}) { "spec/javascripts" }
21
- # watch(%r{^spec/javascripts/.+_spec\.js$}) { "spec/javascripts" }
22
- # end
23
-
24
- # guard 'coffeescript', :input => 'app/assets/javascripts/gmaps4rails', :output => 'public/javascripts/gmaps4rails'
@@ -1,20 +0,0 @@
1
- <% content_for :scripts do %>
2
- <%= javascript_include_tag *js_dependencies %>
3
-
4
- <script type="text/javascript">
5
- <%=raw options.to_gmaps4rails %>
6
- </script>
7
- <% end %>
8
-
9
- <% case dom.map_provider %>
10
- <% when "mapquest" %>
11
- <div id="<%= dom.map_id %>" style="width:750px; height:475px;">
12
- <!-- TODO: change this style dynamically -->
13
- </div>
14
- <% when "bing" %>
15
- <div id="<%= dom.map_id %>" class="<%= dom.map_class %>"></div>
16
- <% else %>
17
- <div class="<%= dom.container_class %>">
18
- <div id="<%= dom.map_id %>" class="<%= dom.map_class %>"></div>
19
- </div>
20
- <% end %>
@@ -1,43 +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 Gmaps4rails.pipeline_enabled?
10
- directory assets_source_path, assets_destination_path
11
- copy_file "../../../public/stylesheets/gmaps4rails.css", "vendor/assets/stylesheets/gmaps4rails.css"
12
- else
13
- %w( base google openlayers all ).each do |filename|
14
- copy_file js_source_path(filename), js_destination_path(filename)
15
- end
16
- copy_file "../../../public/stylesheets/gmaps4rails.css", "public/stylesheets/gmaps4rails.css"
17
- end
18
- end
19
-
20
- def show_readme
21
- readme 'README' if behavior == :invoke
22
- end
23
-
24
- private
25
-
26
- def assets_source_path
27
- '../../../vendor/assets/javascripts/gmaps4rails/'
28
- end
29
-
30
- def assets_destination_path
31
- 'vendor/assets/javascripts/gmaps4rails'
32
- end
33
-
34
- def js_source_path(filename)
35
- "../../../public/javascripts/gmaps4rails/#{filename}.js"
36
- end
37
-
38
- def js_destination_path(filename)
39
- "public/javascripts/gmaps4rails/#{filename}.js"
40
- end
41
- end
42
- end
43
- end
@@ -1,2 +0,0 @@
1
- **************************************
2
- Google Maps For Rails
@@ -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
@@ -1,126 +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
- # checks whether or not the app has pipeline enabled
120
- # works for Rails 3.0.x and above
121
- # @return [Boolean]
122
- def Gmaps4rails.pipeline_enabled?
123
- Rails.configuration.respond_to?('assets') && Rails.configuration.assets.enabled
124
- end
125
-
126
- end