Skip to content

Commit 40db0f1

Browse files
committed
feat: endpoints for group and room informations
1 parent 507470b commit 40db0f1

File tree

2 files changed

+97
-0
lines changed

2 files changed

+97
-0
lines changed

lib/line/bot/client.rb

+36
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,42 @@ def get_room_member_ids(room_id, continuation_token = nil)
295295
get(endpoint, endpoint_path, credentials)
296296
end
297297

298+
# Gets the group ID, group name, and group icon URL of a group where the LINE Official Account is a member.
299+
#
300+
# @param group_id [String] Group's identifier
301+
#
302+
# @return [Net::HTTPResponse]
303+
def get_group_summary(group_id)
304+
channel_token_required
305+
306+
endpoint_path = "/bot/group/#{group_id}/summary"
307+
get(endpoint, endpoint_path, credentials)
308+
end
309+
310+
# Gets the user IDs of the members of a group that the bot is in.
311+
#
312+
# @param group_id [String] Group's identifier
313+
#
314+
# @return [Net::HTTPResponse]
315+
def get_group_members_count(group_id)
316+
channel_token_required
317+
318+
endpoint_path = "/bot/group/#{group_id}/members/count"
319+
get(endpoint, endpoint_path, credentials)
320+
end
321+
322+
# Gets the count of members in a room.
323+
#
324+
# @param room_id [String] Room's identifier
325+
#
326+
# @return [Net::HTTPResponse]
327+
def get_room_members_count(room_id)
328+
channel_token_required
329+
330+
endpoint_path = "/bot/room/#{room_id}/members/count"
331+
get(endpoint, endpoint_path, credentials)
332+
end
333+
298334
# Get a list of all uploaded rich menus
299335
#
300336
# @return [Net::HTTPResponse]

spec/line/bot/client_get_group_or_room_member_spec.rb

+61
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,26 @@
3131
}
3232
EOS
3333

34+
GROUP_SUMMARY = <<"EOS"
35+
{
36+
"groupId": "group_id",
37+
"groupName": "Group name",
38+
"pictureUrl":"https://example.com/abcdefghijklmn"
39+
}
40+
EOS
41+
42+
GROUP_MEMBERS_COUNT = <<"EOS"
43+
{
44+
"count": 3
45+
}
46+
EOS
47+
48+
ROOM_MEMBERS_COUNT = <<"EOS"
49+
{
50+
"count": 3
51+
}
52+
EOS
53+
3454
WebMock.allow_net_connect!
3555

3656
describe Line::Bot::Client do
@@ -136,4 +156,45 @@ def generate_client
136156
expect(contact['displayName']).to eq "LINE taro"
137157
expect(contact['pictureUrl']).to eq "http://obs.line-apps.com/image"
138158
end
159+
160+
it 'gets group summary' do
161+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/group/{groupId}/summary'
162+
stub_request(:get, uri_template).to_return { |request| {body: GROUP_SUMMARY, status: 200} }
163+
164+
client = generate_client
165+
group_id = "group_id"
166+
167+
response = client.get_group_summary(group_id)
168+
169+
contact = JSON.parse(response.body)
170+
expect(contact['groupId']).to eq "group_id"
171+
expect(contact['groupName']).to eq "Group name"
172+
expect(contact['pictureUrl']).to eq "https://example.com/abcdefghijklmn"
173+
end
174+
175+
it 'gets group members count' do
176+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/group/{groupId}/members/count'
177+
stub_request(:get, uri_template).to_return { |request| {body: GROUP_MEMBERS_COUNT, status: 200} }
178+
179+
client = generate_client
180+
group_id = "group_id"
181+
182+
response = client.get_group_members_count(group_id)
183+
184+
contact = JSON.parse(response.body)
185+
expect(contact['count']).to eq 3
186+
end
187+
188+
it 'gets group members count' do
189+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/room/{roomId}/members/count'
190+
stub_request(:get, uri_template).to_return { |request| {body: ROOM_MEMBERS_COUNT, status: 200} }
191+
192+
client = generate_client
193+
room_id = "room_id"
194+
195+
response = client.get_room_members_count(room_id)
196+
197+
contact = JSON.parse(response.body)
198+
expect(contact['count']).to eq 3
199+
end
139200
end

0 commit comments

Comments
 (0)