Class: CiscoSpark::Messages

Inherits:
Collection show all
Defined in:
lib/messages.rb

Instance Attribute Summary

Attributes inherited from Collection

#items

Class Method Summary collapse

Methods inherited from Collection

#[], #each, #initialize, #length, #push, #to_s

Constructor Details

This class inherits a constructor from CiscoSpark::Collection

Class Method Details

.CLI(options = {}) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/messages.rb', line 4

def CLI(options = {})
  case options[:action]
  when 'list'
    params = {}
    i[before roomId mentionedPeople beforeMessage].each { |k| params[k] = options[k] if options[k] }
    raise 'roomId must be specified' unless options[:roomId]
    messages = CiscoSpark::Messages::list(params)
    return messages
  when 'get'
    raise 'Specify message ID with --id' unless options[:id]
    message = CiscoSpark::Message::get(options[:id])
    return message
  when 'create'
    raise 'Specify room ID with --roomid' unless options[:roomId]
    params = {}
    i[toPersonId toPersonEmail text markdown files].each { |k| params[k] = options[k] if options[k] }
    message = CiscoSpark::Message::create(params)
    return message
  when 'delete'
    raise 'Specify message ID with --id' unless options[:id]
    message = CiscoSpark::Message::get(options[:id])
    message.delete
    return message
  else
    raise "action not specified or not one of list, get, create, delete"
  end
end

.list(params = {}) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/messages.rb', line 31

def list(params = {})
  out = CiscoSpark::Messages.new
  res = CiscoSpark.rest('GET', '/messages', params: params)
  if res.ok
    data = JSON.parse(res.body)
    data['items'].each do |r|
      message = CiscoSpark::Message.new(r)
      out.push(message)
    end
  end
  out
end