Class: CS::Messages

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/csapi/messages.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

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

#afterObject

Returns the value of attribute after.



6
7
8
# File 'lib/csapi/messages.rb', line 6

def after
  @after
end

#dataObject

Returns the value of attribute data.



6
7
8
# File 'lib/csapi/messages.rb', line 6

def data
  @data
end

#qObject

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

Returns:

  • (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