Class: SelfSDK::Chat::Group

Inherits:
Object
  • Object
show all
Defined in:
lib/chat/group.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(chat, payload) ⇒ Group

Returns a new instance of Group.



10
11
12
13
14
15
16
17
18
19
# File 'lib/chat/group.rb', line 10

def initialize(chat, payload)
  @chat = chat
  @payload = payload
  @gid = payload[:gid]
  @members = payload[:members]
  @name = payload[:name]
  @link = payload[:link] if payload.key? :link
  @key = payload[:key] if payload.key? :key
  @mime = payload[:mime] if payload.key? :mime
end

Instance Attribute Details

#gidObject

Returns the value of attribute gid.



8
9
10
# File 'lib/chat/group.rb', line 8

def gid
  @gid
end

#membersObject

Returns the value of attribute members.



8
9
10
# File 'lib/chat/group.rb', line 8

def members
  @members
end

#nameObject

Returns the value of attribute name.



8
9
10
# File 'lib/chat/group.rb', line 8

def name
  @name
end

#payloadObject

Returns the value of attribute payload.



8
9
10
# File 'lib/chat/group.rb', line 8

def payload
  @payload
end

Instance Method Details

#invite(user) ⇒ Object

Sends an invitation to the specified user to join the group.

Parameters:

  • user (String)

    user to be invited.



25
26
27
28
29
30
# File 'lib/chat/group.rb', line 25

def invite(user)
  raise "invalid input" if user.empty?

  @members << user
  @chat.invite(@gid, @name, @members)
end

#joinObject

Sends a confi¡rmation message that has joined the group.



38
39
40
# File 'lib/chat/group.rb', line 38

def join
  @chat.join(@gid, @members)
end

#leaveObject

Sends a message to leave the current group.



33
34
35
# File 'lib/chat/group.rb', line 33

def leave
  @chat.leave(@gid, @members)
end

#message(body, opts = {}) ⇒ Object

Sends a message to the current group

Parameters:

  • body (String)

    message body to be sent.



45
46
47
48
# File 'lib/chat/group.rb', line 45

def message(body, opts = {})
  opts[:gid] = @gid
  @chat.message(@members, body, opts)
end