geoapi 0.0.1 → 0.2.0
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.
- data/README +13 -8
- data/geoapi.gemspec +2 -2
- data/lib/geoapi.rb +1 -1
- data/lib/geoapi/entity.rb +2 -21
- data/lib/geoapi/{base.rb → query.rb} +30 -9
- data/lib/geoapi/version.rb +2 -2
- data/lib/geoapi/view.rb +1 -1
- metadata +2 -2
data/README
CHANGED
@@ -1,8 +1,13 @@
|
|
1
1
|
= NOTE
|
2
2
|
|
3
|
-
This is
|
3
|
+
This is still actively being developed and is very alpha. You can currently conduct a simple search and an MQL query. The results are returned as ruby hash.
|
4
|
+
|
5
|
+
== TODO
|
6
|
+
|
7
|
+
- Building data objects to represent Entities and Views.
|
8
|
+
|
9
|
+
- Allow updates to views.
|
4
10
|
|
5
|
-
I am quickly developing this into a fully featured gem that supports the full MQL queries offered by GeoAPI.com, so expect frequent updates until a major point release is reached.
|
6
11
|
|
7
12
|
= GeoAPI
|
8
13
|
|
@@ -20,14 +25,14 @@ A Ruby wrapper for the GeoAPI.com APIs. This gem was almost entirely inspired b
|
|
20
25
|
longitude = -131.000
|
21
26
|
|
22
27
|
# Non Required Options
|
23
|
-
optional_parameters = {:radius => '500m', :type => 'POI',
|
28
|
+
optional_parameters = {:radius => '500m', :type => 'POI', "include-parents" => true, :limit => 5, :pretty => true}
|
24
29
|
|
25
|
-
#
|
26
|
-
|
30
|
+
# Simple Search
|
31
|
+
result = GeoAPI::Query.simple_search(latitude, longitude, optional_parameters)
|
27
32
|
|
28
|
-
|
29
|
-
|
30
|
-
|
33
|
+
# MQL Query
|
34
|
+
q = {:lat => 37.75629, :lon => -122.4213, :radius => "1km", :entity => [{:type => "business", :guid => nil}]}
|
35
|
+
results = GeoAPI::Query.query(q)
|
31
36
|
|
32
37
|
|
33
38
|
|
data/geoapi.gemspec
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
Gem::Specification.new do |s|
|
2
2
|
s.name = "geoapi"
|
3
|
-
s.version = "0.0
|
3
|
+
s.version = "0.2.0"
|
4
4
|
s.date = "2009-11-10"
|
5
5
|
s.summary = "A Ruby wrapper for the GeoAPI.com API."
|
6
6
|
s.email = "chrisabruce@gmail.com"
|
@@ -13,7 +13,7 @@ Gem::Specification.new do |s|
|
|
13
13
|
"LICENSE",
|
14
14
|
"geoapi.gemspec",
|
15
15
|
"lib/geoapi.rb",
|
16
|
-
"lib/geoapi/
|
16
|
+
"lib/geoapi/query.rb",
|
17
17
|
"lib/geoapi/entity.rb",
|
18
18
|
"lib/geoapi/view.rb",
|
19
19
|
"lib/geoapi/version.rb"
|
data/lib/geoapi.rb
CHANGED
data/lib/geoapi/entity.rb
CHANGED
@@ -1,29 +1,10 @@
|
|
1
1
|
module GeoAPI
|
2
|
-
class Entity
|
2
|
+
class Entity
|
3
3
|
attr_reader :guid, :name, :type, :geom, :url, :latitude, :longitude, :views, :userviews, :raw_json
|
4
4
|
|
5
5
|
alias_method :lat, :latitude
|
6
6
|
alias_method :lon, :longitude
|
7
|
-
|
8
|
-
# Class methods
|
9
|
-
def self.search(lat, lon, options = {})
|
10
|
-
options[:lat] = lat
|
11
|
-
options[:lon] = lon
|
12
|
-
url = build_url('search', options)
|
13
|
-
get_then_parse(url)
|
14
|
-
end
|
15
|
-
|
16
|
-
def self.get_then_parse(url)
|
17
|
-
response = JSON.parse(get(url))
|
18
|
-
results = []
|
19
|
-
if response && response['result']
|
20
|
-
response['result'].each do |entity|
|
21
|
-
results << Entity.new(entity)
|
22
|
-
end
|
23
|
-
end
|
24
|
-
return results
|
25
|
-
end
|
26
|
-
|
7
|
+
|
27
8
|
# Instance methods
|
28
9
|
def initialize(attrs)
|
29
10
|
@raw_json = JSON.generate(attrs)
|
@@ -1,14 +1,35 @@
|
|
1
1
|
module GeoAPI
|
2
|
-
class
|
2
|
+
class Query
|
3
|
+
|
3
4
|
class << self
|
5
|
+
# Uses GeoAPI's simple search method
|
6
|
+
def simple_search(lat, lon, options = {})
|
7
|
+
options[:lat] = lat
|
8
|
+
options[:lon] = lon
|
9
|
+
url = build_url('search', options)
|
10
|
+
get_then_parse(url)
|
11
|
+
end
|
12
|
+
|
13
|
+
# Uses GeoAPI's MQL query method
|
14
|
+
def query(query)
|
15
|
+
q = JSON.generate(query)
|
16
|
+
url = build_url('q', {:q => URI.escape(q)})
|
17
|
+
get_then_parse(url)
|
18
|
+
end
|
19
|
+
|
20
|
+
|
21
|
+
def get_then_parse(url)
|
22
|
+
JSON.parse(get(url))
|
23
|
+
end
|
24
|
+
|
4
25
|
def build_url(resource_path, options = {})
|
5
26
|
|
6
27
|
options[:apikey] ||= GeoAPI.apikey
|
7
28
|
query_string = build_query_params(options)
|
8
|
-
|
29
|
+
|
9
30
|
"#{GeoAPI::API_URL}#{resource_path}#{query_string}"
|
10
31
|
end
|
11
|
-
|
32
|
+
|
12
33
|
def get(url)
|
13
34
|
RestClient.get(url)
|
14
35
|
rescue RestClient::RequestFailed
|
@@ -16,16 +37,16 @@ module GeoAPI
|
|
16
37
|
rescue RestClient::ResourceNotFound
|
17
38
|
raise NotFound, "GUID invalid"
|
18
39
|
end
|
19
|
-
|
40
|
+
|
20
41
|
protected
|
21
|
-
|
42
|
+
|
22
43
|
# Take options and build query string
|
23
44
|
def build_query_params(options)
|
24
45
|
query = {}
|
25
|
-
|
26
|
-
#
|
46
|
+
|
47
|
+
#convert True/False
|
27
48
|
options.each_pair do |key, value|
|
28
|
-
new_key = key.to_s
|
49
|
+
new_key = key.to_s
|
29
50
|
new_val = case value
|
30
51
|
when TrueClass then 1
|
31
52
|
when FalseClass then 0
|
@@ -37,4 +58,4 @@ module GeoAPI
|
|
37
58
|
end
|
38
59
|
end
|
39
60
|
end
|
40
|
-
end
|
61
|
+
end
|
data/lib/geoapi/version.rb
CHANGED
data/lib/geoapi/view.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: geoapi
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chris Bruce
|
@@ -45,7 +45,7 @@ files:
|
|
45
45
|
- LICENSE
|
46
46
|
- geoapi.gemspec
|
47
47
|
- lib/geoapi.rb
|
48
|
-
- lib/geoapi/
|
48
|
+
- lib/geoapi/query.rb
|
49
49
|
- lib/geoapi/entity.rb
|
50
50
|
- lib/geoapi/view.rb
|
51
51
|
- lib/geoapi/version.rb
|