Class: Moni::MoniGroup
- Inherits:
-
Object
- Object
- Moni::MoniGroup
- Defined in:
- lib/moni/moni_group.rb
Class Method Summary collapse
Instance Method Summary collapse
- #add_watch(hash) ⇒ Object
- #check_and_serialize ⇒ Object
-
#initialize(hash) ⇒ MoniGroup
constructor
A new instance of MoniGroup.
- #send_notices! ⇒ Object
Constructor Details
#initialize(hash) ⇒ MoniGroup
Returns a new instance of MoniGroup.
13 14 15 16 17 18 19 20 21 |
# File 'lib/moni/moni_group.rb', line 13 def initialize(hash) @group_name = hash.delete("group_name") @contacts = hash.delete("contacts") @watches = [] hash["watches"].to_a.each do |w| @watches << MoniWatch.new(w) end end |
Class Method Details
.from_serialized(serialized) ⇒ Object
4 5 6 7 |
# File 'lib/moni/moni_group.rb', line 4 def self.from_serialized(serialized) hash = JSON.parse(serialized) new(hash) end |
.from_url(url) ⇒ Object
9 10 11 |
# File 'lib/moni/moni_group.rb', line 9 def self.from_url(url) from_serialized(open(url).read) end |
Instance Method Details
#add_watch(hash) ⇒ Object
23 24 25 |
# File 'lib/moni/moni_group.rb', line 23 def add_watch(hash) @watches << MoniWatch.new(hash) end |
#check_and_serialize ⇒ Object
27 28 29 30 31 32 33 |
# File 'lib/moni/moni_group.rb', line 27 def check_and_serialize { :group_name => @group_name, :contacts => @contacts, :watches => @watches.collect(&:check_and_serialize) }.to_json end |
#send_notices! ⇒ Object
35 36 37 38 39 40 41 |
# File 'lib/moni/moni_group.rb', line 35 def send_notices! @watches.select(&:failed?).each do |w| @contacts.each do |contact_number| Twilio::Sms.("5126075807", contact_number, "#{w.name} failed") end end end |