Class: Heater::PointSet
- Inherits:
-
Object
- Object
- Heater::PointSet
- Defined in:
- lib/heater/point_set.rb
Instance Attribute Summary collapse
-
#created_at ⇒ Object
Returns the value of attribute created_at.
-
#id ⇒ Object
Returns the value of attribute id.
-
#name ⇒ Object
Returns the value of attribute name.
-
#points ⇒ Object
Returns the value of attribute points.
-
#updated_at ⇒ Object
Returns the value of attribute updated_at.
Class Method Summary collapse
- .create(name) ⇒ Object
-
.find(name) ⇒ Object
def self.find(name,api_key,Heater::API.instance.api_endpoint).
Instance Method Summary collapse
- #add_point(lat, lng) ⇒ Object
-
#add_points(points) ⇒ Object
Must be array of points.
- #destroy ⇒ Object
- #example_url ⇒ Object
-
#get_points_in_set ⇒ Object
What does this do? :-).
-
#initialize(options = {}) ⇒ PointSet
constructor
A new instance of PointSet.
- #remove_point(lat, lng) ⇒ Object
- #save ⇒ Object
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(={}) .each do |key,value| self.send("#{key}=",value) if self.respond_to?(key.to_sym) end end |
Instance Attribute Details
#created_at ⇒ Object
Returns the value of attribute created_at.
3 4 5 |
# File 'lib/heater/point_set.rb', line 3 def created_at @created_at end |
#id ⇒ Object
Returns the value of attribute id.
3 4 5 |
# File 'lib/heater/point_set.rb', line 3 def id @id end |
#name ⇒ Object
Returns the value of attribute name.
3 4 5 |
# File 'lib/heater/point_set.rb', line 3 def name @name end |
#points ⇒ Object
Returns the value of attribute points.
3 4 5 |
# File 'lib/heater/point_set.rb', line 3 def points @points end |
#updated_at ⇒ Object
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 |
#destroy ⇒ Object
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_url ⇒ Object
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_set ⇒ Object
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 |