Permalink
Browse files

extracted all remote functionality into geo-remote gem

  • Loading branch information...
1 parent 1c32034 commit 0e05cd2679ee8eaaaedc2a1a4be7b5a2737c96e7 @kristianmandrup committed Apr 1, 2012
Showing with 11 additions and 1,826 deletions.
  1. +5 −86 README.textile
  2. +1 −1 VERSION
  3. +1 −3 lib/geo_magic.rb
  4. +0 −48 lib/geo_magic/geocode/base_adapter.rb
  5. +0 −31 lib/geo_magic/geocode/config.rb
  6. +0 −28 lib/geo_magic/geocode/geocoder/adapter.rb
  7. +0 −107 lib/geo_magic/geocode/geocoder/api.rb
  8. +0 −29 lib/geo_magic/geocode/graticule/adapter.rb
  9. +0 −59 lib/geo_magic/geocode/graticule/multi_adapter.rb
  10. +0 −36 lib/geo_magic/geocoder.rb
  11. +0 −107 lib/geo_magic/location.rb
  12. +0 −11 lib/geo_magic/meta.rb
  13. +2 −0 lib/geo_magic/points.rb
  14. +1 −1 lib/geo_magic/{point/points_center.rb → points/center.rb}
  15. +1 −1 lib/geo_magic/{point → points}/random.rb
  16. +0 −23 lib/geo_magic/remote.rb
  17. +0 −25 lib/geo_magic/remote/class_methods.rb
  18. +0 −65 spec/geo_magic/calculate_spec.rb
  19. +0 −41 spec/geo_magic/distance/class_methods_spec.rb
  20. +0 −104 spec/geo_magic/distance/conversion_spec.rb
  21. +0 −30 spec/geo_magic/distance/formula/haversine_spec.rb
  22. +0 −32 spec/geo_magic/distance/formula/plane_spec.rb
  23. +0 −30 spec/geo_magic/distance/formula/spherical_spec.rb
  24. +0 −30 spec/geo_magic/distance/formula/vincenty_spec.rb
  25. +0 −45 spec/geo_magic/distance/point_distance_spec.rb
  26. +0 −38 spec/geo_magic/distance/points_distance_spec.rb
  27. +0 −27 spec/geo_magic/distance_spec.rb
  28. 0 spec/geo_magic/geocode/geocoder/adapter_spec.rb
  29. 0 spec/geo_magic/geocode/geocoder/api_spec.rb
  30. +0 −36 spec/geo_magic/geocode/geocoder_rails_spec.rb
  31. +0 −80 spec/geo_magic/geocode/geocoder_spec.rb
  32. 0 spec/geo_magic/geocode/graticule/adapter_spec.rb
  33. 0 spec/geo_magic/geocode/graticule/api_spec.rb
  34. +0 −36 spec/geo_magic/meta/include_calc_spec.rb
  35. +0 −31 spec/geo_magic/meta/include_remote_spec.rb
  36. +0 −100 spec/geo_magic/radius/circular_spec.rb
  37. 0 spec/geo_magic/radius/random_points_spec.rb
  38. +0 −97 spec/geo_magic/radius/rectangular_spec.rb
  39. +0 −77 spec/geo_magic/radius/square_spec.rb
  40. 0 spec/geo_magic/radius/within_radius_spec.rb
  41. 0 spec/geo_magic/radius_spec.rb
  42. +0 −26 spec/geo_magic/remote_spec.rb
  43. +0 −22 spec/geo_magic/shape/circle_spec.rb
  44. +0 −92 spec/geo_magic/shape/rectangle_spec.rb
  45. +0 −15 spec/geo_magic/shape/square_spec.rb
  46. +0 −14 spec/geo_magic/shape_spec.rb
  47. +0 −39 spec/geo_magic/vector/direction_vector_spec.rb
  48. +0 −32 spec/geo_magic/vector/distance_vector_spec.rb
  49. +0 −17 spec/geo_magic/vector/point_vector_spec.rb
  50. +0 −72 spec/geo_magic/vector_spec.rb
  51. +0 −2 spec/spec_helper.rb
View
@@ -1,99 +1,18 @@
h1. Geo Magic
-This little clever project was the result of me not being satisfied with existing Geo Location and Coding solutions out there to suit my needs.
+This little magic gem attempts to provide a nice DSL for performing Geo functionality.
+It levearegs some of my other geo- gems.
-Many of the projects did not return quality data (fx when requesting IP or location) and others were tightly bound to Active Record and SQL databases for calculations etc.
+*Geo Magic* should mainly be a DSL sugar-coating on top of these geo gems and integrate them all in a nice, convenient way under the cover.
-This little gem should get you going...
+Main features:
-Some of the main features:
-
-* Get IP and location data using freegeoip.net
-* Geocoding and Reverse Geocoding using adapters (currently: Graticule and Geocode gems)
* Find points within a radius (circle or square from center)
* Generate random points within a radius (for testing purposes)
-This gem attempts to provide a nice DSL for performing Geo functions.
-
h2. Update April 1 2012
-Major update under way. Trying to refactor gem to use the various geo gems that were previously extracted from this project. The 'remote' folder should also be extracted into a separate gem.
-GeoMagic should mainly be a DSL sugar-coating on top of these geo gems and integrate them all in a nice, convenient way under the cover.
-
-h2. IP and location data
-
-Uses "freegeoip.net":http://freegeoip.net JSON API
-
-RSpec 2 examples of API usage
-
-<pre>require 'geo_magic/remote'
-
-ip = GeoMagic::Remote.my_ip
-puts "ip: #{ip.inspect}"
-
-location = GeoMagic::Remote.location_of '74.200.247.59'
-puts "city: #{location['city']}"
-</pre>
-
-h2. Geocoder adapters
-
-The following Geocode adapters are supported
-
-* Geocoder
-* Graticule
-* GraticuleMulti
-
-Single Geocode Geocoder:
-
-<pre>
- # Use Graticule Multi geocoder, which tries multiple geocode services in succession!
- geocoder = GeoMagic.geo_coder(:type => :geocoder)
- # Set environment key to use or auto-detect if not explicitly passed as argument
- geocoder.configure 'map_api_keys.yaml', :development
- location = geocoder.instance.geocode "Mullerstrasse 9, Munich"
- location.city
-</pre>
-
-Single Graticule Geocoder:
-
-<pre>
- # Use Graticule geocoder
- geocoder = GeoMagic.geo_coder(:type => graticule)
- geocoder.configure 'map_api_keys.yaml', :development
- location = geocoder.instance.geocode "Mullerstrasse 9, Munich"
- location.city
-</pre>
-
-Multi Graticule Geocoder:
-
-<pre>
- # Use Graticule Multi geocoder, which tries multiple geocode services in succession!
- geocoder = GeoMagic.geo_coder(:type => graticule_multi)
- ..
-</pre>
-
-Multi Graticule Customization:
-
-<pre>
- # Use Graticule Multi geocoder, which tries multiple geocode services in succession!
- geocoder = GeoMagic.geo_coder(:type => graticule_multi)
- location = geocoder.instance(:timeout => 3) do |result|
- [:address, :street].include?(result.precision)]
- end
- ..
-</pre>
-
-Geocoder in Rails:
-
-<pre>
- geocoder = GeoMagic.geo_coder(:env => :rails).configure
-
- location = geocoder.instance.geocode "Mullerstrasse 9, Munich"
- location.city.should == 'Munich'
-</pre>
-
-By default, the configuration expects a file in config/map_api_keys.yml containing the keys for each environment (see spec/fictures folder).
-This can be customized if needed: @geocoder.configure '../my_keys.yaml'@
+Refactoring in progress
h3. Create random points in Radius
View
@@ -1 +1 @@
-0.2.4.3
+0.3.0
View
@@ -2,6 +2,4 @@
require 'active_support/inflector'
require 'geo_magic/core_ext'
-require 'geo_magic/remote'
-require 'geo_magic/meta'
-require 'geo_magic/geocoder'
+require 'geo_magic/points'
@@ -1,48 +0,0 @@
-module GeoMagic
- module Geocode
- class BaseAdapter
- attr_accessor :service_name, :environment
-
- def initialize services = :google, env = :default
- setup(env)
- @service_name = get_service(services)
- @environment = env
- end
-
- def configured?
- configured
- end
-
- def get_service services
- case services
- when String, Symbol
- services
- when Array
- services.first
- else
- raise ArgumentError, "service argument is not valid: #{services.inspect}"
- end
- end
-
- def get_key service_name
- method = "#{service_name}_key"
- raise ArgumentError, "Invalid map service: #{service_name}, must be one of #{GeoMagic::ServiceAdapter.services_available}" if !respond_to? method
- send method
- end
-
- def setup env
- case env
- when :rails
- require 'rails/config'
- self.class.send(:include, RailsServiceAdapter)
- else
- self.class.send(:include, ServiceAdapter)
- end
- end
-
- protected
-
- attr_accessor :configured
- end
- end
-end
@@ -1,31 +0,0 @@
-module GeoMagic
- module ServiceAdapter
- attr_reader :geo_coder, :config
-
- def geocode location_str
- raise 'method #geocode must be implemented by adapter subclass'
- end
-
- def reverse_geocode latitude, longitude
- raise 'method #reverse_geocode should be implemented by adapter subclass'
- end
-
- def configure path, env = :development
- @config ||= ::YAML.load_file(path)[env.to_s]
- send :configured, true
- self
- end
-
- def self.services_available
- [:google, :yahoo]
- end
-
- services_available.each do |api|
- class_eval %{
- def #{api}_key
- config['#{api}_key']
- end
- }
- end
- end
-end
@@ -1,28 +0,0 @@
-require 'geocode'
-require 'geo_magic/geocode/geocoder/api'
-
-module GeoMagic
- module Geocode
- class GeocoderAdapter < BaseAdapter
- def initialize service_name = :google, env = :default
- super
- end
-
- def instance
- @geo_coder ||= ::Geocode.new_geocoder service_name, {:google_api_key => google_key}
- self
- end
-
- def geocode location_str
- result = geo_coder.geocode(CGI.escape(location_str)).extend API
- # p result.data['Status']
- raise GeoMagic::GeoCodeError if result.data['Status']['code'] != 200
- result
- end
-
- def reverse_geocode latitude, longitude
- geo_coder.reverse_geocode "#{latitude}, #{longitude}"
- end
- end
- end
-end
@@ -1,107 +0,0 @@
-module GeoMagic
- module Geocode
- class GeocoderAdapter < BaseAdapter
- module API
- # Address
-
- def street
- thoroughfare["ThoroughfareName"] ? thoroughfare["ThoroughfareName"] : ""
- end
-
- def postal_code
- locality["PostalCode"] ? locality["PostalCode"]["PostalCodeNumber"] : ""
- end
- alias_method :zip, :postal_code
-
- def city
- subadm_api["SubAdministrativeAreaName"] ? subadm_api["SubAdministrativeAreaName"] : ""
- end
-
- def state
- adm_api["AdministrativeAreaName"] ? adm_api["AdministrativeAreaName"] : ""
- end
-
- def country_code
- country_api["CountryNameCode"] ? country_api["CountryNameCode"] : ""
- end
-
- def country_name
- country_api["CountryName"] ? country_api["CountryName"] : ""
- end
- alias_method :country, :country_name
-
- def address_hash
- {:street => street, :postal_code => postal_code, :city => city, :state => state, :country => country, :country_code => country_code}
- end
-
- # Location
-
- def latitude
- coords[1]
- end
-
- def longitude
- coords[0]
- end
-
- def location_hash
- {:longitude => longitude, :latitude => latitude}
- end
-
- protected
-
- def thoroughfare
- @thoroughfare ||= begin
- thorough = [:subadm_api, :locality_api, :dependent_locality_api].select do |api|
- x = send(api)
- x ? x["Thoroughfare"] : nil
- end
- thorough.empty? ? {} : send(thorough.first)["Thoroughfare"]
- end
- end
-
- def locality
- @locality ||= begin
- loc = [:locality_api, :dependent_locality_api].select do |api|
- x = send(api)
- x ? x["PostalCode"] || x["LocalityName"] : nil
- end
- loc.empty? ? {} : send(loc.first)
- end
- end
-
- def api
- data["Placemark"].first
- end
-
- def coords
- api["Point"]["coordinates"]
- end
-
- def adr_api
- api["AddressDetails"]
- end
-
- def country_api
- adr_api["Country"]
- end
-
- def adm_api
- country_api["AdministrativeArea"]
- end
-
- def subadm_api
- adm_api["SubAdministrativeArea"]
- end
-
- def locality_api
- subadm_api["Locality"]
- end
-
- def dependent_locality_api
- locality_api["DependentLocality"]
- end
- end
- end
- end
-end
@@ -1,29 +0,0 @@
-require 'graticule'
-
-module GeoMagic
- module Geocode
- class GraticuleAdapter < BaseAdapter
- def initialize services = :google, env = :default
- super
- end
-
- def instance
- @geo_coder ||= create_graticule_service
- self
- end
-
- def create_graticule_service key_name = nil
- api_key = get_key(key_name || service_name)
- gs_service.new api_key
- end
-
- def geocode location_str
- geo_coder.locate location_str
- end
-
- def gs_service
- ::Graticule.service(service_name)
- end
- end
- end
-end
Oops, something went wrong.

0 comments on commit 0e05cd2

Please sign in to comment.