spatial_features 2.1.4 → 2.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/spatial_features/has_fusion_table_features/api.rb +5 -1
- data/lib/spatial_features/has_fusion_table_features/service.rb +6 -27
- data/lib/spatial_features/has_fusion_table_features.rb +7 -7
- data/lib/spatial_features/version.rb +1 -1
- data/lib/spatial_features.rb +0 -1
- metadata +1 -15
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e95e4c5de92ba868287059cbc55cd3ad0d2c1846
|
4
|
+
data.tar.gz: 9a69e73f631891b6f0a2d31cc44a0beedc18c07f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 45abd37c19fb70efdb09451017a2541a00f60e2eac82f41271669103f1ff26ae91942a3eaaff8d5c9553f3585a416ccdad4e26b538635f66a215c9a29f7fa693
|
7
|
+
data.tar.gz: d4a85dc77e38d8c5f761e9260affcb1daad1586c881eb673f0e91d108f5691eccb5d8f4daf512dea92a38e63ced95aa36768b7b81e9f07164f2245ed53ee65a7
|
@@ -21,13 +21,17 @@ module SpatialFeatures
|
|
21
21
|
end
|
22
22
|
|
23
23
|
def find_table(name)
|
24
|
-
service.tables.find {|table| table
|
24
|
+
service.tables.find {|table| table.name == name }.try(:table_id)
|
25
25
|
end
|
26
26
|
|
27
27
|
def delete_table(table_id)
|
28
28
|
service.delete_table(table_id)
|
29
29
|
end
|
30
30
|
|
31
|
+
def tables
|
32
|
+
service.tables
|
33
|
+
end
|
34
|
+
|
31
35
|
def set_features(table_id, features, colour: nil)
|
32
36
|
colour_features(features, colour)
|
33
37
|
service.replace_rows(table_id, features_to_csv(features))
|
@@ -1,5 +1,3 @@
|
|
1
|
-
require 'json'
|
2
|
-
|
3
1
|
module SpatialFeatures
|
4
2
|
module FusionTables
|
5
3
|
class Service
|
@@ -11,29 +9,24 @@ module SpatialFeatures
|
|
11
9
|
end
|
12
10
|
|
13
11
|
def table_ids
|
14
|
-
tables.collect
|
12
|
+
tables.collect(&:table_id)
|
15
13
|
end
|
16
14
|
|
17
15
|
def tables
|
18
|
-
|
16
|
+
fusion_tables_service.list_tables.items
|
19
17
|
end
|
20
18
|
|
21
19
|
def create_table(name, columns = [], table_options = {})
|
22
|
-
|
23
|
-
|
24
|
-
return parse_reponse(response)['tableId']
|
25
|
-
end
|
26
|
-
|
27
|
-
def select(query)
|
28
|
-
parse_reponse request(:get, "https://www.googleapis.com/fusiontables/v2/query", :params => {:sql => query})
|
20
|
+
table_object = {:name => name, :columns => columns, :is_exportable => true}.merge(table_options)
|
21
|
+
fusion_tables_service.insert_table(table_object, :fields => 'table_id')
|
29
22
|
end
|
30
23
|
|
31
24
|
def delete_table(table_id)
|
32
|
-
|
25
|
+
fusion_tables_service.delete_table(table_id)
|
33
26
|
end
|
34
27
|
|
35
28
|
def style_ids(table_id)
|
36
|
-
|
29
|
+
tables.collect(&:style_id)
|
37
30
|
end
|
38
31
|
|
39
32
|
def styles(table_id)
|
@@ -66,20 +59,6 @@ module SpatialFeatures
|
|
66
59
|
end
|
67
60
|
end
|
68
61
|
|
69
|
-
def request(method, url, header: {}, body: {}, params: {})
|
70
|
-
headers = @authorization.apply('Content-Type' => 'application/json')
|
71
|
-
headers.merge!(header)
|
72
|
-
headers.merge!(:params => params)
|
73
|
-
return RestClient::Request.execute(:method => method, :url => url, :headers => headers, :payload => body)
|
74
|
-
rescue RestClient::ExceptionWithResponse => e
|
75
|
-
puts e.response
|
76
|
-
raise e
|
77
|
-
end
|
78
|
-
|
79
|
-
def parse_reponse(response)
|
80
|
-
JSON.parse(response.body)
|
81
|
-
end
|
82
|
-
|
83
62
|
def replace_rows(table_id, csv)
|
84
63
|
fusion_tables_service.replace_table_rows(table_id, :upload_source => csv, :options => {:open_timeout_sec => 1.hour})
|
85
64
|
end
|
@@ -25,7 +25,7 @@ module SpatialFeatures
|
|
25
25
|
fusion_table_groups(group_options) do |fusion_table_id, records, group_features|
|
26
26
|
API.delete_table(fusion_table_id)
|
27
27
|
end
|
28
|
-
fusion_table_id_cache
|
28
|
+
@fusion_table_id_cache = nil
|
29
29
|
end
|
30
30
|
|
31
31
|
def acts_like_fusion_table_features?
|
@@ -33,17 +33,17 @@ module SpatialFeatures
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def fusion_table_id_cache
|
36
|
-
@fusion_table_id_cache ||= Hash.new
|
37
|
-
|
38
|
-
end
|
36
|
+
@fusion_table_id_cache ||= Hash.new {|hash, table_name| hash[table_name] = API.find_or_create_table(table_name) }
|
37
|
+
.replace(API.tables.collect {|table| [table.name, table.table_id] }.to_h) # Warm the cache
|
39
38
|
end
|
40
39
|
|
41
40
|
private
|
42
41
|
|
43
42
|
def fusion_table_groups(only: [], except: [])
|
44
|
-
all.group_by(&:fusion_table_id)
|
45
|
-
|
46
|
-
|
43
|
+
groups = all.group_by(&:fusion_table_id)
|
44
|
+
groups.select! {|fusion_table_id| Array.wrap(only).include?(fusion_table_id) } if only.present?
|
45
|
+
groups.select! {|fusion_table_id| !Array.wrap(except).include?(fusion_table_id) } if except.present?
|
46
|
+
groups.each do |fusion_table_id, records|
|
47
47
|
yield fusion_table_id, records, features.where(:spatial_model_id => records)
|
48
48
|
end
|
49
49
|
end
|
data/lib/spatial_features.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: spatial_features
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.1.
|
4
|
+
version: 2.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ryan Wallace
|
@@ -81,20 +81,6 @@ dependencies:
|
|
81
81
|
- - "~>"
|
82
82
|
- !ruby/object:Gem::Version
|
83
83
|
version: '1.6'
|
84
|
-
- !ruby/object:Gem::Dependency
|
85
|
-
name: rest-client
|
86
|
-
requirement: !ruby/object:Gem::Requirement
|
87
|
-
requirements:
|
88
|
-
- - "~>"
|
89
|
-
- !ruby/object:Gem::Version
|
90
|
-
version: '2.0'
|
91
|
-
type: :runtime
|
92
|
-
prerelease: false
|
93
|
-
version_requirements: !ruby/object:Gem::Requirement
|
94
|
-
requirements:
|
95
|
-
- - "~>"
|
96
|
-
- !ruby/object:Gem::Version
|
97
|
-
version: '2.0'
|
98
84
|
- !ruby/object:Gem::Dependency
|
99
85
|
name: googleauth
|
100
86
|
requirement: !ruby/object:Gem::Requirement
|