Class: Heater::PointSet

Inherits:
Object
  • Object
show all
Defined in:
lib/heater/point_set.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options = {}) ⇒ PointSet

Returns a new instance of PointSet.



5
6
7
8
9
# File 'lib/heater/point_set.rb', line 5

def initialize(options={})
  options.each do |key,value|
    self.send("#{key}=",value) if self.respond_to?(key.to_sym)
  end
end

Instance Attribute Details

#created_atObject

Returns the value of attribute created_at.



3
4
5
# File 'lib/heater/point_set.rb', line 3

def created_at
  @created_at
end

#idObject

Returns the value of attribute id.



3
4
5
# File 'lib/heater/point_set.rb', line 3

def id
  @id
end

#nameObject

Returns the value of attribute name.



3
4
5
# File 'lib/heater/point_set.rb', line 3

def name
  @name
end

#pointsObject

Returns the value of attribute points.



3
4
5
# File 'lib/heater/point_set.rb', line 3

def points
  @points
end

#updated_atObject

Returns the value of attribute updated_at.



3
4
5
# File 'lib/heater/point_set.rb', line 3

def updated_at
  @updated_at
end

Class Method Details

.create(name) ⇒ Object



46
47
48
49
50
51
52
# File 'lib/heater/point_set.rb', line 46

def self.create(name)
  result = JSON.parse(RestClient.post("#{Heater::API.instance.api_endpoint}/point_sets", 
    :point_set => {:name => name}, :api_key => Heater::API.instance.api_key, 
    :content_type => "application/json").body)
  
  PointSet.new(result['point_set'])
end

.find(name) ⇒ Object

def self.find(name,api_key,Heater::API.instance.api_endpoint)



55
56
57
58
# File 'lib/heater/point_set.rb', line 55

def self.find(name)
  result = JSON.parse(RestClient.get("#{Heater::API.instance.api_endpoint}/point_sets/#{name}?api_key=#{Heater::API.instance.api_key}").body)
  PointSet.new(result['point_set'])
end

Instance Method Details

#add_point(lat, lng) ⇒ Object



16
17
18
19
# File 'lib/heater/point_set.rb', line 16

def add_point(lat,lng)
  result = JSON.parse(RestClient.post(@points, :point => {:lat => lat, :lng => lng}, :api_key => Heater::API.instance.api_key).body)
  Point.new(result['point'])
end

#add_points(points) ⇒ Object

Must be array of points



22
23
24
25
26
27
# File 'lib/heater/point_set.rb', line 22

def add_points(points)
  return false unless points.is_a?(Array)
  return false unless points.all? {|item| item.is_a?(Point) }
  result = JSON.parse(RestClient.post(@points, :points => points.to_json, :api_key => Heater::API.instance.api_key).body)
  result
end

#destroyObject



42
43
44
# File 'lib/heater/point_set.rb', line 42

def destroy
  JSON.parse(RestClient.delete("#{@id}?api_key=#{Heater::API.instance.api_key}", :api_key => Heater::API.instance.api_key, :content_type => "application/json").body)
end

#example_urlObject



11
12
13
14
# File 'lib/heater/point_set.rb', line 11

def example_url
  result = JSON.parse(RestClient.get("#{Heater::API.instance.api_endpoint}/point_sets/#{@name}/examples.json?api_key=#{Heater::API.instance.api_key}").body)
  result['public_url']
end

#get_points_in_setObject

What does this do? :-)



34
35
36
# File 'lib/heater/point_set.rb', line 34

def get_points_in_set
  JSON.parse(RestClient.get("#{@id}?api_key=#{Heater::API.instance.api_key}").body)
end

#remove_point(lat, lng) ⇒ Object



29
30
31
# File 'lib/heater/point_set.rb', line 29

def remove_point(lat,lng)
  JSON.parse(RestClient.delete("#{@points}/(#{lat},#{lng}).json?api_key=#{Heater::API.instance.api_key}", :content_type => "application/json").body)
end

#saveObject



38
39
40
# File 'lib/heater/point_set.rb', line 38

def save
  JSON.parse(RestClient.put("#{@id}", :point_set => {:name => @name}, :api_key => Heater::API.instance.api_key ).body)
end