Class: CS::Messages
- Inherits:
-
Object
- Object
- CS::Messages
- Includes:
- Enumerable
- Defined in:
- lib/csapi/messages.rb
Instance Attribute Summary collapse
-
#after ⇒ Object
Returns the value of attribute after.
-
#data ⇒ Object
Returns the value of attribute data.
-
#q ⇒ Object
Returns the value of attribute q.
Class Method Summary collapse
Instance Method Summary collapse
- #has_more? ⇒ Boolean
-
#initialize(object, q) ⇒ Messages
constructor
A new instance of Messages.
- #method_missing(meth, *args, &block) ⇒ Object
- #more(limit = nil) ⇒ Object
Constructor Details
#initialize(object, q) ⇒ Messages
Returns a new instance of Messages.
29 30 31 32 33 |
# File 'lib/csapi/messages.rb', line 29 def initialize(object, q) @after = object['after'] if object.include? 'after'; @q = q; @data = object['object'].map {|u| Message.new(u) } end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(meth, *args, &block) ⇒ Object
36 37 38 |
# File 'lib/csapi/messages.rb', line 36 def method_missing meth, *args, &block @data.send(meth.to_sym, *args, &block) end |
Instance Attribute Details
#after ⇒ Object
Returns the value of attribute after.
6 7 8 |
# File 'lib/csapi/messages.rb', line 6 def after @after end |
#data ⇒ Object
Returns the value of attribute data.
6 7 8 |
# File 'lib/csapi/messages.rb', line 6 def data @data end |
#q ⇒ Object
Returns the value of attribute q.
6 7 8 |
# File 'lib/csapi/messages.rb', line 6 def q @q end |
Class Method Details
.getMessages(type = 'inbox', limit = 5, start = nil) ⇒ Object
8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 |
# File 'lib/csapi/messages.rb', line 8 def self.getMessages(type='inbox', limit=5, start=nil) types = ['inbox', 'sent']; throw ArgumentError.new("Can't fetch messages of kind #{type}") unless types.include? type; url = "/users/#{CS::instance.uid}/messages" q = { type: type, limit: limit } if (start) q[:start] = start end r = HTTP.get(url, query:q); object = JSON.parse r.body CS::Messages.new(object, q); end |
Instance Method Details
#has_more? ⇒ Boolean
41 42 43 |
# File 'lib/csapi/messages.rb', line 41 def has_more? return @after != nil end |
#more(limit = nil) ⇒ Object
46 47 48 |
# File 'lib/csapi/messages.rb', line 46 def more limit=nil Messages.getMessages(@q[:type], (limit || @q[:limit]), @after) end |