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



30
31
32
# File 'lib/blueticks/resources/groups.rb', line 30

def add_member(group_id, chat_id:)
  client.request("POST", "/v1/groups/#{group_id}/members", body: { "chat_id" => chat_id })
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



42
43
44
# File 'lib/blueticks/resources/groups.rb', line 42

def demote_admin(group_id, chat_id)
  client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}/admin")
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



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

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

#promote_admin(group_id, chat_id) ⇒ Object



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

def promote_admin(group_id, chat_id)
  client.request("POST", "/v1/groups/#{group_id}/members/#{chat_id}/admin")
end

#remove_member(group_id, chat_id) ⇒ Object



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

def remove_member(group_id, chat_id)
  client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}")
end

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



46
47
48
49
50
51
# File 'lib/blueticks/resources/groups.rb', line 46

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?
  client.request("PUT", "/v1/groups/#{group_id}/picture", body: body)
end

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

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



23
24
25
26
27
28
# 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?
  client.request("PATCH", "/v1/groups/#{group_id}", body: body)
end