lib/sysdig/user_notifications.rb in sysdig-0.2.3 vs lib/sysdig/user_notifications.rb in sysdig-0.2.4

- old
+ new

@@ -1,31 +1,38 @@ -class Sysdig::UserNotifications < Sysdig::Collection +class Sysdig::UserNotifications < Sysdig::Singular - model Sysdig::UserNotification + attribute :sns_enabled, type: :boolean, squash: ["sns", "enabled"] + attribute :sns_topics, type: :array, squash: ["sns", "topics"] - def all(options={}) - load(service.get_user_notifications.body.fetch("userNotification")).tap { |_| self.records.compact! } - end + attribute :email_enabled, type: :boolean, squash: ["email", "enabled"] + attribute :email_recipients, type: :array, squash: ["email", "recipients"] - def get(type) - all.find { |r| r.identity == type.to_s } + attribute :pager_duty_enabled, type: :boolean, squash: ["pagerDuty", "enabled"] + attribute :pager_duty_integrated, type: :boolean, squash: ["pagerDuty", "integrated"] + attribute :pager_duty_bind_resolution, type: :boolean, squash: ["pagerDuty", "resolveOnOk"] + attribute :pager_duty_connect_url, squash: ["pagerDuty", "connectUrl"] + + def fetch_attributes(options={}) + service.get_user_notifications.body.fetch("userNotification") end - def new(args) - type, attributes = *args + def save + data = service.update_user_notifications( + "sns" => { + "enabled" => self.sns_enabled, + "topics" => self.sns_topics, + }, + "email" => { + "enabled" => self.email_enabled, + "recipients" => self.email_recipients, + }, + "pagerDuty" => { + "enabled" => self.pager_duty_enabled, + "integrated" => self.pager_duty_integrated, + "resolveOnOk" => self.pager_duty_bind_resolution, + "connectUrl" => self.pager_duty_connect_url, + }, + ).body.fetch("userNotification") - unless attributes.is_a?(::Hash) - raise(ArgumentError.new("Initialization parameters must be an attributes hash, got #{attributes.class} #{attributes.inspect}")) - end - - concrete_model = model.types[type] - - if concrete_model - concrete_model.new( - { - :collection => self, - :service => service, - }.merge(attributes) - ) - end + merge_attributes(data) end end