Class: SparkApi::Models::Message

Inherits:
Base
  • Object
show all
Extended by:
Finders
Defined in:
lib/spark_api/models/message.rb

Constant Summary

Constants included from Paginate

Paginate::DEFAULT_PAGE_SIZE

Instance Attribute Summary

Attributes inherited from Base

#attributes, #errors, #parent

Class Method Summary collapse

Instance Method Summary collapse

Methods included from Finders

find, find_one, first, last

Methods inherited from Base

connection, #connection, count, element_name, element_name=, first, get, #id, #initialize, #load, #method_missing, #parse_id, path, #path, #persisted?, prefix, prefix=, #resource_pluralized, #resource_uri, #respond_to?, #to_param, #to_partial_path

Methods included from Paginate

#collect, #paginate, #per_page

Methods included from Dirty

#changed, #changed?, #changed_attributes, #changes, #dirty_attributes, #previous_changes

Constructor Details

This class inherits a constructor from SparkApi::Models::Base

Dynamic Method Handling

This class handles dynamic methods through the method_missing method in the class SparkApi::Models::Base

Class Method Details

.unread(args = {}) ⇒ Object



28
29
30
# File 'lib/spark_api/models/message.rb', line 28

def self.unread(args={})
  collect(connection.get("#{path}/unread", args))
end

.unread_countObject



32
33
34
# File 'lib/spark_api/models/message.rb', line 32

def self.unread_count
  unread _pagination: 'count'
end

Instance Method Details

#replies(args = {}) ⇒ Object



23
24
25
26
# File 'lib/spark_api/models/message.rb', line 23

def replies(args = {})
  arguments = {:_expand => "Body, Sender"}.merge(args)
  Message.collect(connection.get("#{self.class.path}/#{self.Id}/replies", arguments))
end

#save(arguments = {}) ⇒ Object



7
8
9
10
11
12
13
14
15
16
# File 'lib/spark_api/models/message.rb', line 7

def save(arguments={})
  begin
    return save!(arguments)
  rescue BadResourceRequest => e
    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

#save!(arguments = {}) ⇒ Object



18
19
20
21
# File 'lib/spark_api/models/message.rb', line 18

def save!(arguments={})
  results = connection.post self.class.path, {"Messages" => [ attributes ]}, arguments
  true
end