lib/keikokuc/notification.rb in keikokuc-0.7 vs lib/keikokuc/notification.rb in keikokuc-0.8

- old
+ new

@@ -5,22 +5,23 @@ # Examples # # notification = Keikokuc::Notification.new(message: 'hello', # severity: 'info', # target_name: 'sunny-skies-42' -# producer_api_key: 'abcd') +# producer_password: 'abcd', +# username: 'heroku-postgres') # if notification.publish # # persist notification # else # # handle error # end # class Keikokuc::Notification attr_accessor :message, :url, :severity, :target_name, :account_email, - :producer_api_key, :remote_id, - :errors, :read_at, :account_sequence + :producer_password, :username, + :remote_id, :errors, :account_sequence # Public: Initialize a notification # # opts - a hash of attributes to be set on constructed object # @@ -28,21 +29,21 @@ # # notification = Keikokuc::Notification.new(message: 'hello') # # All keys on the attr_accessor list will be set def initialize(opts = {}) - @message = opts[:message] - @url = opts[:url] - @severity = opts[:severity] - @target_name = opts[:target_name] - @account_email = opts[:account_email] - @producer_api_key = opts[:producer_api_key] - @remote_id = opts[:remote_id] - @errors = opts[:errors] - @read_at = opts[:read_at] - @account_sequence = opts[:account_sequence] - @client = opts[:client] + @message = opts[:message] + @url = opts[:url] + @severity = opts[:severity] + @target_name = opts[:target_name] + @account_email = opts[:account_email] + @producer_password = opts[:producer_password] + @username = opts[:username] + @remote_id = opts[:remote_id] + @errors = opts[:errors] + @account_sequence = opts[:account_sequence] + @client = opts[:client] end # Public: publishes this notification to keikoku # # This method sets the `remote_id` attribute if it succeeds. @@ -68,41 +69,33 @@ # no longer be displayed to any consumer for this user # # Returns a boolean set to true if marking as read succeeded def read response, error = client.read_notification(remote_id) - if error.nil? - self.read_at = response[:read_at] - end error.nil? end - # Public: whether this notification is marked as read by this user - # - # Returns true if the user has marked this notification as read - def read? - !!@read_at - end - # Internal: coerces this notification to a hash # # Returns this notification's attributes as a hash def to_hash { - :message => @message, - :url => @url, - :severity => @severity, - :target_name => @target_name, - :account_email => @account_email, - :producer_api_key => @producer_api_key, - :remote_id => @remote_id, - :errors => @errors, - :read_at => @read_at, - :account_sequence => @account_sequence, - :client => @client + :message => @message, + :url => @url, + :severity => @severity, + :target_name => @target_name, + :account_email => @account_email, + :producer_password => @producer_password, + :remote_id => @remote_id, + :errors => @errors, + :account_sequence => @account_sequence, + :client => @client } end def client # :nodoc: - @client ||= Keikokuc::Client.new(:producer_api_key => producer_api_key) + @client ||= Keikokuc::Client.new( + :username => username, + :api_key => producer_password + ) end end