spatial_features 2.1.4 → 2.1.5

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 161e05dd5050ab333151fad1b7ec795e3f7586dd
4
- data.tar.gz: 64e96f4e2f77c54db017c31e0d7babcce42015ba
3
+ metadata.gz: e95e4c5de92ba868287059cbc55cd3ad0d2c1846
4
+ data.tar.gz: 9a69e73f631891b6f0a2d31cc44a0beedc18c07f
5
5
  SHA512:
6
- metadata.gz: 42339e9b2190d5ad0b88a5823140b70febf158de17978822598799d22ad46e0276f76d28c1289599acfd24e7fd36d2c946e0bb2e09f1e43e37c48f6feb2c4c7f
7
- data.tar.gz: 52bb8cfed4a5728f997e8f0cbb7b6ededf330e1f7dbf1ce6478b7306556f802165a3746e6ba8a1e9f626c541e93138636984b23af998658aa021c34b2e792b04
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['name'] == name }.try(:fetch, 'tableId')
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 {|t| t['tableId'] }
12
+ tables.collect(&:table_id)
15
13
  end
16
14
 
17
15
  def tables
18
- parse_reponse(request(:get, 'https://www.googleapis.com/fusiontables/v2/tables')).fetch('items', [])
16
+ fusion_tables_service.list_tables.items
19
17
  end
20
18
 
21
19
  def create_table(name, columns = [], table_options = {})
22
- body = {:name => name, :columns => columns}.merge(:description => "Features", :isExportable => true).merge(table_options).to_json
23
- response = request(:post, 'https://www.googleapis.com/fusiontables/v2/tables', :body => body)
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
- request(:delete, "https://www.googleapis.com/fusiontables/v2/tables/#{table_id}")
25
+ fusion_tables_service.delete_table(table_id)
33
26
  end
34
27
 
35
28
  def style_ids(table_id)
36
- styles(table_id).collect {|t| t['styleId'] }
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.clear
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 do |hash, table_name|
37
- hash[table_name] = API.find_or_create_table(table_name)
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).each do |fusion_table_id, records|
45
- next if only.present? && !Array.wrap(only).include?(fusion_table_id)
46
- next if except.present? && Array.wrap(except).include?(fusion_table_id)
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
@@ -1,3 +1,3 @@
1
1
  module SpatialFeatures
2
- VERSION = "2.1.4"
2
+ VERSION = "2.1.5"
3
3
  end
@@ -2,7 +2,6 @@
2
2
  require 'rgeo/shapefile'
3
3
  require 'nokogiri'
4
4
  require 'zip'
5
- require 'rest-client'
6
5
  require 'googleauth'
7
6
  require 'google/apis/fusiontables_v2'
8
7
  require 'google/apis/drive_v3'
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
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