Class: Geoiq::Map

Inherits:
BaseModel show all
Defined in:
lib/geoiq/map.rb

Instance Attribute Summary collapse

Attributes inherited from BaseModel

#auth

Instance Method Summary collapse

Methods inherited from BaseModel

api_methods, crud

Constructor Details

#initialize(auth, options = {}) ⇒ Map

Returns a new instance of Map.



11
12
13
14
15
16
17
18
19
# File 'lib/geoiq/map.rb', line 11

def initialize(auth, options={})
  self.geoiq_id = options.delete(:geoiq_id) if options.include?(:geoiq_id)
  self.title = options[:title] || "Untitled Map"
  self.tags = (options[:tags] || []).join(",")
  self.extent = options[:extent] || [-180,-90,180,90]
  self.basemap = options[:basemap] || "Acetate"
  self.layers = options[:layers] || []
  super
end

Instance Attribute Details

#basemapObject

Returns the value of attribute basemap.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def basemap
  @basemap
end

#descriptionObject

Returns the value of attribute description.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def description
  @description
end

#extentObject

Returns the value of attribute extent.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def extent
  @extent
end

#geoiq_idObject

Returns the value of attribute geoiq_id.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def geoiq_id
  @geoiq_id
end

#jsonObject

Returns the value of attribute json.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def json
  @json
end

#layersObject

Returns the value of attribute layers.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def layers
  @layers
end

#publishedObject

Returns the value of attribute published.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def published
  @published
end

#tagsObject

Returns the value of attribute tags.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def tags
  @tags
end

#titleObject

Returns the value of attribute title.



5
6
7
# File 'lib/geoiq/map.rb', line 5

def title
  @title
end

Instance Method Details

#add_layer(layer) ⇒ Object

layers are an array of ids of datasets to add



52
53
54
55
56
57
58
# File 'lib/geoiq/map.rb', line 52

def add_layer(layer)
  requires_geoiq_id
  options = {:source => "finder:#{layer}"}
  response = request(:post, "/maps/#{self.geoiq_id}/layers.json", {:query => options})
  layer_index = response.headers["location"].match(/(\d+)\.json/)[1].to_i
  return layer_index if response["status"].to_i == 201
end

#attributesObject



7
8
9
# File 'lib/geoiq/map.rb', line 7

def attributes
  %w{title description tags basemap extent layers}
end

#create(options = {}) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'lib/geoiq/map.rb', line 27

def create(options={})
  self.attributes.each do |a|
    options.merge!({a => self.send(a)})
  end
  
  response = request(:post, "/maps.json", {:query => options})
  
  id =  response.headers["location"].match(/(\d+)\.json/)[1].to_i

  return find(id)
end

#deleteObject



45
46
47
48
49
# File 'lib/geoiq/map.rb', line 45

def delete
  requires_geoiq_id
  response = request(:delete, "/maps/#{self.geoiq_id}.json")
  return true if response["status"].to_i == 204
end

#find(id, options = {}) ⇒ Object



21
22
23
24
25
# File 'lib/geoiq/map.rb', line 21

def find(id, options={})
  response = request(:get, "/maps/#{id}.json", {:query => options})
  map = Geoiq::Map.parse(response, auth, {:geoiq_id => id})
  map
end

#update(options = {}) ⇒ Object



39
40
41
42
43
# File 'lib/geoiq/map.rb', line 39

def update(options={})
  requires_geoiq_id
  response = request(:put, "/maps/#{self.geoiq_id}.json", {:query => options})
  return true if response["status"].to_i == 200 || response["status"].to_i == 201
end