Skip to content

Commit 239362c

Browse files
authored
Merge pull request #268 from zenizh/validate-message-objects
Add APIs to validate message objects
2 parents 7a064f2 + 9705d4e commit 239362c

File tree

2 files changed

+175
-0
lines changed

2 files changed

+175
-0
lines changed

lib/line/bot/client.rb

Lines changed: 65 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -535,6 +535,71 @@ def get_message_delivery_broadcast(date)
535535
get(endpoint, endpoint_path, credentials)
536536
end
537537

538+
# Validate message objects of a reply message
539+
#
540+
# @param messages [Array] Array of message objects to validate
541+
#
542+
# @return [Net::HTTPResponse]
543+
def validate_reply_message_objects(messages)
544+
channel_token_required
545+
546+
endpoint_path = '/bot/message/validate/reply'
547+
payload = { messages: messages }.to_json
548+
post(endpoint, endpoint_path, payload, credentials)
549+
end
550+
551+
# Validate message objects of a push message
552+
#
553+
# @param messages [Array] Array of message objects to validate
554+
#
555+
# @return [Net::HTTPResponse]
556+
def validate_push_message_objects(messages)
557+
channel_token_required
558+
559+
endpoint_path = '/bot/message/validate/push'
560+
payload = { messages: messages }.to_json
561+
post(endpoint, endpoint_path, payload, credentials)
562+
end
563+
564+
# Validate message objects of a multicast message
565+
#
566+
# @param messages [Array] Array of message objects to validate
567+
#
568+
# @return [Net::HTTPResponse]
569+
def validate_multicast_message_objects(messages)
570+
channel_token_required
571+
572+
endpoint_path = '/bot/message/validate/multicast'
573+
payload = { messages: messages }.to_json
574+
post(endpoint, endpoint_path, payload, credentials)
575+
end
576+
577+
# Validate message objects of a narrowcast message
578+
#
579+
# @param messages [Array] Array of message objects to validate
580+
#
581+
# @return [Net::HTTPResponse]
582+
def validate_narrowcast_message_objects(messages)
583+
channel_token_required
584+
585+
endpoint_path = '/bot/message/validate/narrowcast'
586+
payload = { messages: messages }.to_json
587+
post(endpoint, endpoint_path, payload, credentials)
588+
end
589+
590+
# Validate message objects of a broadcast message
591+
#
592+
# @param messages [Array] Array of message objects to validate
593+
#
594+
# @return [Net::HTTPResponse]
595+
def validate_broadcast_message_objects(messages)
596+
channel_token_required
597+
598+
endpoint_path = '/bot/message/validate/broadcast'
599+
payload = { messages: messages }.to_json
600+
post(endpoint, endpoint_path, payload, credentials)
601+
end
602+
538603
# Create a rich menu
539604
#
540605
# @param rich_menu [Hash] The rich menu represented as a rich menu object
Lines changed: 110 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,110 @@
1+
require 'spec_helper'
2+
require 'webmock/rspec'
3+
require 'json'
4+
5+
MESSAGE_OBJECTS = {
6+
messages: [
7+
{
8+
type: 'text',
9+
text: 'Hello, world'
10+
}
11+
]
12+
}
13+
14+
RESPONSE_BODY = <<"EOS"
15+
{}
16+
EOS
17+
18+
describe Line::Bot::Client do
19+
def dummy_config
20+
{
21+
channel_token: 'access token',
22+
}
23+
end
24+
25+
def client
26+
Line::Bot::Client.new do |config|
27+
config.channel_token = dummy_config[:channel_token]
28+
end
29+
end
30+
31+
it 'validates message objects of a reply message' do
32+
uri_template = Addressable::Template.new(Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/validate/reply')
33+
stub_request(:post, uri_template).with(body: MESSAGE_OBJECTS).to_return { |request| { body: RESPONSE_BODY, status: 200 } }
34+
35+
messages = [
36+
{
37+
type: 'text',
38+
text: 'Hello, world'
39+
}
40+
]
41+
42+
response = client.validate_reply_message_objects(messages)
43+
expect(response).to be_a(Net::HTTPOK)
44+
expect(JSON.parse(response.body)).to eq({})
45+
end
46+
47+
it 'validates message objects of a push message' do
48+
uri_template = Addressable::Template.new(Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/validate/push')
49+
stub_request(:post, uri_template).with(body: MESSAGE_OBJECTS).to_return { |request| { body: RESPONSE_BODY, status: 200 } }
50+
51+
messages = [
52+
{
53+
type: 'text',
54+
text: 'Hello, world'
55+
}
56+
]
57+
58+
response = client.validate_push_message_objects(messages)
59+
expect(response).to be_a(Net::HTTPOK)
60+
expect(JSON.parse(response.body)).to eq({})
61+
end
62+
63+
it 'validates message objects of a multicast message' do
64+
uri_template = Addressable::Template.new(Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/validate/multicast')
65+
stub_request(:post, uri_template).with(body: MESSAGE_OBJECTS).to_return { |request| { body: RESPONSE_BODY, status: 200 } }
66+
67+
messages = [
68+
{
69+
type: 'text',
70+
text: 'Hello, world'
71+
}
72+
]
73+
74+
response = client.validate_multicast_message_objects(messages)
75+
expect(response).to be_a(Net::HTTPOK)
76+
expect(JSON.parse(response.body)).to eq({})
77+
end
78+
79+
it 'validates message objects of a narrowcast message' do
80+
uri_template = Addressable::Template.new(Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/validate/narrowcast')
81+
stub_request(:post, uri_template).with(body: MESSAGE_OBJECTS).to_return { |request| { body: RESPONSE_BODY, status: 200 } }
82+
83+
messages = [
84+
{
85+
type: 'text',
86+
text: 'Hello, world'
87+
}
88+
]
89+
90+
response = client.validate_narrowcast_message_objects(messages)
91+
expect(response).to be_a(Net::HTTPOK)
92+
expect(JSON.parse(response.body)).to eq({})
93+
end
94+
95+
it 'validates message objects of a broadcast message' do
96+
uri_template = Addressable::Template.new(Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/validate/broadcast')
97+
stub_request(:post, uri_template).with(body: MESSAGE_OBJECTS).to_return { |request| { body: RESPONSE_BODY, status: 200 } }
98+
99+
messages = [
100+
{
101+
type: 'text',
102+
text: 'Hello, world'
103+
}
104+
]
105+
106+
response = client.validate_broadcast_message_objects(messages)
107+
expect(response).to be_a(Net::HTTPOK)
108+
expect(JSON.parse(response.body)).to eq({})
109+
end
110+
end

0 commit comments

Comments
 (0)