gcoder 0.12.0 → 0.12.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile +4 -0
- data/README.md +55 -47
- data/Rakefile +6 -42
- data/gcoder.gemspec +21 -18
- data/lib/gcoder/version.rb +1 -1
- metadata +45 -15
- data/Gemfile.lock +0 -20
data/.gitignore
CHANGED
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -4,14 +4,16 @@ GCoder geocodes stuff using the Google Geocoding API (V3) and caches the
|
|
4
4
|
results somewhere, if you want. _(Need something more bulldozer-like? Check out
|
5
5
|
[Geokit](http://github.com/andre/geokit-gem).)_
|
6
6
|
|
7
|
-
|
7
|
+
```ruby
|
8
|
+
# Bon Usage
|
8
9
|
|
9
|
-
|
10
|
+
require 'gcoder'
|
10
11
|
|
11
|
-
|
12
|
+
G = GCoder.connect(:storage => :heap)
|
12
13
|
|
13
|
-
|
14
|
-
|
14
|
+
G['dundas and sorauren', :region => :ca] # ... it geocodes!
|
15
|
+
G[[41.87, -74.16]] # ... and reverse-geocodes!
|
16
|
+
```
|
15
17
|
|
16
18
|
The returned value is the 'results' portion of the Google Geocoding API
|
17
19
|
[response](http://code.google.com/apis/maps/documentation/geocoding/#JSON).
|
@@ -43,7 +45,9 @@ of two latitude / longitude pairs. The first describes the Northeast corner of
|
|
43
45
|
the box and the second describes the Southwest corner of the box. Here is an
|
44
46
|
example input:
|
45
47
|
|
46
|
-
|
48
|
+
```ruby
|
49
|
+
[[50.09, -94.88], [41.87, -74.16]]
|
50
|
+
```
|
47
51
|
|
48
52
|
More info [here](http://code.google.com/apis/maps/documentation/geocoding/#Viewports).
|
49
53
|
|
@@ -102,53 +106,57 @@ Making your own adapter is pretty easy. Your adapter needs to respond to four
|
|
102
106
|
instance methods: `connect`, `set`, `get`, and `clear`. Let's make an adapter
|
103
107
|
for Sequel.
|
104
108
|
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
118
|
-
|
119
|
-
end
|
120
|
-
|
121
|
-
def get(key)
|
122
|
-
if (row = table.filter(:id => nkey(key)).first)
|
123
|
-
row[:value]
|
124
|
-
else
|
125
|
-
nil
|
126
|
-
end
|
127
|
-
end
|
128
|
-
|
129
|
-
def clear
|
130
|
-
table.delete_all
|
131
|
-
end
|
132
|
-
|
133
|
-
private
|
134
|
-
|
135
|
-
def table
|
136
|
-
@db[@table_name]
|
137
|
-
end
|
109
|
+
```ruby
|
110
|
+
class SequelAdapter < GCoder::Storage::Adapter
|
111
|
+
def connect
|
112
|
+
@db = Sequel.connect(config[:connection])
|
113
|
+
@table_name = (config[:table_name] || :gcoder_results)
|
114
|
+
end
|
115
|
+
|
116
|
+
# The methods `nkey` and `nval` are used to "normalize" keys and values,
|
117
|
+
# respectively. You are encouraged to use them.
|
118
|
+
def set(key, value)
|
119
|
+
if get(key)
|
120
|
+
table.filter(:id => nkey(key)).update(:value => nval(value))
|
121
|
+
else
|
122
|
+
table.insert(:id => nkey(key), :value => nval(value))
|
138
123
|
end
|
124
|
+
end
|
139
125
|
|
140
|
-
|
126
|
+
def get(key)
|
127
|
+
if (row = table.filter(:id => nkey(key)).first)
|
128
|
+
row[:value]
|
129
|
+
else
|
130
|
+
nil
|
131
|
+
end
|
132
|
+
end
|
133
|
+
|
134
|
+
def clear
|
135
|
+
table.delete_all
|
136
|
+
end
|
137
|
+
|
138
|
+
private
|
139
|
+
|
140
|
+
def table
|
141
|
+
@db[@table_name]
|
142
|
+
end
|
143
|
+
end
|
144
|
+
|
145
|
+
GCoder::Storage.register(:sequel, SequelAdapter)
|
146
|
+
```
|
141
147
|
|
142
148
|
Now we can use our adapter as a caching layer by specifying it like this:
|
143
149
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
149
|
-
|
150
|
+
```ruby
|
151
|
+
G = GCoder.connect \
|
152
|
+
:storage => :sequel,
|
153
|
+
:storage_config => {
|
154
|
+
:connection => 'sqlite://geo.db',
|
155
|
+
:table_name => :locations
|
156
|
+
}
|
157
|
+
```
|
150
158
|
|
151
|
-
##
|
159
|
+
## Contributors
|
152
160
|
|
153
161
|
* Carsten Nielsen
|
154
162
|
* Christos Pappas (Added support for Google Maps API Premier and Rails.cache
|
data/Rakefile
CHANGED
@@ -1,48 +1,12 @@
|
|
1
|
-
require '
|
2
|
-
require '
|
3
|
-
require 'rake
|
4
|
-
|
5
|
-
def gemspec
|
6
|
-
@gemspec ||= begin
|
7
|
-
Gem::Specification.load(File.expand_path('gcoder.gemspec'))
|
8
|
-
end
|
9
|
-
end
|
10
|
-
|
11
|
-
task :default => :spec
|
12
|
-
|
13
|
-
desc 'Start an irb console'
|
14
|
-
task :console do
|
15
|
-
system 'irb -I lib -r gcoder'
|
16
|
-
end
|
17
|
-
|
18
|
-
desc 'Validates the gemspec'
|
19
|
-
task :gemspec do
|
20
|
-
gemspec.validate
|
21
|
-
end
|
22
|
-
|
23
|
-
desc 'Displays the current version'
|
24
|
-
task :version do
|
25
|
-
puts "Current version: #{gemspec.version}"
|
26
|
-
end
|
27
|
-
|
28
|
-
desc 'Installs the gem locally'
|
29
|
-
task :install => :package do
|
30
|
-
sh "gem install pkg/#{gemspec.name}-#{gemspec.version}"
|
31
|
-
end
|
32
|
-
|
33
|
-
desc 'Release the gem'
|
34
|
-
task :release => :package do
|
35
|
-
sh "gem push pkg/#{gemspec.name}-#{gemspec.version}.gem"
|
36
|
-
end
|
37
|
-
|
38
|
-
Gem::PackageTask.new(gemspec) do |pkg|
|
39
|
-
pkg.gem_spec = gemspec
|
40
|
-
end
|
41
|
-
task :gem => :gemspec
|
42
|
-
task :package => :gemspec
|
1
|
+
require 'bundler/setup'
|
2
|
+
require 'bundler/gem_tasks'
|
3
|
+
require 'rake'
|
43
4
|
|
5
|
+
require 'rake/testtask'
|
44
6
|
Rake::TestTask.new(:spec) do |t|
|
45
7
|
t.libs += %w[gcoder spec]
|
46
8
|
t.test_files = FileList['spec/**/*.rb']
|
47
9
|
t.verbose = true
|
48
10
|
end
|
11
|
+
|
12
|
+
task :default => :spec
|
data/gcoder.gemspec
CHANGED
@@ -1,24 +1,27 @@
|
|
1
|
-
|
2
|
-
require File.expand_path("../lib/gcoder/version", __FILE__)
|
1
|
+
require File.expand_path('../lib/gcoder/version', __FILE__)
|
3
2
|
|
4
3
|
Gem::Specification.new do |s|
|
5
|
-
s.name
|
6
|
-
s.version
|
7
|
-
s.platform
|
8
|
-
s.
|
9
|
-
s.
|
10
|
-
s.
|
11
|
-
s.
|
12
|
-
s.
|
13
|
-
|
14
|
-
s.required_rubygems_version = '>= 1.8.5'
|
4
|
+
s.name = 'gcoder'
|
5
|
+
s.version = GCoder::VERSION
|
6
|
+
s.platform = Gem::Platform::RUBY
|
7
|
+
s.date = Date.today.strftime('%F')
|
8
|
+
s.homepage = 'http://github.com/heycarsten/gcoder'
|
9
|
+
s.authors = ['Carsten Nielsen', 'Christos Pappas']
|
10
|
+
s.email = 'heycarsten@gmail.com'
|
11
|
+
s.summary = 'A nice library for geocoding stuff with Google Maps API V3'
|
15
12
|
s.rubyforge_project = 'gcoder'
|
13
|
+
s.files = `git ls-files`.split(?\n)
|
14
|
+
s.test_files = `git ls-files -- {test,spec}/*`.split(?\n)
|
15
|
+
s.require_paths = ['lib']
|
16
16
|
|
17
|
-
s.add_dependency
|
18
|
-
s.add_dependency
|
19
|
-
s.add_dependency
|
17
|
+
s.add_dependency 'hashie'
|
18
|
+
s.add_dependency 'yajl-ruby'
|
19
|
+
s.add_dependency 'ruby-hmac'
|
20
|
+
s.add_development_dependency 'bundler', '>= 1.0.14'
|
21
|
+
s.add_development_dependency 'redis'
|
20
22
|
|
21
|
-
s.
|
22
|
-
|
23
|
-
|
23
|
+
s.description = <<-END
|
24
|
+
Uses Google Maps Geocoding API (V3) to geocode stuff and optionally caches the
|
25
|
+
results somewhere.
|
26
|
+
END
|
24
27
|
end
|
data/lib/gcoder/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: gcoder
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.12.
|
4
|
+
version: 0.12.1
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -10,11 +10,11 @@ authors:
|
|
10
10
|
autorequire:
|
11
11
|
bindir: bin
|
12
12
|
cert_chain: []
|
13
|
-
date: 2011-
|
13
|
+
date: 2011-10-04 00:00:00.000000000Z
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
16
16
|
name: hashie
|
17
|
-
requirement: &
|
17
|
+
requirement: &70147457520440 !ruby/object:Gem::Requirement
|
18
18
|
none: false
|
19
19
|
requirements:
|
20
20
|
- - ! '>='
|
@@ -22,10 +22,10 @@ dependencies:
|
|
22
22
|
version: '0'
|
23
23
|
type: :runtime
|
24
24
|
prerelease: false
|
25
|
-
version_requirements: *
|
25
|
+
version_requirements: *70147457520440
|
26
26
|
- !ruby/object:Gem::Dependency
|
27
27
|
name: yajl-ruby
|
28
|
-
requirement: &
|
28
|
+
requirement: &70147457519540 !ruby/object:Gem::Requirement
|
29
29
|
none: false
|
30
30
|
requirements:
|
31
31
|
- - ! '>='
|
@@ -33,10 +33,10 @@ dependencies:
|
|
33
33
|
version: '0'
|
34
34
|
type: :runtime
|
35
35
|
prerelease: false
|
36
|
-
version_requirements: *
|
36
|
+
version_requirements: *70147457519540
|
37
37
|
- !ruby/object:Gem::Dependency
|
38
38
|
name: ruby-hmac
|
39
|
-
requirement: &
|
39
|
+
requirement: &70147457518700 !ruby/object:Gem::Requirement
|
40
40
|
none: false
|
41
41
|
requirements:
|
42
42
|
- - ! '>='
|
@@ -44,18 +44,42 @@ dependencies:
|
|
44
44
|
version: '0'
|
45
45
|
type: :runtime
|
46
46
|
prerelease: false
|
47
|
-
version_requirements: *
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
47
|
+
version_requirements: *70147457518700
|
48
|
+
- !ruby/object:Gem::Dependency
|
49
|
+
name: bundler
|
50
|
+
requirement: &70147457455060 !ruby/object:Gem::Requirement
|
51
|
+
none: false
|
52
|
+
requirements:
|
53
|
+
- - ! '>='
|
54
|
+
- !ruby/object:Gem::Version
|
55
|
+
version: 1.0.14
|
56
|
+
type: :development
|
57
|
+
prerelease: false
|
58
|
+
version_requirements: *70147457455060
|
59
|
+
- !ruby/object:Gem::Dependency
|
60
|
+
name: redis
|
61
|
+
requirement: &70147457454080 !ruby/object:Gem::Requirement
|
62
|
+
none: false
|
63
|
+
requirements:
|
64
|
+
- - ! '>='
|
65
|
+
- !ruby/object:Gem::Version
|
66
|
+
version: '0'
|
67
|
+
type: :development
|
68
|
+
prerelease: false
|
69
|
+
version_requirements: *70147457454080
|
70
|
+
description: ! 'Uses Google Maps Geocoding API (V3) to geocode stuff and optionally
|
71
|
+
caches the
|
72
|
+
|
73
|
+
results somewhere.
|
74
|
+
|
75
|
+
'
|
76
|
+
email: heycarsten@gmail.com
|
52
77
|
executables: []
|
53
78
|
extensions: []
|
54
79
|
extra_rdoc_files: []
|
55
80
|
files:
|
56
81
|
- .gitignore
|
57
82
|
- Gemfile
|
58
|
-
- Gemfile.lock
|
59
83
|
- LICENSE
|
60
84
|
- README.md
|
61
85
|
- Rakefile
|
@@ -89,15 +113,21 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
89
113
|
- - ! '>='
|
90
114
|
- !ruby/object:Gem::Version
|
91
115
|
version: '0'
|
116
|
+
segments:
|
117
|
+
- 0
|
118
|
+
hash: 3722071626544291887
|
92
119
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
120
|
none: false
|
94
121
|
requirements:
|
95
122
|
- - ! '>='
|
96
123
|
- !ruby/object:Gem::Version
|
97
|
-
version:
|
124
|
+
version: '0'
|
125
|
+
segments:
|
126
|
+
- 0
|
127
|
+
hash: 3722071626544291887
|
98
128
|
requirements: []
|
99
129
|
rubyforge_project: gcoder
|
100
|
-
rubygems_version: 1.8.
|
130
|
+
rubygems_version: 1.8.6
|
101
131
|
signing_key:
|
102
132
|
specification_version: 3
|
103
133
|
summary: A nice library for geocoding stuff with Google Maps API V3
|
data/Gemfile.lock
DELETED