Class: Ambient::Orb
- Inherits:
-
Object
- Object
- Ambient::Orb
- Defined in:
- lib/ambient.rb
Overview
Ambient::Orb
The Ambient::Orb methods will check their parameters to avoid making expensive net calls that will fail due to values out of range. Any error cases will raise an AmbientError exception
Example:
Ambient::Orb.new(:id => 'ABC-DEF-GHI', :color => :red).update
or:
@my_orb = Ambient::Orb.new(:id => my_id)
@my_orb.color = :blue
@my_orb.update
@my_orb.color = :green
@my_orb.update
The second example isn’t as useful, since it can take up to 30 minutes for an Orb to actually be updated over the ether.
Constant Summary collapse
- AMBIENT_HOST =
:nodoc:
"myambient.com"
- AMBIENT_PORT =
:nodoc:
8080
- AMBIENT_URL =
:nodoc:
'/java/my_devices/submitdata.jsp'
- @@animations =
{ :none => 0, :very_slow => 1, :slow => 2, :medium_slow => 3, :medium => 4, :medium_fast => 5, :fast => 6, :very_fast => 7, :cresendo => 8, :heartbeat => 9 }
- @@colors =
Colors available for the ‘color’ property
{ :red => 0, :light_red => 1, :dark_orange => 2, :orange => 3, :light_orange => 4, :dark_yellow => 5, :yellow => 6, :lime_green => 7, :pale_green => 8, :green => 12, :pale_aqua => 15, :aqua => 16, :dark_aqua => 17, :cyan => 18, :dark_cyan => 19, :light_blue => 20, :sky_blue => 21, :blue => 24, :deep_blue => 25, :very_deep_blue => 26, :violet => 27, :purple => 28, :light_purple => 29, :magenta => 30, :deep_magenta => 33, :very_deep_magenta => 35, :white => 36 }
Instance Attribute Summary collapse
-
#animation ⇒ Object
Animation to set the Orb to perform.
-
#color ⇒ Object
Color to set the Orb to display.
-
#id ⇒ Object
Orb ID from the bottom of your Orb or Beacon.
-
#update_at ⇒ Object
readonly
The time and date at which the orb should be updated, set after the update() call.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ Orb
constructor
Takes a hash of up to three values: :id => Orb ID :color => Color value :animation => Animation value.
-
#update ⇒ Object
Make the HTTP call to the Ambient Devices web site to cause your orb to be updated.
Constructor Details
#initialize(options = {}) ⇒ Orb
Takes a hash of up to three values:
:id => Orb ID
:color => Color value
:animation => Animation value
136 137 138 139 140 |
# File 'lib/ambient.rb', line 136 def initialize( = {}) self.color = [:color] || 0 self.animation = [:animation] || 0 self.id = [:id] || nil end |
Instance Attribute Details
#animation ⇒ Object
Animation to set the Orb to perform
87 88 89 |
# File 'lib/ambient.rb', line 87 def animation @animation end |
#color ⇒ Object
Color to set the Orb to display
84 85 86 |
# File 'lib/ambient.rb', line 84 def color @color end |
#id ⇒ Object
Orb ID from the bottom of your Orb or Beacon
81 82 83 |
# File 'lib/ambient.rb', line 81 def id @id end |
#update_at ⇒ Object (readonly)
The time and date at which the orb should be updated, set after the update() call
90 91 92 |
# File 'lib/ambient.rb', line 90 def update_at @update_at end |
Instance Method Details
#update ⇒ Object
Make the HTTP call to the Ambient Devices web site to cause your orb to be updated. The Orb ID supplied must be registered with Ambient Devices as using the developer channel for this call to succeed.
Returns self, to allow this to work
-
Ambient::Orb.new(:id => ‘ABC-DEF-GHI’, :color => :red).update.update_at
149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 |
# File 'lib/ambient.rb', line 149 def update raise AmbientError, "No ID set for Ambient Orb" if id == nil Net::HTTP.start(AMBIENT_HOST, AMBIENT_PORT) do |http| begin response = http.get("#{AMBIENT_URL}?devID=#{id}&anim=#{animation}&color=#{color}") rescue Exception raise AmbientError, "HTTP Get Failed" end xml = REXML::Document.new(response.body) xml.elements.each("//response") do |resp| raise AmbientError, resp.text unless resp.attributes["type"] == "OK" end xml.elements.each("//maxNextUpdate") do |update| @update_at = DateTime::parse(update.text).new_offset(5.0/24.0) end end self end |