Skip to content

Commit 351fd3f

Browse files
authored
Merge pull request #187 from etrex/feature/endpoints_for_group_informations
feat: endpoints for group and room informations
2 parents 8c91b6b + 40db0f1 commit 351fd3f

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
@@ -300,6 +300,42 @@ def get_room_member_ids(room_id, continuation_token = nil)
300300
get(endpoint, endpoint_path, credentials)
301301
end
302302

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