Class: Blueticks::Resources::GroupsResource

Inherits:
BaseResource show all
Defined in:
lib/blueticks/resources/groups.rb

Instance Attribute Summary

Attributes inherited from BaseResource

#client

Instance Method Summary collapse

Methods inherited from BaseResource

#initialize

Constructor Details

This class inherits a constructor from Blueticks::BaseResource

Instance Method Details

#add_member(group_id, chat_id:) ⇒ Object

Add a participant to the group by chat_id (JID) or +E.164 phone.



32
33
34
35
36
# File 'lib/blueticks/resources/groups.rb', line 32

def add_member(group_id, chat_id:)
  data = client.request("POST", "/v1/groups/#{group_id}/members",
                        body: { "chat_id" => chat_id })
  Types::Group.from_hash(data)
end

#create(name:, participants:) ⇒ Object

Create a new group with an initial participant list.



10
11
12
13
14
# File 'lib/blueticks/resources/groups.rb', line 10

def create(name:, participants:)
  data = client.request("POST", "/v1/groups",
                        body: { "name" => name, "participants" => participants })
  Types::Group.from_hash(data)
end

#demote_admin(group_id, chat_id) ⇒ Object

Revoke admin privileges from a group member.



51
52
53
54
# File 'lib/blueticks/resources/groups.rb', line 51

def demote_admin(group_id, chat_id)
  data = client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}/admin")
  Types::Group.from_hash(data)
end

#get(group_id) ⇒ Object

Retrieve group metadata by JID.



17
18
19
20
# File 'lib/blueticks/resources/groups.rb', line 17

def get(group_id)
  data = client.request("GET", "/v1/groups/#{group_id}")
  Types::Group.from_hash(data)
end

#leave(group_id) ⇒ Object

Leave the group as the authenticated identity. Idempotent (204).



66
67
68
69
# File 'lib/blueticks/resources/groups.rb', line 66

def leave(group_id)
  client.request("DELETE", "/v1/groups/#{group_id}/members/me")
  nil
end

#promote_admin(group_id, chat_id) ⇒ Object

Grant admin privileges to a group member.



45
46
47
48
# File 'lib/blueticks/resources/groups.rb', line 45

def promote_admin(group_id, chat_id)
  data = client.request("POST", "/v1/groups/#{group_id}/members/#{chat_id}/admin")
  Types::Group.from_hash(data)
end

#remove_member(group_id, chat_id) ⇒ Object

Remove a participant from the group.



39
40
41
42
# File 'lib/blueticks/resources/groups.rb', line 39

def remove_member(group_id, chat_id)
  data = client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}")
  Types::Group.from_hash(data)
end

#set_picture(group_id, file_data_url:, file_name: nil, file_mime_type: nil) ⇒ Object

Replace the group picture. ‘file_data_url` is a base64 data URL (PNG/JPEG, <=20 MiB).



57
58
59
60
61
62
63
# File 'lib/blueticks/resources/groups.rb', line 57

def set_picture(group_id, file_data_url:, file_name: nil, file_mime_type: nil)
  body = { "file_data_url" => file_data_url }
  body["file_name"] = file_name unless file_name.nil?
  body["file_mime_type"] = file_mime_type unless file_mime_type.nil?
  data = client.request("PUT", "/v1/groups/#{group_id}/picture", body: body)
  Types::Group.from_hash(data)
end

#update(group_id, name: nil, settings: nil) ⇒ Object

Rename the group and/or update admin-only settings.



23
24
25
26
27
28
29
# File 'lib/blueticks/resources/groups.rb', line 23

def update(group_id, name: nil, settings: nil)
  body = {}
  body["name"] = name unless name.nil?
  body["settings"] = settings unless settings.nil?
  data = client.request("PATCH", "/v1/groups/#{group_id}", body: body)
  Types::Group.from_hash(data)
end