Sha256: cd4614239d725f93bcdd1d0d16ac7feea1769528ec5374f90b9194007fd48f62

Contents?: true

Size: 1.26 KB

Versions: 27

Compression:

Stored size: 1.26 KB

Contents

module SparkApi
  module Models
    class Notification < Base

      self.element_name = 'notifications'

      def save(arguments={})
        self.errors = [] # clear the errors hash
        begin
          return save!(arguments)
        rescue BadResourceRequest => e
          self.errors << {:code => e.code, :message => e.message}
          SparkApi.logger.warn("Failed to save resource #{self}: #{e.message}")
        rescue NotFound => e
          SparkApi.logger.error("Failed to save resource #{self}: #{e.message}")
        end
        false
      end

      def save!(arguments={})
        results = connection.post self.class.path, attributes, arguments
        result = results.first
        attributes['ResourceUri'] = result['ResourceUri']
        true
      end

      def self.unread()
        # force pagination so response knows to deal with returned pagination info
        result = connection.get "#{self.path}/unread", {:_pagination => 'count'}
        result
      end

      def self.mark_read(notifications, arguments={})
        notifications = Array(notifications)

        ids = notifications.map { |n| n.respond_to?('Id') ? n.Id : n }
        result = connection.put "#{self.path}/#{ids.join(',')}", {'Read' => true}, arguments
      end

    end
  end
end

Version data entries

27 entries across 27 versions & 1 rubygems

Version Path
spark_api-1.4.9 lib/spark_api/models/notification.rb
spark_api-1.4.8 lib/spark_api/models/notification.rb
spark_api-1.4.6 lib/spark_api/models/notification.rb
spark_api-1.4.5 lib/spark_api/models/notification.rb
spark_api-1.4.4 lib/spark_api/models/notification.rb
spark_api-1.4.2 lib/spark_api/models/notification.rb
spark_api-1.4.1 lib/spark_api/models/notification.rb
spark_api-1.4.0 lib/spark_api/models/notification.rb
spark_api-1.3.28 lib/spark_api/models/notification.rb
spark_api-1.3.27 lib/spark_api/models/notification.rb
spark_api-1.3.26 lib/spark_api/models/notification.rb
spark_api-1.3.25 lib/spark_api/models/notification.rb
spark_api-1.3.24 lib/spark_api/models/notification.rb
spark_api-1.3.23 lib/spark_api/models/notification.rb
spark_api-1.3.21 lib/spark_api/models/notification.rb
spark_api-1.3.20 lib/spark_api/models/notification.rb
spark_api-1.3.19 lib/spark_api/models/notification.rb
spark_api-1.3.18 lib/spark_api/models/notification.rb
spark_api-1.3.17 lib/spark_api/models/notification.rb
spark_api-1.3.16 lib/spark_api/models/notification.rb