Class: Blueticks::Resources::GroupsResource
- Inherits:
-
BaseResource
- Object
- BaseResource
- Blueticks::Resources::GroupsResource
- Defined in:
- lib/blueticks/resources/groups.rb
Instance Attribute Summary
Attributes inherited from BaseResource
Instance Method Summary collapse
-
#add_members(group_id, chat_id: nil, participants: nil) ⇒ Object
Add members to the group by chat id (JID / +E.164) and/or a list of participants.
-
#create(name:, participants:) ⇒ Object
Create a new group with an initial participant list.
-
#demote_admin(group_id, chat_id) ⇒ Object
Revoke admin privileges from a group member.
-
#leave(group_id) ⇒ Object
Leave the group as the authenticated identity.
-
#list(search_token: nil, include_archive: nil, skip: nil, limit: nil) ⇒ Object
List groups.
-
#promote_admin(group_id, chat_id) ⇒ Object
Grant admin privileges to a group member.
-
#remove_member(group_id, chat_id) ⇒ Object
Remove a participant from the group.
-
#retrieve(group_id, include: nil) ⇒ Object
Retrieve group metadata by id.
-
#set_picture(group_id, file_data_url: nil, url: nil, file_name: nil, file_mime_type: nil) ⇒ Object
Replace the group picture.
-
#update(group_id, name: nil, settings: nil) ⇒ Object
Rename the group and/or update admin-only settings.
Methods inherited from BaseResource
Constructor Details
This class inherits a constructor from Blueticks::BaseResource
Instance Method Details
#add_members(group_id, chat_id: nil, participants: nil) ⇒ Object
Add members to the group by chat id (JID / +E.164) and/or a list of participants.
53 54 55 56 57 58 59 |
# File 'lib/blueticks/resources/groups.rb', line 53 def add_members(group_id, chat_id: nil, participants: nil) body = {} body["chatId"] = chat_id unless chat_id.nil? body["participants"] = participants unless participants.nil? env = client.request("POST", "/v1/groups/#{group_id}/members", body: body) Types::Group.from_hash(env && env["data"]) end |
#create(name:, participants:) ⇒ Object
Create a new group with an initial participant list.
26 27 28 29 30 |
# File 'lib/blueticks/resources/groups.rb', line 26 def create(name:, participants:) env = client.request("POST", "/v1/groups", body: { "name" => name, "participants" => participants }) Types::Group.from_hash(env && env["data"]) end |
#demote_admin(group_id, chat_id) ⇒ Object
Revoke admin privileges from a group member.
74 75 76 77 |
# File 'lib/blueticks/resources/groups.rb', line 74 def demote_admin(group_id, chat_id) env = client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}/admin") Types::Group.from_hash(env && env["data"]) end |
#leave(group_id) ⇒ Object
Leave the group as the authenticated identity. Idempotent (204).
92 93 94 95 |
# File 'lib/blueticks/resources/groups.rb', line 92 def leave(group_id) client.request("DELETE", "/v1/groups/#{group_id}/members/me") nil end |
#list(search_token: nil, include_archive: nil, skip: nil, limit: nil) ⇒ Object
List groups.
List the groups the connected WhatsApp engine sees. Offset-paginated
(GroupListItem rows), with an optional case-insensitive name search via
search_token.
15 16 17 18 19 20 21 22 23 |
# File 'lib/blueticks/resources/groups.rb', line 15 def list(search_token: nil, include_archive: nil, skip: nil, limit: nil) params = {} params["searchToken"] = search_token unless search_token.nil? params["includeArchive"] = include_archive unless include_archive.nil? params["skip"] = skip unless skip.nil? params["limit"] = limit unless limit.nil? env = client.request("GET", "/v1/groups", params: params.empty? ? nil : params) Types::PaginatedPage.from_hash(env, item_type: Types::GroupListItem) end |
#promote_admin(group_id, chat_id) ⇒ Object
Grant admin privileges to a group member.
68 69 70 71 |
# File 'lib/blueticks/resources/groups.rb', line 68 def promote_admin(group_id, chat_id) env = client.request("POST", "/v1/groups/#{group_id}/members/#{chat_id}/admin") Types::Group.from_hash(env && env["data"]) end |
#remove_member(group_id, chat_id) ⇒ Object
Remove a participant from the group.
62 63 64 65 |
# File 'lib/blueticks/resources/groups.rb', line 62 def remove_member(group_id, chat_id) env = client.request("DELETE", "/v1/groups/#{group_id}/members/#{chat_id}") Types::Group.from_hash(env && env["data"]) end |
#retrieve(group_id, include: nil) ⇒ Object
Retrieve group metadata by id. Pass include: "participants" to embed
the participant list.
34 35 36 37 38 |
# File 'lib/blueticks/resources/groups.rb', line 34 def retrieve(group_id, include: nil) params = include.nil? ? nil : { "include" => include } env = client.request("GET", "/v1/groups/#{group_id}", params: params) Types::Group.from_hash(env && env["data"]) end |
#set_picture(group_id, file_data_url: nil, url: nil, file_name: nil, file_mime_type: nil) ⇒ Object
Replace the group picture. file_data_url is a base64 data URL, or pass
a hosted url.
81 82 83 84 85 86 87 88 89 |
# File 'lib/blueticks/resources/groups.rb', line 81 def set_picture(group_id, file_data_url: nil, url: nil, file_name: nil, file_mime_type: nil) body = {} body["fileDataUrl"] = file_data_url unless file_data_url.nil? body["url"] = url unless url.nil? body["fileName"] = file_name unless file_name.nil? body["fileMimeType"] = file_mime_type unless file_mime_type.nil? env = client.request("PUT", "/v1/groups/#{group_id}/picture", body: body) Types::Group.from_hash(env && env["data"]) end |
#update(group_id, name: nil, settings: nil) ⇒ Object
Rename the group and/or update admin-only settings. settings is a hash
using the API's wire keys (announce, restrict, editInfoAdminsOnly,
description).
43 44 45 46 47 48 49 |
# File 'lib/blueticks/resources/groups.rb', line 43 def update(group_id, name: nil, settings: nil) body = {} body["name"] = name unless name.nil? body["settings"] = settings unless settings.nil? env = client.request("PATCH", "/v1/groups/#{group_id}", body: body) Types::Group.from_hash(env && env["data"]) end |