Class: Geoiq::Dataset
Instance Attribute Summary collapse
-
#data_type ⇒ Object
Returns the value of attribute data_type.
-
#description ⇒ Object
Returns the value of attribute description.
-
#feature_count ⇒ Object
Returns the value of attribute feature_count.
-
#geoiq_id ⇒ Object
Returns the value of attribute geoiq_id.
-
#json ⇒ Object
Returns the value of attribute json.
-
#link ⇒ Object
Returns the value of attribute link.
-
#published ⇒ Object
Returns the value of attribute published.
-
#tags ⇒ Object
Returns the value of attribute tags.
-
#title ⇒ Object
Returns the value of attribute title.
Attributes inherited from BaseModel
Instance Method Summary collapse
- #attributes ⇒ Object
- #csv_upload(filename, options = {}) ⇒ Object
- #delete ⇒ Object
- #features(options = {}) ⇒ Object
-
#find(id, options = {}) ⇒ Object
datasets.find(123).
-
#initialize(auth, options = {}) ⇒ Dataset
constructor
A new instance of Dataset.
- #shp_upload(shp_file, dbf_file, shx_file) ⇒ Object
- #update(options) ⇒ Object
-
#url_upload(url, options = {}) ⇒ Object
Create a new dataset by passing in a url, and optional type type = csv,kml,rss, wms, tile.
Methods inherited from BaseModel
Constructor Details
#initialize(auth, options = {}) ⇒ Dataset
Returns a new instance of Dataset.
11 12 13 14 15 16 17 |
# File 'lib/geoiq/dataset.rb', line 11 def initialize(auth, = {}) self.geoiq_id = .delete(:geoiq_id) if .include?(:geoiq_id) self.title = [:title] || "Untitled" self.description = [:description] || "" self. = [:tags] || "" super end |
Instance Attribute Details
#data_type ⇒ Object
Returns the value of attribute data_type.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def data_type @data_type end |
#description ⇒ Object
Returns the value of attribute description.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def description @description end |
#feature_count ⇒ Object
Returns the value of attribute feature_count.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def feature_count @feature_count end |
#geoiq_id ⇒ Object
Returns the value of attribute geoiq_id.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def geoiq_id @geoiq_id end |
#json ⇒ Object
Returns the value of attribute json.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def json @json end |
#link ⇒ Object
Returns the value of attribute link.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def link @link end |
#published ⇒ Object
Returns the value of attribute published.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def published @published end |
#tags ⇒ Object
Returns the value of attribute tags.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def @tags end |
#title ⇒ Object
Returns the value of attribute title.
5 6 7 |
# File 'lib/geoiq/dataset.rb', line 5 def title @title end |
Instance Method Details
#attributes ⇒ Object
7 8 9 |
# File 'lib/geoiq/dataset.rb', line 7 def attributes %w{title description tags published data_type feature_count link} end |
#csv_upload(filename, options = {}) ⇒ Object
54 55 56 57 58 59 60 61 62 63 64 65 66 |
# File 'lib/geoiq/dataset.rb', line 54 def csv_upload(filename, ={}) type = "text/csv" content = File.read(filename) response = request(:post, "/datasets.json", {:body => content, :headers =>{ "Content-Type" => "#{type}"}, :query => }) id = response.headers["location"].match(/(\d+)\.json/)[1].to_i return find(id) end |
#delete ⇒ Object
38 39 40 41 42 |
# File 'lib/geoiq/dataset.rb', line 38 def delete requires_geoiq_id response = request(:delete, "/datasets/#{self.geoiq_id}.json") return true if response["status"].to_i == 204 end |
#features(options = {}) ⇒ Object
45 46 47 48 49 50 51 52 |
# File 'lib/geoiq/dataset.rb', line 45 def features(={}) requires_geoiq_id response = request(:get, "/datasets/#{self.geoiq_id}/features.json", {:query => }) features = JSON.parse(response.body) end |
#find(id, options = {}) ⇒ Object
datasets.find(123)
20 21 22 23 24 25 |
# File 'lib/geoiq/dataset.rb', line 20 def find(id, ={}) = {:include_geometry=>0} response = request(:get, "/datasets/#{id}.json", {:query => }) dataset = Geoiq::Dataset.parse(response, auth, {:geoiq_id => id}) dataset end |
#shp_upload(shp_file, dbf_file, shx_file) ⇒ Object
68 69 70 71 72 73 74 75 76 77 78 79 |
# File 'lib/geoiq/dataset.rb', line 68 def shp_upload(shp_file, dbf_file, shx_file) body = shp_upload_body(shp_file, dbf_file, shx_file) response = request(:post, "/datasets.json", {:body => body, :headers =>{ "Content-Type" => "multipart/form-data, boundary=89d6e3836995"} }) id = response.headers["location"].match(/(\d+)\.json/)[1].to_i return find(id) end |
#update(options) ⇒ Object
27 28 29 30 31 32 33 34 35 36 |
# File 'lib/geoiq/dataset.rb', line 27 def update() requires_geoiq_id self.title ||= [:title] self.description ||= [:description] self. ||= [:tags] self.attributes ||= [:attributes] = {:overlay => } response = request(:put, "/datasets/#{self.geoiq_id}.json", {:query => }) return true if response["status"].to_i == 200 || response["status"].to_i == 201 end |
#url_upload(url, options = {}) ⇒ Object
Create a new dataset by passing in a url, and optional type type = csv,kml,rss, wms, tile
83 84 85 86 87 88 89 |
# File 'lib/geoiq/dataset.rb', line 83 def url_upload(url, ={}) query = {:url => url}.merge() response = request(:post, "/datasets.json", {:query => query}) id = response.headers["location"].match(/(\d+)\.json/)[1].to_i return find(id) end |