geong 0.0.1
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.
- checksums.yaml +7 -0
- data/.gitignore +15 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +22 -0
- data/README.md +131 -0
- data/Rakefile +24 -0
- data/bin/geong_server +6 -0
- data/generated/geong/geocoder/geocoder_constants.rb +13 -0
- data/generated/geong/geocoder/geocoder_service.rb +160 -0
- data/generated/geong/geocoder/geocoder_types.rb +72 -0
- data/geong.gemspec +26 -0
- data/lib/geong/cache.rb +29 -0
- data/lib/geong/client.rb +49 -0
- data/lib/geong/geocoder/geocoder_handler.rb +30 -0
- data/lib/geong/geocoder.rb +7 -0
- data/lib/geong/server/configuration.rb +90 -0
- data/lib/geong/server.rb +44 -0
- data/lib/geong/version.rb +3 -0
- data/lib/geong.rb +7 -0
- data/thrift/geocoder.thrift +29 -0
- metadata +135 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: a989717d4c54d884f4e084565f43b1a0de2cfe71
|
4
|
+
data.tar.gz: b10bb4ce8f9b84b17d4aa8a39c4e3cf5c6587f01
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: c3756653b390eb2022ce427a0f159ca69be53c408a53a86eee2165a2122e9af691e58dbbf773faaae52126816fcac3ba1a74d7a4beeb0383b6e471c933d46169
|
7
|
+
data.tar.gz: 5660773081bad10fadf8361bf0e9d169ae75aee0f158c0d3ccafb67847d4fe297053597bd09fd17781dd32af2b51539d01ecf5d7932a50e430eb3a42631c3cb1
|
data/.gitignore
ADDED
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
Copyright (c) 2014 TODO: Write your name
|
2
|
+
|
3
|
+
MIT License
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining
|
6
|
+
a copy of this software and associated documentation files (the
|
7
|
+
"Software"), to deal in the Software without restriction, including
|
8
|
+
without limitation the rights to use, copy, modify, merge, publish,
|
9
|
+
distribute, sublicense, and/or sell copies of the Software, and to
|
10
|
+
permit persons to whom the Software is furnished to do so, subject to
|
11
|
+
the following conditions:
|
12
|
+
|
13
|
+
The above copyright notice and this permission notice shall be
|
14
|
+
included in all copies or substantial portions of the Software.
|
15
|
+
|
16
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
|
17
|
+
EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
|
18
|
+
MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
|
19
|
+
NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
|
20
|
+
LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
|
21
|
+
OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
|
22
|
+
WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,131 @@
|
|
1
|
+
# Geong
|
2
|
+
|
3
|
+
Thrift based Geocoding RPC. using the ruby [Geocoder](https://github.com/alexreisner/geocoder "Geocoder") library.
|
4
|
+
|
5
|
+
## Installation
|
6
|
+
|
7
|
+
Add this line to your application's Gemfile:
|
8
|
+
|
9
|
+
```ruby
|
10
|
+
gem 'geong'
|
11
|
+
```
|
12
|
+
|
13
|
+
And then execute:
|
14
|
+
|
15
|
+
$ bundle
|
16
|
+
|
17
|
+
Or install it yourself as:
|
18
|
+
|
19
|
+
$ gem install geong
|
20
|
+
|
21
|
+
## Usage
|
22
|
+
|
23
|
+
### Run Server
|
24
|
+
|
25
|
+
$ geong_server
|
26
|
+
|
27
|
+
### Ruby Client
|
28
|
+
|
29
|
+
require "geong"
|
30
|
+
client = Geong::Client.new(host: "127.0.0.1")
|
31
|
+
client.open
|
32
|
+
|
33
|
+
client.coordinates "toko-tower"
|
34
|
+
=> <Geong::Geocoder::Location latitude:35.6585805, longitude:139.7454329>
|
35
|
+
|
36
|
+
client.address("133.11.0.1")
|
37
|
+
=> "Tokyo, 13 , Japan"
|
38
|
+
|
39
|
+
## Configure
|
40
|
+
|
41
|
+
You can give the configuration script by using the -c option.
|
42
|
+
|
43
|
+
$ geong_server -p 19090 -c config.rb
|
44
|
+
|
45
|
+
### Thrift Configuration
|
46
|
+
|
47
|
+
If you want to change the server settings, please use the Geong::Server.configure block in configuration script.
|
48
|
+
Configuration DSL supported following methods.
|
49
|
+
|
50
|
+
* logger(default: Logger.new(STDERR)) This option is available only if the default server.
|
51
|
+
* port(default: 9090) This option is available only if the default transport.
|
52
|
+
* num_threads(default: 20) This option is available only if the default transport.
|
53
|
+
* transport(default: Thrift::ServerSocket)
|
54
|
+
* transport_factory(default: Thrift::FramedTransportFactory)
|
55
|
+
* protocol_factory(default: nil)
|
56
|
+
* server(default: Thrift::NonblockingServer)
|
57
|
+
* processor(readOnly) create geong processor
|
58
|
+
|
59
|
+
### Example. Using ThinHTTPServer
|
60
|
+
|
61
|
+
# server(config.rb)
|
62
|
+
require "thrift/server/thin_http_server"
|
63
|
+
|
64
|
+
Geong::Server.configure do
|
65
|
+
server Thrift::ThinHTTPServer.new(processor, {port: 8080})
|
66
|
+
end
|
67
|
+
|
68
|
+
|
69
|
+
# client
|
70
|
+
require "geong"
|
71
|
+
options = {transport: Thrift::HTTPClientTransport.new("http://127.0.0.1:8080")}
|
72
|
+
|
73
|
+
client = Geong::Client.new(options)
|
74
|
+
client.open
|
75
|
+
|
76
|
+
client.coordinates("TokyoTower")
|
77
|
+
|
78
|
+
|
79
|
+
### Geocoder Configuration
|
80
|
+
|
81
|
+
you can customize the Geocoder in the config file.
|
82
|
+
use Geocoder.configure method.
|
83
|
+
|
84
|
+
# config.rb
|
85
|
+
Geocoder.configure(
|
86
|
+
|
87
|
+
# geocoding service (see below for supported options):
|
88
|
+
:lookup => :yandex,
|
89
|
+
|
90
|
+
# IP address geocoding service (see below for supported options):
|
91
|
+
:ip_lookup => :maxmind,
|
92
|
+
|
93
|
+
# to use an API key:
|
94
|
+
:api_key => "...",
|
95
|
+
|
96
|
+
# geocoding service request timeout, in seconds (default 3):
|
97
|
+
:timeout => 5,
|
98
|
+
|
99
|
+
# set default units to kilometers:
|
100
|
+
:units => :km,
|
101
|
+
|
102
|
+
# caching (see below for details):
|
103
|
+
:cache => Redis.new,
|
104
|
+
:cache_prefix => "..."
|
105
|
+
|
106
|
+
)
|
107
|
+
|
108
|
+
If have you using Redis, if you want to have a expiration in the cache, please set as follows.
|
109
|
+
Geong::Cache.redis has been added two options that default_ttl_seconds and default_ttl_miliseconds.
|
110
|
+
Other options are the same as Redis.new.
|
111
|
+
|
112
|
+
# config.rb
|
113
|
+
Geocoder.configure(
|
114
|
+
cache: Geong::Cache.redis(default_ttl_seconds: 100)
|
115
|
+
)
|
116
|
+
|
117
|
+
|
118
|
+
## Other Languages
|
119
|
+
|
120
|
+
Thrift file is located in the following path.
|
121
|
+
Please create a binding from below if you want to use other languages.
|
122
|
+
|
123
|
+
thrift/geocoder.thrift
|
124
|
+
|
125
|
+
## Contributing
|
126
|
+
|
127
|
+
1. Fork it ( https://github.com/[my-github-username]/geong/fork )
|
128
|
+
2. Create your feature branch (`git checkout -b my-new-feature`)
|
129
|
+
3. Commit your changes (`git commit -am 'Add some feature'`)
|
130
|
+
4. Push to the branch (`git push origin my-new-feature`)
|
131
|
+
5. Create a new Pull Request
|
data/Rakefile
ADDED
@@ -0,0 +1,24 @@
|
|
1
|
+
require "bundler/gem_tasks"
|
2
|
+
require 'tempfile'
|
3
|
+
require 'shellwords'
|
4
|
+
|
5
|
+
namespace :geong do
|
6
|
+
task :generate_thrift do
|
7
|
+
output_dir = File.expand_path('../generated/geong/geocoder/', __FILE__)
|
8
|
+
thrift_file = File.expand_path('../thrift/geocoder.thrift', __FILE__)
|
9
|
+
command = "thrift --gen rb -out #{Shellwords.escape(output_dir)} #{Shellwords.escape(thrift_file)}"
|
10
|
+
$stderr.puts(command)
|
11
|
+
unless system(command)
|
12
|
+
abort "thrift command error!"
|
13
|
+
end
|
14
|
+
Dir.glob(output_dir + '/*.rb').each do |file|
|
15
|
+
file_body = nil
|
16
|
+
File.open(file, 'r') do |in_f|
|
17
|
+
file_body = in_f.read
|
18
|
+
end
|
19
|
+
File.open(file, 'w') do |out_f|
|
20
|
+
out_f << file_body.gsub("require 'geocoder_", "require 'geong/geocoder/geocoder_")
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
data/bin/geong_server
ADDED
@@ -0,0 +1,160 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.1)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
require 'geong/geocoder/geocoder_types'
|
9
|
+
|
10
|
+
module Geong
|
11
|
+
module Geocoder
|
12
|
+
module GeocoderService
|
13
|
+
class Client
|
14
|
+
include ::Thrift::Client
|
15
|
+
|
16
|
+
def coordinates(address)
|
17
|
+
send_coordinates(address)
|
18
|
+
return recv_coordinates()
|
19
|
+
end
|
20
|
+
|
21
|
+
def send_coordinates(address)
|
22
|
+
send_message('coordinates', Coordinates_args, :address => address)
|
23
|
+
end
|
24
|
+
|
25
|
+
def recv_coordinates()
|
26
|
+
result = receive_message(Coordinates_result)
|
27
|
+
return result.success unless result.success.nil?
|
28
|
+
raise result.error unless result.error.nil?
|
29
|
+
raise result.error2 unless result.error2.nil?
|
30
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'coordinates failed: unknown result')
|
31
|
+
end
|
32
|
+
|
33
|
+
def address(query)
|
34
|
+
send_address(query)
|
35
|
+
return recv_address()
|
36
|
+
end
|
37
|
+
|
38
|
+
def send_address(query)
|
39
|
+
send_message('address', Address_args, :query => query)
|
40
|
+
end
|
41
|
+
|
42
|
+
def recv_address()
|
43
|
+
result = receive_message(Address_result)
|
44
|
+
return result.success unless result.success.nil?
|
45
|
+
raise result.error unless result.error.nil?
|
46
|
+
raise result.error2 unless result.error2.nil?
|
47
|
+
raise ::Thrift::ApplicationException.new(::Thrift::ApplicationException::MISSING_RESULT, 'address failed: unknown result')
|
48
|
+
end
|
49
|
+
|
50
|
+
end
|
51
|
+
|
52
|
+
class Processor
|
53
|
+
include ::Thrift::Processor
|
54
|
+
|
55
|
+
def process_coordinates(seqid, iprot, oprot)
|
56
|
+
args = read_args(iprot, Coordinates_args)
|
57
|
+
result = Coordinates_result.new()
|
58
|
+
begin
|
59
|
+
result.success = @handler.coordinates(args.address)
|
60
|
+
rescue ::Geong::Geocoder::NoResultException => error
|
61
|
+
result.error = error
|
62
|
+
rescue ::Geong::Geocoder::TimeoutException => error2
|
63
|
+
result.error2 = error2
|
64
|
+
end
|
65
|
+
write_result(result, oprot, 'coordinates', seqid)
|
66
|
+
end
|
67
|
+
|
68
|
+
def process_address(seqid, iprot, oprot)
|
69
|
+
args = read_args(iprot, Address_args)
|
70
|
+
result = Address_result.new()
|
71
|
+
begin
|
72
|
+
result.success = @handler.address(args.query)
|
73
|
+
rescue ::Geong::Geocoder::NoResultException => error
|
74
|
+
result.error = error
|
75
|
+
rescue ::Geong::Geocoder::TimeoutException => error2
|
76
|
+
result.error2 = error2
|
77
|
+
end
|
78
|
+
write_result(result, oprot, 'address', seqid)
|
79
|
+
end
|
80
|
+
|
81
|
+
end
|
82
|
+
|
83
|
+
# HELPER FUNCTIONS AND STRUCTURES
|
84
|
+
|
85
|
+
class Coordinates_args
|
86
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
87
|
+
ADDRESS = 1
|
88
|
+
|
89
|
+
FIELDS = {
|
90
|
+
ADDRESS => {:type => ::Thrift::Types::STRING, :name => 'address'}
|
91
|
+
}
|
92
|
+
|
93
|
+
def struct_fields; FIELDS; end
|
94
|
+
|
95
|
+
def validate
|
96
|
+
end
|
97
|
+
|
98
|
+
::Thrift::Struct.generate_accessors self
|
99
|
+
end
|
100
|
+
|
101
|
+
class Coordinates_result
|
102
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
103
|
+
SUCCESS = 0
|
104
|
+
ERROR = 1
|
105
|
+
ERROR2 = 2
|
106
|
+
|
107
|
+
FIELDS = {
|
108
|
+
SUCCESS => {:type => ::Thrift::Types::STRUCT, :name => 'success', :class => ::Geong::Geocoder::Location},
|
109
|
+
ERROR => {:type => ::Thrift::Types::STRUCT, :name => 'error', :class => ::Geong::Geocoder::NoResultException},
|
110
|
+
ERROR2 => {:type => ::Thrift::Types::STRUCT, :name => 'error2', :class => ::Geong::Geocoder::TimeoutException}
|
111
|
+
}
|
112
|
+
|
113
|
+
def struct_fields; FIELDS; end
|
114
|
+
|
115
|
+
def validate
|
116
|
+
end
|
117
|
+
|
118
|
+
::Thrift::Struct.generate_accessors self
|
119
|
+
end
|
120
|
+
|
121
|
+
class Address_args
|
122
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
123
|
+
QUERY = 1
|
124
|
+
|
125
|
+
FIELDS = {
|
126
|
+
QUERY => {:type => ::Thrift::Types::STRING, :name => 'query'}
|
127
|
+
}
|
128
|
+
|
129
|
+
def struct_fields; FIELDS; end
|
130
|
+
|
131
|
+
def validate
|
132
|
+
end
|
133
|
+
|
134
|
+
::Thrift::Struct.generate_accessors self
|
135
|
+
end
|
136
|
+
|
137
|
+
class Address_result
|
138
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
139
|
+
SUCCESS = 0
|
140
|
+
ERROR = 1
|
141
|
+
ERROR2 = 2
|
142
|
+
|
143
|
+
FIELDS = {
|
144
|
+
SUCCESS => {:type => ::Thrift::Types::STRING, :name => 'success'},
|
145
|
+
ERROR => {:type => ::Thrift::Types::STRUCT, :name => 'error', :class => ::Geong::Geocoder::NoResultException},
|
146
|
+
ERROR2 => {:type => ::Thrift::Types::STRUCT, :name => 'error2', :class => ::Geong::Geocoder::TimeoutException}
|
147
|
+
}
|
148
|
+
|
149
|
+
def struct_fields; FIELDS; end
|
150
|
+
|
151
|
+
def validate
|
152
|
+
end
|
153
|
+
|
154
|
+
::Thrift::Struct.generate_accessors self
|
155
|
+
end
|
156
|
+
|
157
|
+
end
|
158
|
+
|
159
|
+
end
|
160
|
+
end
|
@@ -0,0 +1,72 @@
|
|
1
|
+
#
|
2
|
+
# Autogenerated by Thrift Compiler (0.9.1)
|
3
|
+
#
|
4
|
+
# DO NOT EDIT UNLESS YOU ARE SURE THAT YOU KNOW WHAT YOU ARE DOING
|
5
|
+
#
|
6
|
+
|
7
|
+
require 'thrift'
|
8
|
+
|
9
|
+
module Geong
|
10
|
+
module Geocoder
|
11
|
+
class Location
|
12
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
13
|
+
LATITUDE = 1
|
14
|
+
LONGITUDE = 2
|
15
|
+
|
16
|
+
FIELDS = {
|
17
|
+
LATITUDE => {:type => ::Thrift::Types::DOUBLE, :name => 'latitude'},
|
18
|
+
LONGITUDE => {:type => ::Thrift::Types::DOUBLE, :name => 'longitude'}
|
19
|
+
}
|
20
|
+
|
21
|
+
def struct_fields; FIELDS; end
|
22
|
+
|
23
|
+
def validate
|
24
|
+
end
|
25
|
+
|
26
|
+
::Thrift::Struct.generate_accessors self
|
27
|
+
end
|
28
|
+
|
29
|
+
class NoResultException < ::Thrift::Exception
|
30
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
31
|
+
def initialize(message=nil)
|
32
|
+
super()
|
33
|
+
self.message = message
|
34
|
+
end
|
35
|
+
|
36
|
+
MESSAGE = 1
|
37
|
+
|
38
|
+
FIELDS = {
|
39
|
+
MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
|
40
|
+
}
|
41
|
+
|
42
|
+
def struct_fields; FIELDS; end
|
43
|
+
|
44
|
+
def validate
|
45
|
+
end
|
46
|
+
|
47
|
+
::Thrift::Struct.generate_accessors self
|
48
|
+
end
|
49
|
+
|
50
|
+
class TimeoutException < ::Thrift::Exception
|
51
|
+
include ::Thrift::Struct, ::Thrift::Struct_Union
|
52
|
+
def initialize(message=nil)
|
53
|
+
super()
|
54
|
+
self.message = message
|
55
|
+
end
|
56
|
+
|
57
|
+
MESSAGE = 1
|
58
|
+
|
59
|
+
FIELDS = {
|
60
|
+
MESSAGE => {:type => ::Thrift::Types::STRING, :name => 'message'}
|
61
|
+
}
|
62
|
+
|
63
|
+
def struct_fields; FIELDS; end
|
64
|
+
|
65
|
+
def validate
|
66
|
+
end
|
67
|
+
|
68
|
+
::Thrift::Struct.generate_accessors self
|
69
|
+
end
|
70
|
+
|
71
|
+
end
|
72
|
+
end
|
data/geong.gemspec
ADDED
@@ -0,0 +1,26 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'geong/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "geong"
|
8
|
+
spec.version = Geong::VERSION
|
9
|
+
spec.authors = ["yuki teraoka"]
|
10
|
+
spec.email = ["teraoka.yuki@synergy101.jp"]
|
11
|
+
spec.summary = %q{Thrift based Geocoding RPC.}
|
12
|
+
spec.description = %q{Thrift based Geocoding RPC. using the ruby Geocoder library.}
|
13
|
+
spec.homepage = ""
|
14
|
+
spec.license = "MIT"
|
15
|
+
|
16
|
+
spec.files = `git ls-files -z`.split("\x0")
|
17
|
+
spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
|
18
|
+
spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
|
19
|
+
spec.require_paths = ["lib", "generated"]
|
20
|
+
|
21
|
+
spec.add_runtime_dependency "geocoder"
|
22
|
+
spec.add_runtime_dependency "thrift"
|
23
|
+
spec.add_development_dependency "redis"
|
24
|
+
spec.add_development_dependency "bundler", "~> 1.7"
|
25
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
26
|
+
end
|
data/lib/geong/cache.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
module Geong
|
3
|
+
module Cache
|
4
|
+
def self.redis(options = {})
|
5
|
+
require "redis"
|
6
|
+
redis = Redis.new(options)
|
7
|
+
if options[:default_ttl_seconds] or options[:default_ttl_milliseconds]
|
8
|
+
redis.singleton_class.prepend RedisDefaultTTL
|
9
|
+
redis.default_ttl_seconds = options[:default_ttl_seconds]
|
10
|
+
redis.default_ttl_milliseconds = options[:default_ttl_milliseconds]
|
11
|
+
end
|
12
|
+
redis
|
13
|
+
end
|
14
|
+
|
15
|
+
module RedisDefaultTTL
|
16
|
+
def default_ttl_seconds=(ttl_seconds)
|
17
|
+
@default_ttl_seconds = ttl_seconds
|
18
|
+
end
|
19
|
+
|
20
|
+
def default_ttl_milliseconds=(ttl_milliseconds)
|
21
|
+
@default_ttl_milliseconds = ttl_milliseconds
|
22
|
+
end
|
23
|
+
|
24
|
+
def []=(key, value)
|
25
|
+
set(key, value, {ex: @default_ttl_seconds, px: @default_ttl_milliseconds})
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
data/lib/geong/client.rb
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
require 'thrift'
|
2
|
+
|
3
|
+
module Geong
|
4
|
+
class Client
|
5
|
+
DEFAULT_HOST = '127.0.0.1'
|
6
|
+
DEFAULT_PORT = 9090
|
7
|
+
|
8
|
+
attr_reader :transport, :protocol
|
9
|
+
def initialize(options = {})
|
10
|
+
@transport = options[:transport] || self.class.default_transport(options)
|
11
|
+
@protocol = options[:protocol ] || self.class.default_protocol(@transport, options)
|
12
|
+
@client = Geong::Geocoder::GeocoderService::Client.new(@protocol)
|
13
|
+
end
|
14
|
+
|
15
|
+
def self.default_transport(options)
|
16
|
+
Thrift::FramedTransport.new(Thrift::Socket.new(options[:host] || DEFAULT_HOST, options[:port] || DEFAULT_PORT))
|
17
|
+
end
|
18
|
+
|
19
|
+
def self.default_protocol(transport, options)
|
20
|
+
Thrift::BinaryProtocol.new(transport)
|
21
|
+
end
|
22
|
+
|
23
|
+
def open
|
24
|
+
@transport.open
|
25
|
+
self
|
26
|
+
end
|
27
|
+
|
28
|
+
def open?
|
29
|
+
@transport.open?
|
30
|
+
end
|
31
|
+
|
32
|
+
def close
|
33
|
+
@transport.close
|
34
|
+
self
|
35
|
+
end
|
36
|
+
|
37
|
+
def closed?
|
38
|
+
@transport.closed?
|
39
|
+
end
|
40
|
+
|
41
|
+
def respond_to_missing?(method, include_private)
|
42
|
+
@client.respond_to?(method, include_private)
|
43
|
+
end
|
44
|
+
|
45
|
+
def method_missing(*args, &block)
|
46
|
+
@client.send(*args, &block)
|
47
|
+
end
|
48
|
+
end
|
49
|
+
end
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'geocoder'
|
2
|
+
|
3
|
+
module Geong
|
4
|
+
module Geocoder
|
5
|
+
class GeocoderHandler
|
6
|
+
def coordinates(address)
|
7
|
+
result = ::Geocoder.coordinates(address)
|
8
|
+
if result.nil?
|
9
|
+
raise NoResultException, "coordinates not found. address: #{address}"
|
10
|
+
end
|
11
|
+
location = Location.new
|
12
|
+
location.latitude = result[0]
|
13
|
+
location.longitude = result[1]
|
14
|
+
location
|
15
|
+
rescue TimeoutError => e
|
16
|
+
raise TimeoutException, e.message
|
17
|
+
end
|
18
|
+
|
19
|
+
def address(query)
|
20
|
+
result = ::Geocoder.address(query)
|
21
|
+
if result.nil?
|
22
|
+
raise NoResultException, "address not found. query: #{query}"
|
23
|
+
end
|
24
|
+
result
|
25
|
+
rescue TimeoutError => e
|
26
|
+
raise TimeoutException, e.message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
end
|
@@ -0,0 +1,90 @@
|
|
1
|
+
require 'geong/geocoder'
|
2
|
+
require 'logger'
|
3
|
+
require 'optparse'
|
4
|
+
|
5
|
+
module Geong
|
6
|
+
class Server
|
7
|
+
class Configuration
|
8
|
+
DEFAULT_PORT = 9090
|
9
|
+
DEFAULT_NUM_THREADS = 20
|
10
|
+
DEFAULT_LOGGER = Logger.new(STDERR)
|
11
|
+
DEFAULT_LOGGER.level = Logger::DEBUG
|
12
|
+
|
13
|
+
attr_writer :logger, :port, :num_threads, :transport, :transport_factory, :protocol_factory, :server
|
14
|
+
|
15
|
+
def configure(&block)
|
16
|
+
self.instance_exec(self, &block)
|
17
|
+
self
|
18
|
+
end
|
19
|
+
|
20
|
+
def processor
|
21
|
+
handler = Geocoder::GeocoderHandler.new()
|
22
|
+
Geocoder::GeocoderService::Processor.new(handler)
|
23
|
+
end
|
24
|
+
|
25
|
+
def port(port = nil)
|
26
|
+
self.port = port if port
|
27
|
+
get_port
|
28
|
+
end
|
29
|
+
|
30
|
+
def get_port
|
31
|
+
@port ||= DEFAULT_PORT
|
32
|
+
end
|
33
|
+
|
34
|
+
def num_threads(num_threads = nil)
|
35
|
+
self.num_threads = num_threads if num_threads
|
36
|
+
get_num_threads
|
37
|
+
end
|
38
|
+
|
39
|
+
def get_num_threads
|
40
|
+
@num_threads ||= DEFAULT_NUM_THREADS
|
41
|
+
end
|
42
|
+
|
43
|
+
def logger(logger = nil)
|
44
|
+
self.logger = logger if logger
|
45
|
+
get_logger
|
46
|
+
end
|
47
|
+
|
48
|
+
def get_logger
|
49
|
+
@logger ||= DEFAULT_LOGGER
|
50
|
+
end
|
51
|
+
|
52
|
+
def transport(transport = nil)
|
53
|
+
self.transport = transport if transport
|
54
|
+
get_transport
|
55
|
+
end
|
56
|
+
|
57
|
+
def get_transport
|
58
|
+
@transport ||= Thrift::ServerSocket.new(port)
|
59
|
+
end
|
60
|
+
|
61
|
+
def transport_factory(transport_factory = nil)
|
62
|
+
self.transport_factory = transport_factory if transport_factory
|
63
|
+
get_transport_factory ||= Thrift::FramedTransportFactory.new
|
64
|
+
end
|
65
|
+
|
66
|
+
def get_transport_factory
|
67
|
+
@transport_factory
|
68
|
+
end
|
69
|
+
|
70
|
+
def protocol_factory(protocol_factory = nil)
|
71
|
+
self.protocol_factory = protocol_factory if protocol_factory
|
72
|
+
get_protocol_factory
|
73
|
+
end
|
74
|
+
|
75
|
+
def get_protocol_factory
|
76
|
+
@protocol_factory
|
77
|
+
end
|
78
|
+
|
79
|
+
def server(server = nil)
|
80
|
+
self.server =server if server
|
81
|
+
get_server
|
82
|
+
end
|
83
|
+
|
84
|
+
def get_server
|
85
|
+
return @server if @server
|
86
|
+
@server ||= Thrift::NonblockingServer.new(processor, transport, transport_factory, protocol_factory, num_threads, logger)
|
87
|
+
end
|
88
|
+
end
|
89
|
+
end
|
90
|
+
end
|
data/lib/geong/server.rb
ADDED
@@ -0,0 +1,44 @@
|
|
1
|
+
require 'geong/geocoder'
|
2
|
+
require 'geong/server/configuration'
|
3
|
+
require 'logger'
|
4
|
+
require 'optparse'
|
5
|
+
|
6
|
+
module Geong
|
7
|
+
class Server
|
8
|
+
@@default_configuration = Configuration.new
|
9
|
+
|
10
|
+
def self.start(argv)
|
11
|
+
params = ARGV.getopts('', "port:#{Geong::Server::Configuration::DEFAULT_PORT}", 'daemon', 'config:')
|
12
|
+
|
13
|
+
@@default_configuration.port = params["port"] || DEFAULT_PORT
|
14
|
+
|
15
|
+
config_filepath = params["config"] ? File.expand_path(params["config"]) : null
|
16
|
+
|
17
|
+
if config_filepath
|
18
|
+
@@default_configuration.logger.info "Load config file. #{config_filepath}"
|
19
|
+
load config_filepath
|
20
|
+
end
|
21
|
+
|
22
|
+
if params["daemon"]
|
23
|
+
Process.daemon
|
24
|
+
end
|
25
|
+
|
26
|
+
new(@@default_configuration).serve
|
27
|
+
end
|
28
|
+
|
29
|
+
def self.configure(&block)
|
30
|
+
@@default_configuration.configure(&block)
|
31
|
+
end
|
32
|
+
|
33
|
+
def initialize(configuration)
|
34
|
+
@configuration = configuration
|
35
|
+
@logger = configuration.logger
|
36
|
+
@server = configuration.get_server
|
37
|
+
end
|
38
|
+
|
39
|
+
def serve
|
40
|
+
@logger.info "Starting the geong server..."
|
41
|
+
@server.serve()
|
42
|
+
end
|
43
|
+
end
|
44
|
+
end
|
data/lib/geong.rb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
|
2
|
+
namespace rb Geong.Geocoder
|
3
|
+
namespace java com.tera_works.geong.geocoder
|
4
|
+
namespace php com.tera_works.geong.geocoder
|
5
|
+
namespace py com_tera_works_geong_geocoder
|
6
|
+
namespace cpp Geong
|
7
|
+
|
8
|
+
|
9
|
+
struct Location
|
10
|
+
{
|
11
|
+
1:double latitude,
|
12
|
+
2:double longitude
|
13
|
+
}
|
14
|
+
|
15
|
+
exception NoResultException
|
16
|
+
{
|
17
|
+
1:string message
|
18
|
+
}
|
19
|
+
|
20
|
+
exception TimeoutException
|
21
|
+
{
|
22
|
+
1:string message
|
23
|
+
}
|
24
|
+
|
25
|
+
service GeocoderService
|
26
|
+
{
|
27
|
+
Location coordinates(1:string address) throws(1:NoResultException error, 2:TimeoutException error2),
|
28
|
+
string address(1:string query) throws(1:NoResultException error, 2:TimeoutException error2),
|
29
|
+
}
|
metadata
ADDED
@@ -0,0 +1,135 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: geong
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.0.1
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- yuki teraoka
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2014-11-10 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: geocoder
|
15
|
+
requirement: !ruby/object:Gem::Requirement
|
16
|
+
requirements:
|
17
|
+
- - ">="
|
18
|
+
- !ruby/object:Gem::Version
|
19
|
+
version: '0'
|
20
|
+
type: :runtime
|
21
|
+
prerelease: false
|
22
|
+
version_requirements: !ruby/object:Gem::Requirement
|
23
|
+
requirements:
|
24
|
+
- - ">="
|
25
|
+
- !ruby/object:Gem::Version
|
26
|
+
version: '0'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: thrift
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :runtime
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
41
|
+
- !ruby/object:Gem::Dependency
|
42
|
+
name: redis
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - ">="
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :development
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - ">="
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - "~>"
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.7'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - "~>"
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.7'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - "~>"
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - "~>"
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
description: Thrift based Geocoding RPC. using the ruby Geocoder library.
|
84
|
+
email:
|
85
|
+
- teraoka.yuki@synergy101.jp
|
86
|
+
executables:
|
87
|
+
- geong_server
|
88
|
+
extensions: []
|
89
|
+
extra_rdoc_files: []
|
90
|
+
files:
|
91
|
+
- ".gitignore"
|
92
|
+
- Gemfile
|
93
|
+
- LICENSE.txt
|
94
|
+
- README.md
|
95
|
+
- Rakefile
|
96
|
+
- bin/geong_server
|
97
|
+
- generated/geong/geocoder/geocoder_constants.rb
|
98
|
+
- generated/geong/geocoder/geocoder_service.rb
|
99
|
+
- generated/geong/geocoder/geocoder_types.rb
|
100
|
+
- geong.gemspec
|
101
|
+
- lib/geong.rb
|
102
|
+
- lib/geong/cache.rb
|
103
|
+
- lib/geong/client.rb
|
104
|
+
- lib/geong/geocoder.rb
|
105
|
+
- lib/geong/geocoder/geocoder_handler.rb
|
106
|
+
- lib/geong/server.rb
|
107
|
+
- lib/geong/server/configuration.rb
|
108
|
+
- lib/geong/version.rb
|
109
|
+
- thrift/geocoder.thrift
|
110
|
+
homepage: ''
|
111
|
+
licenses:
|
112
|
+
- MIT
|
113
|
+
metadata: {}
|
114
|
+
post_install_message:
|
115
|
+
rdoc_options: []
|
116
|
+
require_paths:
|
117
|
+
- lib
|
118
|
+
- generated
|
119
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
120
|
+
requirements:
|
121
|
+
- - ">="
|
122
|
+
- !ruby/object:Gem::Version
|
123
|
+
version: '0'
|
124
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
125
|
+
requirements:
|
126
|
+
- - ">="
|
127
|
+
- !ruby/object:Gem::Version
|
128
|
+
version: '0'
|
129
|
+
requirements: []
|
130
|
+
rubyforge_project:
|
131
|
+
rubygems_version: 2.2.2
|
132
|
+
signing_key:
|
133
|
+
specification_version: 4
|
134
|
+
summary: Thrift based Geocoding RPC.
|
135
|
+
test_files: []
|