kingpin 0.5.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.rspec +1 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/kingpin.gemspec +70 -0
- data/lib/http_client.rb +62 -0
- data/lib/kingpin.rb +103 -0
- data/lib/pin_caster.rb +89 -0
- data/lib/pincaster.rb +1 -0
- data/lib/pincaster_layer.rb +9 -0
- data/lib/pincaster_pin.rb +13 -0
- data/spec/pincaster_spec.rb +7 -0
- data/spec/spec_helper.rb +12 -0
- metadata +146 -0
data/.document
ADDED
data/.rspec
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
--color
|
data/Gemfile
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
source "http://rubygems.org"
|
2
|
+
# Add dependencies required to use your gem here.
|
3
|
+
# Example:
|
4
|
+
# gem "activesupport", ">= 2.3.5"
|
5
|
+
|
6
|
+
# Add dependencies to develop your gem here.
|
7
|
+
# Include everything needed to run rake, tests, features, etc.
|
8
|
+
group :development do
|
9
|
+
gem "rspec", "~> 2.3.0"
|
10
|
+
gem "bundler", "~> 1.0.0"
|
11
|
+
gem "jeweler", "~> 1.5.2"
|
12
|
+
gem "rcov", ">= 0"
|
13
|
+
end
|
data/Gemfile.lock
ADDED
@@ -0,0 +1,28 @@
|
|
1
|
+
GEM
|
2
|
+
remote: http://rubygems.org/
|
3
|
+
specs:
|
4
|
+
diff-lcs (1.1.2)
|
5
|
+
git (1.2.5)
|
6
|
+
jeweler (1.5.2)
|
7
|
+
bundler (~> 1.0.0)
|
8
|
+
git (>= 1.2.5)
|
9
|
+
rake
|
10
|
+
rake (0.8.7)
|
11
|
+
rcov (0.9.9)
|
12
|
+
rspec (2.3.0)
|
13
|
+
rspec-core (~> 2.3.0)
|
14
|
+
rspec-expectations (~> 2.3.0)
|
15
|
+
rspec-mocks (~> 2.3.0)
|
16
|
+
rspec-core (2.3.1)
|
17
|
+
rspec-expectations (2.3.0)
|
18
|
+
diff-lcs (~> 1.1.2)
|
19
|
+
rspec-mocks (2.3.0)
|
20
|
+
|
21
|
+
PLATFORMS
|
22
|
+
ruby
|
23
|
+
|
24
|
+
DEPENDENCIES
|
25
|
+
bundler (~> 1.0.0)
|
26
|
+
jeweler (~> 1.5.2)
|
27
|
+
rcov
|
28
|
+
rspec (~> 2.3.0)
|
data/LICENSE.txt
ADDED
@@ -0,0 +1,20 @@
|
|
1
|
+
Copyright (c) 2011 Jan Roesner
|
2
|
+
|
3
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
4
|
+
a copy of this software and associated documentation files (the
|
5
|
+
"Software"), to deal in the Software without restriction, including
|
6
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
7
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
8
|
+
permit persons to whom the Software is furnished to do so, subject to
|
9
|
+
the following conditions:
|
10
|
+
|
11
|
+
The above copyright notice and this permission notice shall be
|
12
|
+
included in all copies or substantial portions of the Software.
|
13
|
+
|
14
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
15
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
16
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
17
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
18
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
19
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
20
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.rdoc
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
= kingpin
|
2
|
+
|
3
|
+
Description goes here.
|
4
|
+
|
5
|
+
== Contributing to kingpin
|
6
|
+
|
7
|
+
* Check out the latest master to make sure the feature hasn't been implemented or the bug hasn't been fixed yet
|
8
|
+
* Check out the issue tracker to make sure someone already hasn't requested it and/or contributed it
|
9
|
+
* Fork the project
|
10
|
+
* Start a feature/bugfix branch
|
11
|
+
* Commit and push until you are happy with your contribution
|
12
|
+
* Make sure to add tests for it. This is important so I don't break it in a future version unintentionally.
|
13
|
+
* Please try not to mess with the Rakefile, version, or history. If you want to have your own version, or is otherwise necessary, that is fine, but please isolate to its own commit so I can cherry-pick around it.
|
14
|
+
|
15
|
+
== Copyright
|
16
|
+
|
17
|
+
Copyright (c) 2011 Jan Roesner. See LICENSE.txt for
|
18
|
+
further details.
|
19
|
+
|
data/Rakefile
ADDED
@@ -0,0 +1,50 @@
|
|
1
|
+
require 'rubygems'
|
2
|
+
require 'bundler'
|
3
|
+
begin
|
4
|
+
Bundler.setup(:default, :development)
|
5
|
+
rescue Bundler::BundlerError => e
|
6
|
+
$stderr.puts e.message
|
7
|
+
$stderr.puts "Run `bundle install` to install missing gems"
|
8
|
+
exit e.status_code
|
9
|
+
end
|
10
|
+
require 'rake'
|
11
|
+
|
12
|
+
require 'jeweler'
|
13
|
+
Jeweler::Tasks.new do |gem|
|
14
|
+
# gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
|
15
|
+
gem.name = "kingpin"
|
16
|
+
gem.homepage = "http://railspotting.de"
|
17
|
+
gem.license = "MIT"
|
18
|
+
gem.summary = %Q{Kingpin makes your ActiveRecord model a Pincaster pin and thus geosearcheable. Fast!}
|
19
|
+
gem.description = %Q{Kingpin extends every ActiveRecord model to become a Pincaster pin automatically. Thus the model automatically creates a Pincaster pin everytime it is saved. Kingpin afterwards provides methods at class and instance level that make geolocation easy and thanks to Pincaster amazingly fast.}
|
20
|
+
gem.email = "jan@roesner.it"
|
21
|
+
gem.authors = ["Jan Roesner"]
|
22
|
+
# Include your dependencies below. Runtime dependencies are required when using your gem,
|
23
|
+
# and development dependencies are only needed for development (ie running rake tasks, tests, etc)
|
24
|
+
# gem.add_runtime_dependency 'jabber4r', '> 0.1'
|
25
|
+
# gem.add_development_dependency 'rspec', '> 1.2.3'
|
26
|
+
end
|
27
|
+
Jeweler::RubygemsDotOrgTasks.new
|
28
|
+
|
29
|
+
require 'rspec/core'
|
30
|
+
require 'rspec/core/rake_task'
|
31
|
+
RSpec::Core::RakeTask.new(:spec) do |spec|
|
32
|
+
spec.pattern = FileList['spec/**/*_spec.rb']
|
33
|
+
end
|
34
|
+
|
35
|
+
RSpec::Core::RakeTask.new(:rcov) do |spec|
|
36
|
+
spec.pattern = 'spec/**/*_spec.rb'
|
37
|
+
spec.rcov = true
|
38
|
+
end
|
39
|
+
|
40
|
+
task :default => :spec
|
41
|
+
|
42
|
+
require 'rake/rdoctask'
|
43
|
+
Rake::RDocTask.new do |rdoc|
|
44
|
+
version = File.exist?('VERSION') ? File.read('VERSION') : ""
|
45
|
+
|
46
|
+
rdoc.rdoc_dir = 'rdoc'
|
47
|
+
rdoc.title = "kingpin #{version}"
|
48
|
+
rdoc.rdoc_files.include('README*')
|
49
|
+
rdoc.rdoc_files.include('lib/**/*.rb')
|
50
|
+
end
|
data/VERSION
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
0.5.0
|
data/kingpin.gemspec
ADDED
@@ -0,0 +1,70 @@
|
|
1
|
+
# Generated by jeweler
|
2
|
+
# DO NOT EDIT THIS FILE DIRECTLY
|
3
|
+
# Instead, edit Jeweler::Tasks in Rakefile, and run 'rake gemspec'
|
4
|
+
# -*- encoding: utf-8 -*-
|
5
|
+
|
6
|
+
Gem::Specification.new do |s|
|
7
|
+
s.name = %q{kingpin}
|
8
|
+
s.version = "0.5.0"
|
9
|
+
|
10
|
+
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
|
+
s.authors = ["Jan Roesner"]
|
12
|
+
s.date = %q{2011-03-11}
|
13
|
+
s.description = %q{Kingpin extends every ActiveRecord model to become a Pincaster pin automatically. Thus the model automatically creates a Pincaster pin everytime it is saved. Kingpin afterwards provides methods at class and instance level that make geolocation easy and thanks to Pincaster amazingly fast.}
|
14
|
+
s.email = %q{jan@roesner.it}
|
15
|
+
s.extra_rdoc_files = [
|
16
|
+
"LICENSE.txt",
|
17
|
+
"README.rdoc"
|
18
|
+
]
|
19
|
+
s.files = [
|
20
|
+
".document",
|
21
|
+
".rspec",
|
22
|
+
"Gemfile",
|
23
|
+
"Gemfile.lock",
|
24
|
+
"LICENSE.txt",
|
25
|
+
"README.rdoc",
|
26
|
+
"Rakefile",
|
27
|
+
"VERSION",
|
28
|
+
"kingpin.gemspec",
|
29
|
+
"lib/http_client.rb",
|
30
|
+
"lib/kingpin.rb",
|
31
|
+
"lib/pin_caster.rb",
|
32
|
+
"lib/pincaster.rb",
|
33
|
+
"lib/pincaster_layer.rb",
|
34
|
+
"lib/pincaster_pin.rb",
|
35
|
+
"spec/pincaster_spec.rb",
|
36
|
+
"spec/spec_helper.rb"
|
37
|
+
]
|
38
|
+
s.homepage = %q{http://railspotting.de}
|
39
|
+
s.licenses = ["MIT"]
|
40
|
+
s.require_paths = ["lib"]
|
41
|
+
s.rubygems_version = %q{1.3.7}
|
42
|
+
s.summary = %q{Kingpin makes your ActiveRecord model a Pincaster pin and thus geosearcheable. Fast!}
|
43
|
+
s.test_files = [
|
44
|
+
"spec/pincaster_spec.rb",
|
45
|
+
"spec/spec_helper.rb"
|
46
|
+
]
|
47
|
+
|
48
|
+
if s.respond_to? :specification_version then
|
49
|
+
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
50
|
+
s.specification_version = 3
|
51
|
+
|
52
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
53
|
+
s.add_development_dependency(%q<rspec>, ["~> 2.3.0"])
|
54
|
+
s.add_development_dependency(%q<bundler>, ["~> 1.0.0"])
|
55
|
+
s.add_development_dependency(%q<jeweler>, ["~> 1.5.2"])
|
56
|
+
s.add_development_dependency(%q<rcov>, [">= 0"])
|
57
|
+
else
|
58
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
59
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
60
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
61
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
62
|
+
end
|
63
|
+
else
|
64
|
+
s.add_dependency(%q<rspec>, ["~> 2.3.0"])
|
65
|
+
s.add_dependency(%q<bundler>, ["~> 1.0.0"])
|
66
|
+
s.add_dependency(%q<jeweler>, ["~> 1.5.2"])
|
67
|
+
s.add_dependency(%q<rcov>, [">= 0"])
|
68
|
+
end
|
69
|
+
end
|
70
|
+
|
data/lib/http_client.rb
ADDED
@@ -0,0 +1,62 @@
|
|
1
|
+
class HttpClient
|
2
|
+
|
3
|
+
require 'net/http'
|
4
|
+
require "cgi"
|
5
|
+
require "benchmark"
|
6
|
+
|
7
|
+
def initialize(protocol, host, port, namespace=nil)
|
8
|
+
@http = Net::HTTP.new(host, port)
|
9
|
+
@protocol = protocol
|
10
|
+
@host = host
|
11
|
+
@port = port
|
12
|
+
@namespace = namespace
|
13
|
+
end
|
14
|
+
|
15
|
+
def send_request(method, resource, headers=nil, data=nil, params=nil)
|
16
|
+
return self.send(method.to_s.downcase, headers, resource, data, params)
|
17
|
+
end
|
18
|
+
|
19
|
+
protected
|
20
|
+
|
21
|
+
# sends GET request and returns response
|
22
|
+
def get(headers, resource, data, params)
|
23
|
+
request = Net::HTTP::Get.new(build_uri(resource, params).request_uri, headers)
|
24
|
+
@http.request(request)
|
25
|
+
end
|
26
|
+
|
27
|
+
# sends PUT request and returns response
|
28
|
+
def put(headers, resource, data, params)
|
29
|
+
request = Net::HTTP::Put.new(resource_path(resource), headers)
|
30
|
+
request.body = params.nil? ? data.to_json : params.to_query
|
31
|
+
@http.request(request)
|
32
|
+
end
|
33
|
+
|
34
|
+
# sends POST request and returns response
|
35
|
+
def post(headers, resource, data, params)
|
36
|
+
request = Net::HTTP::Post.new(resource_path(resource), headers)
|
37
|
+
request.body = params.nil? ? data.to_json : params.to_query
|
38
|
+
@http.request(request)
|
39
|
+
end
|
40
|
+
|
41
|
+
# sends DELETE request and returns response
|
42
|
+
def delete(headers, resource, data, params)
|
43
|
+
request = Net::HTTP::Delete.new(resource_path(resource), headers)
|
44
|
+
@http.request(request)
|
45
|
+
end
|
46
|
+
|
47
|
+
# redefines the resource path including the namespace
|
48
|
+
def resource_path(resource)
|
49
|
+
@namespace.nil? ? resource : "/" + @namespace + resource
|
50
|
+
end
|
51
|
+
|
52
|
+
# rebuild a uri in details, so that another protocol, host, port and GET params can be specified, after Net::HTTP was created
|
53
|
+
def build_uri(resource, params=nil)
|
54
|
+
uri = URI.parse(@protocol + "://" + @host + ((@port.nil? || @port != "80") ? ":#{@port}" : ""))
|
55
|
+
uri.scheme = @protocol
|
56
|
+
uri.host = @host
|
57
|
+
uri.port = @port
|
58
|
+
uri.query = params.collect{ |k,v| "#{k}=#{CGI::escape(v.to_s)}" }.reverse.join('&') if not params.nil?
|
59
|
+
uri.path = resource_path(resource)
|
60
|
+
uri
|
61
|
+
end
|
62
|
+
end
|
data/lib/kingpin.rb
ADDED
@@ -0,0 +1,103 @@
|
|
1
|
+
###
|
2
|
+
# Kingpin - makes models pinnable
|
3
|
+
###
|
4
|
+
|
5
|
+
module Kingpin
|
6
|
+
class << self.class.superclass
|
7
|
+
def pinnable(*args)
|
8
|
+
include KingpinInstanceMethods
|
9
|
+
self.kingpin_args = args
|
10
|
+
named_scope :nearby, lambda { |point, radius| { :conditions => ["id in (?)", point.nearby_ids(radius)] } }
|
11
|
+
after_save :autopin if !!args.first[:autopin]
|
12
|
+
end
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
###
|
17
|
+
# PinInstanceMethods - provides models new instance methods
|
18
|
+
###
|
19
|
+
|
20
|
+
module KingpinInstanceMethods
|
21
|
+
def self.included(base)
|
22
|
+
base.extend KingpinClassMethods
|
23
|
+
end
|
24
|
+
|
25
|
+
# add a Pincaster record for self with in layer: self.class
|
26
|
+
def add_pin
|
27
|
+
Pincaster.add_record(self)
|
28
|
+
end
|
29
|
+
|
30
|
+
# returns the Pincaster pin for self
|
31
|
+
def pin
|
32
|
+
Pincaster.get_record(self)
|
33
|
+
end
|
34
|
+
|
35
|
+
# deletes the Pincaster pin for self
|
36
|
+
def delete_pin!
|
37
|
+
Pincaster.delete_record(self)
|
38
|
+
end
|
39
|
+
|
40
|
+
# returns nearby found record_ids in same layer as self, radius meters away, number of results limited to limit
|
41
|
+
def nearby_ids(radius, limit=nil)
|
42
|
+
JSON.parse(Pincaster.nearby(self, radius, limit))["matches"].map{|p| p["key"]}
|
43
|
+
end
|
44
|
+
|
45
|
+
# returns nearby found records in same layer as self, radius metera away, number of results limited to limit
|
46
|
+
def nearby(radius, limit=nil)
|
47
|
+
self.class.find(nearby_ids(radius, limit))
|
48
|
+
end
|
49
|
+
|
50
|
+
# returns objects longitude depending on configured method name for access as well as DEG or RAD configuration
|
51
|
+
def pin_lng
|
52
|
+
if self.class.kingpin_args.nil?
|
53
|
+
[:longitude, :long, :lng, :lgt, :lgdt].each do |l|
|
54
|
+
return self.send(l) if self.respond_to?(l)
|
55
|
+
end
|
56
|
+
return nil
|
57
|
+
else
|
58
|
+
if !!self.class.kingpin_args[:methods]
|
59
|
+
return !!self.class.kingpin_args[:rad] ? self.send(self.class.kingpin_args[:methods][:lng]).to_f * 180.0 / Math::PI : self.send(self.class.kingpin_args[:methods][:lng])
|
60
|
+
else
|
61
|
+
return self.send(self.class.kingpin_args[:methods][:lng])
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
65
|
+
|
66
|
+
# returns objects latitude depending on configured method name for access as well as DEG or RAD configuration
|
67
|
+
def pin_lat
|
68
|
+
if self.class.kingpin_args.nil?
|
69
|
+
[:latitude, :lati, :ltt, :ltd, :lat].each do |l|
|
70
|
+
return self.send(l) if self.respond_to?(l)
|
71
|
+
end
|
72
|
+
return nil
|
73
|
+
else
|
74
|
+
if !!self.class.kingpin_args[:methods]
|
75
|
+
return !!self.class.kingpin_args[:rad] ? self.send(self.class.kingpin_args[:methods][:lat]).to_f * 180.0 / Math::PI : self.send(self.class.kingpin_args[:methods][:lat])
|
76
|
+
else
|
77
|
+
return self.send(self.class.kingpin_args[:methods][:lat])
|
78
|
+
end
|
79
|
+
end
|
80
|
+
end
|
81
|
+
|
82
|
+
# automatically adds a pin for self in case autopin option was set to true for self's AR model
|
83
|
+
def autopin
|
84
|
+
self.add_pin
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
###
|
90
|
+
# PinClassMethods - provides models new class methods
|
91
|
+
###
|
92
|
+
|
93
|
+
module KingpinClassMethods
|
94
|
+
|
95
|
+
def kingpin_args=(args)
|
96
|
+
@@kingpin_args = args
|
97
|
+
end
|
98
|
+
|
99
|
+
def kingpin_args
|
100
|
+
@@kingpin_args.first
|
101
|
+
end
|
102
|
+
|
103
|
+
end
|
data/lib/pin_caster.rb
ADDED
@@ -0,0 +1,89 @@
|
|
1
|
+
require 'json'
|
2
|
+
require 'pincaster_layer'
|
3
|
+
require 'pincaster_pin'
|
4
|
+
|
5
|
+
class Pincaster
|
6
|
+
|
7
|
+
@@http_client = HttpClient.new('http','localhost',4269)
|
8
|
+
|
9
|
+
# Pincaster server is still alive?
|
10
|
+
def self.is_alive?
|
11
|
+
@@http_client.send_request('GET', '/api/1.0/system/ping.json').code == "200" ? true : false rescue false
|
12
|
+
end
|
13
|
+
|
14
|
+
# shutdown Pincaster server immediately
|
15
|
+
def self.shutdown!
|
16
|
+
begin
|
17
|
+
@@http_client.send_request('POST', '/api/1.0/system/shutdown.json')
|
18
|
+
rescue Exception => e
|
19
|
+
case e.message
|
20
|
+
when "end of file reached"
|
21
|
+
return true
|
22
|
+
else
|
23
|
+
return false
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
# returns all known layers
|
29
|
+
def self.layers
|
30
|
+
JSON.parse(@@http_client.send_request('GET', '/api/1.0/layers/index.json').body)["layers"]
|
31
|
+
end
|
32
|
+
|
33
|
+
# returns true if Pincaster already has the given layer
|
34
|
+
def self.has_layer?(layer)
|
35
|
+
raise "Layer has to be a string" if not layer.is_a?(String)
|
36
|
+
self.layers.detect{|l| l["name"] == layer}.nil? ? false : true rescue false
|
37
|
+
end
|
38
|
+
|
39
|
+
# adds a new layer with name of the given string
|
40
|
+
def self.add_layer(layer)
|
41
|
+
raise "Layer has to be a string" if not layer.is_a?(String)
|
42
|
+
@@http_client.send_request('POST', "/api/1.0/layers/#{layer}.json").code == "200" ? true : false rescue false
|
43
|
+
end
|
44
|
+
|
45
|
+
# deletes the layer with the given name
|
46
|
+
def self.delete_layer!(layer)
|
47
|
+
raise "Layer has to be a string" if not layer.is_a?(String)
|
48
|
+
@@http_client.send_request('DELETE', "/api/1.0/layers/#{layer}.json").code == "200" ? true : false rescue false
|
49
|
+
end
|
50
|
+
|
51
|
+
# return a layer object for the layer that was searched for
|
52
|
+
def self.layer(layer)
|
53
|
+
raise "Layer has to be a string" if not layer.is_a?(String)
|
54
|
+
PincasterLayer.new(self.layers.select{|l| l["name"] == layer})
|
55
|
+
end
|
56
|
+
|
57
|
+
# adds a new record as well as creates a layer for it if the latter does not exist already
|
58
|
+
def self.add_record(record)
|
59
|
+
raise "Can't add a record without geocoordinates lng, lat" if record.pin_lng.nil? or record.pin_lat.nil?
|
60
|
+
Pincaster.add_layer(record.class.to_s) if not Pincaster.has_layer?(record.class.to_s)
|
61
|
+
@@http_client.send_request('PUT',
|
62
|
+
"/api/1.0/records/#{record.class.to_s}/#{record.id}.json",
|
63
|
+
nil,
|
64
|
+
nil,
|
65
|
+
{:_loc => "#{record.pin_lat},#{record.pin_lng}"}).code == "200" ? true : false
|
66
|
+
end
|
67
|
+
|
68
|
+
# returns a pin object for the given ActiveRecord object
|
69
|
+
def self.get_record(record)
|
70
|
+
PincasterPin.new(JSON.parse(@@http_client.send_request('GET', "/api/1.0/records/#{record.class.to_s}/#{record.id}.json").body)) rescue nil
|
71
|
+
end
|
72
|
+
|
73
|
+
# deletes the Pincaster record for the given ActiveRecord object
|
74
|
+
def self.delete_record(record)
|
75
|
+
@@http_client.send_request('DELETE', "/api/1.0/records/#{record.class.to_s}/#{record.id}.json").code == "200" ? true : false
|
76
|
+
end
|
77
|
+
|
78
|
+
# returns all pins nearby given record, maximum radius meters away, returns limit number of pins
|
79
|
+
def self.nearby(record, radius, limit)
|
80
|
+
limit ||= 2000
|
81
|
+
raise "Given #{record.class.to_s} has not lng or lat." if record.pin_lng.nil? or record.pin_lat.nil?
|
82
|
+
@@http_client.send_request('GET',
|
83
|
+
"/api/1.0/search/#{record.class.to_s}/nearby/#{record.pin_lat.to_s},#{record.pin_lng.to_s}.json",
|
84
|
+
nil,
|
85
|
+
nil,
|
86
|
+
{:radius => radius.to_s, :limit => limit}).body
|
87
|
+
end
|
88
|
+
|
89
|
+
end
|
data/lib/pincaster.rb
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
Dir[File.dirname(__FILE__) + "/*.rb"].each { |file| require file }
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'pincaster'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
metadata
ADDED
@@ -0,0 +1,146 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: kingpin
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 11
|
5
|
+
prerelease: false
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 5
|
9
|
+
- 0
|
10
|
+
version: 0.5.0
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Jan Roesner
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-11 00:00:00 +01:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
type: :development
|
23
|
+
prerelease: false
|
24
|
+
name: rspec
|
25
|
+
version_requirements: &id001 !ruby/object:Gem::Requirement
|
26
|
+
none: false
|
27
|
+
requirements:
|
28
|
+
- - ~>
|
29
|
+
- !ruby/object:Gem::Version
|
30
|
+
hash: 3
|
31
|
+
segments:
|
32
|
+
- 2
|
33
|
+
- 3
|
34
|
+
- 0
|
35
|
+
version: 2.3.0
|
36
|
+
requirement: *id001
|
37
|
+
- !ruby/object:Gem::Dependency
|
38
|
+
type: :development
|
39
|
+
prerelease: false
|
40
|
+
name: bundler
|
41
|
+
version_requirements: &id002 !ruby/object:Gem::Requirement
|
42
|
+
none: false
|
43
|
+
requirements:
|
44
|
+
- - ~>
|
45
|
+
- !ruby/object:Gem::Version
|
46
|
+
hash: 23
|
47
|
+
segments:
|
48
|
+
- 1
|
49
|
+
- 0
|
50
|
+
- 0
|
51
|
+
version: 1.0.0
|
52
|
+
requirement: *id002
|
53
|
+
- !ruby/object:Gem::Dependency
|
54
|
+
type: :development
|
55
|
+
prerelease: false
|
56
|
+
name: jeweler
|
57
|
+
version_requirements: &id003 !ruby/object:Gem::Requirement
|
58
|
+
none: false
|
59
|
+
requirements:
|
60
|
+
- - ~>
|
61
|
+
- !ruby/object:Gem::Version
|
62
|
+
hash: 7
|
63
|
+
segments:
|
64
|
+
- 1
|
65
|
+
- 5
|
66
|
+
- 2
|
67
|
+
version: 1.5.2
|
68
|
+
requirement: *id003
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
type: :development
|
71
|
+
prerelease: false
|
72
|
+
name: rcov
|
73
|
+
version_requirements: &id004 !ruby/object:Gem::Requirement
|
74
|
+
none: false
|
75
|
+
requirements:
|
76
|
+
- - ">="
|
77
|
+
- !ruby/object:Gem::Version
|
78
|
+
hash: 3
|
79
|
+
segments:
|
80
|
+
- 0
|
81
|
+
version: "0"
|
82
|
+
requirement: *id004
|
83
|
+
description: Kingpin extends every ActiveRecord model to become a Pincaster pin automatically. Thus the model automatically creates a Pincaster pin everytime it is saved. Kingpin afterwards provides methods at class and instance level that make geolocation easy and thanks to Pincaster amazingly fast.
|
84
|
+
email: jan@roesner.it
|
85
|
+
executables: []
|
86
|
+
|
87
|
+
extensions: []
|
88
|
+
|
89
|
+
extra_rdoc_files:
|
90
|
+
- LICENSE.txt
|
91
|
+
- README.rdoc
|
92
|
+
files:
|
93
|
+
- .document
|
94
|
+
- .rspec
|
95
|
+
- Gemfile
|
96
|
+
- Gemfile.lock
|
97
|
+
- LICENSE.txt
|
98
|
+
- README.rdoc
|
99
|
+
- Rakefile
|
100
|
+
- VERSION
|
101
|
+
- kingpin.gemspec
|
102
|
+
- lib/http_client.rb
|
103
|
+
- lib/kingpin.rb
|
104
|
+
- lib/pin_caster.rb
|
105
|
+
- lib/pincaster.rb
|
106
|
+
- lib/pincaster_layer.rb
|
107
|
+
- lib/pincaster_pin.rb
|
108
|
+
- spec/pincaster_spec.rb
|
109
|
+
- spec/spec_helper.rb
|
110
|
+
has_rdoc: true
|
111
|
+
homepage: http://railspotting.de
|
112
|
+
licenses:
|
113
|
+
- MIT
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
|
117
|
+
require_paths:
|
118
|
+
- lib
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
none: false
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
hash: 3
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
version: "0"
|
128
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
129
|
+
none: false
|
130
|
+
requirements:
|
131
|
+
- - ">="
|
132
|
+
- !ruby/object:Gem::Version
|
133
|
+
hash: 3
|
134
|
+
segments:
|
135
|
+
- 0
|
136
|
+
version: "0"
|
137
|
+
requirements: []
|
138
|
+
|
139
|
+
rubyforge_project:
|
140
|
+
rubygems_version: 1.3.7
|
141
|
+
signing_key:
|
142
|
+
specification_version: 3
|
143
|
+
summary: Kingpin makes your ActiveRecord model a Pincaster pin and thus geosearcheable. Fast!
|
144
|
+
test_files:
|
145
|
+
- spec/pincaster_spec.rb
|
146
|
+
- spec/spec_helper.rb
|