Skip to content

Commit 83aca1e

Browse files
authored
Merge pull request #237 from 4geru/add-update-get-get-list-rich-menu-alias
add update/get/get_list rich_menu_alias
2 parents 147323c + f28314b commit 83aca1e

File tree

2 files changed

+77
-1
lines changed

2 files changed

+77
-1
lines changed

lib/line/bot/client.rb

+35
Original file line numberDiff line numberDiff line change
@@ -578,6 +578,41 @@ def unset_rich_menus_alias(rich_menu_alias_id)
578578
delete(endpoint, endpoint_path, credentials)
579579
end
580580

581+
# Update rich menu alias
582+
#
583+
# @param rich_menu_id [String] ID of an uploaded rich menu
584+
# @param rich_menu_alias_id [String] string of alias words rich menu
585+
#
586+
# @return [Net::HTTPResponse]
587+
def update_rich_menus_alias(rich_menu_id, rich_menu_alias_id)
588+
channel_token_required
589+
590+
endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
591+
post(endpoint, endpoint_path, { richMenuId: rich_menu_id }.to_json, credentials)
592+
end
593+
594+
# Get a rich menu alias via a rich menu alias ID
595+
#
596+
# @param rich_menu_alias_id [String] string of alias words rich menu
597+
#
598+
# @return [Net::HTTPResponse]
599+
def get_rich_menus_alias(rich_menu_alias_id)
600+
channel_token_required
601+
602+
endpoint_path = "/bot/richmenu/alias/#{rich_menu_alias_id}"
603+
get(endpoint, endpoint_path, credentials)
604+
end
605+
606+
# Get a list of all uploaded rich menus alias
607+
#
608+
# @return [Net::HTTPResponse]
609+
def get_rich_menus_alias_list
610+
channel_token_required
611+
612+
endpoint_path = "/bot/richmenu/alias/list"
613+
get(endpoint, endpoint_path, credentials)
614+
end
615+
581616
# Link a rich menu to a user
582617
#
583618
# If you want to link a rich menu to multiple users,

spec/line/bot/rich_menu_spec.rb

+42-1
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,23 @@
3838
}
3939
EOS
4040

41+
RICH_MENU_ALIAS_CONTENT = <<"EOS"
42+
{
43+
{
44+
"richMenuAliasId": "alias-1234567",
45+
"richMenuId": "1234567"
46+
}
47+
}
48+
EOS
49+
50+
RICH_MENU_ALIAS_LIST_CONTENT = <<"EOS"
51+
{
52+
"aliases": [
53+
#{RICH_MENU_ALIAS_CONTENT}
54+
]
55+
}
56+
EOS
57+
4158
RICH_MENU_IMAGE_FILE_PATH = 'spec/fixtures/line/bot/rich_menu_01.png'
4259
RICH_MENU_INVALID_FILE_EXTENSION_PATH = 'spec/fixtures/line/bot/rich_menu_01.txt'
4360

@@ -128,14 +145,38 @@
128145
expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias')
129146
end
130147

131-
fit 'deletes a rich menu alias' do
148+
it 'deletes a rich menu alias' do
132149
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567'
133150
stub_request(:delete, uri_template).to_return(body: '{}', status: 200)
134151

135152
client.unset_rich_menus_alias('alias-1234567')
136153
expect(WebMock).to have_requested(:delete, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567')
137154
end
138155

156+
it 'update a rich menu alias' do
157+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567'
158+
stub_request(:post, uri_template).to_return(body: '{}', status: 200)
159+
160+
client.update_rich_menus_alias('1234567', 'alias-1234567')
161+
expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567')
162+
end
163+
164+
it 'get a rich menu alias' do
165+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567'
166+
stub_request(:get, uri_template).to_return(body: RICH_MENU_ALIAS_CONTENT, status: 200)
167+
168+
client.get_rich_menus_alias('alias-1234567')
169+
expect(WebMock).to have_requested(:get, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/alias-1234567')
170+
end
171+
172+
it 'get a rich menu alias list' do
173+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/list'
174+
stub_request(:get, uri_template).to_return(body: RICH_MENU_ALIAS_LIST_CONTENT, status: 200)
175+
176+
client.get_rich_menus_alias_list
177+
expect(WebMock).to have_requested(:get, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/richmenu/alias/list')
178+
end
179+
139180
it 'links a rich menu to a user' do
140181
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/user/1234567/richmenu/7654321'
141182
stub_request(:post, uri_template).to_return(body: '{}', status: 200)

0 commit comments

Comments
 (0)