Skip to content

Commit

Permalink
debug output for all methods
Browse files Browse the repository at this point in the history
  • Loading branch information
Stefan Lewandowski committed Dec 29, 2009
1 parent 9eb2024 commit bb31ecd
Showing 1 changed file with 14 additions and 3 deletions.
17 changes: 14 additions & 3 deletions lib/geoapi/entity.rb
Expand Up @@ -12,6 +12,7 @@ class Entity < GeoAPI::GeoObject


def self.create(params)
puts "GEOAPI::Entity.create #{params.to_json}"
#required: name, geom
#optional: pass id and it will create a new guid for you as user-<apikey>-<id>

Expand All @@ -36,6 +37,7 @@ def self.create(params)
end

def self.destroy(params)
puts "GEOAPI::Entity.destroy #{params.to_json}"
raise ArgumentError, "An id or guid is required (pass :id or :guid in parameters)" unless params.has_key?(:id) || params.has_key?(:guid)

begin
Expand All @@ -51,13 +53,14 @@ def self.destroy(params)
end

def self.create_at_lat_lng(params, lat, lng)
puts "GEOAPI::Entity.create_at_lat_lng #{lat},#{lng}"
p = GeoAPI::Point.new(lat,lng)

self.create(params.merge({:geom=>p}))
end

def self.find(*args)

puts "GEOAPI::Entity.find #{args.to_s}"
raise ArgumentError, "First argument must be symbol (:all or :get)" unless args.first.kind_of?(Symbol)

params = args.extract_options!
Expand Down Expand Up @@ -88,14 +91,17 @@ def self.find(*args)
end

def self.find_by_id(the_id)
puts "GEOAPI::Entity.find_by_id #{the_id}"
self.find(:get, :guid=>"user-#{GeoAPI::API_KEY}-#{the_id}")
end

def self.find_by_guid(the_guid)
puts "GEOAPI::Entity.find_by_guid #{the_guid}"
self.find(:get, :guid=>the_guid)
end

def self.search(lat, lng, conditions)
puts "GEOAPI::Entity.search #{lat},#{lng} | #{conditions.to_s}"
# Accepts all conditions from the API and passes them through - http://docs.geoapi.com/Simple-Search
begin
response = get("/search", :query=>conditions.merge({:lat=>lat,:lon=>lng}))
Expand All @@ -119,9 +125,10 @@ def initialize(attrs)
end

def setup(attrs)

self.guid = attrs['guid'] unless attrs['guid'].blank?
self.guid = "user-#{GeoAPI::API_KEY}-#{attrs['id']}" unless attrs['id'].blank?
puts "GEOAPI::Entity.setup #{self.guid}"
self.errors = attrs['error']
self.name = attrs['name']
self.entity_type = attrs['type']
Expand Down Expand Up @@ -179,10 +186,13 @@ def type #type is a reserved word
end

def update
self.setup(post("/e/#{guid}"))
puts "GEOAPI::Entity.update #{self.guid}"
self.setup(post("/e/#{guid}", :body=>{self.to_json}))
end

def load
puts "GEOAPI::Entity.load #{self.guid}"

raise ArgumentError, "Properties should include a .guid or .id" if self.guid.blank? && self.id.blank?

the_guid = self.guid
Expand All @@ -200,6 +210,7 @@ def load
end

def delete
puts "GEOAPI::Entity.delete #{self.guid}"
raise ArgumentError, "Object has no :guid" if self.guid.blank?
begin
Entity.destroy(:guid=>self.guid)
Expand Down

0 comments on commit bb31ecd

Please sign in to comment.