Skip to content

Commit 4aade45

Browse files
authored
Merge pull request #125 from line/feature/redesign
Support redesign features
2 parents 99f1ffb + 8707b39 commit 4aade45

File tree

2 files changed

+72
-0
lines changed

2 files changed

+72
-0
lines changed

lib/line/bot/client.rb

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -294,6 +294,16 @@ def get_message_delivery_multicast(date)
294294
get(endpoint_path)
295295
end
296296

297+
# Gets the number of messages sent with the /bot/message/multicast endpoint.
298+
#
299+
# @param date [String] Date the messages were sent (format: yyyyMMdd)
300+
#
301+
# @return [Net::HTTPResponse]
302+
def get_message_delivery_broadcast(date)
303+
endpoint_path = "/bot/message/delivery/broadcast?date=#{date}"
304+
get(endpoint_path)
305+
end
306+
297307
# Create a rich menu
298308
#
299309
# @param rich_menu [Hash] The rich menu represented as a rich menu object
@@ -441,6 +451,22 @@ def create_link_token(user_id)
441451
post(endpoint_path)
442452
end
443453

454+
# Get the target limit for additional messages
455+
#
456+
# @return [Net::HTTPResponse]
457+
def get_quota
458+
endpoint_path = "/bot/message/quota"
459+
get(endpoint_path)
460+
end
461+
462+
# Get number of messages sent this month
463+
#
464+
# @return [Net::HTTPResponse]
465+
def get_quota_consumption
466+
endpoint_path = "/bot/message/quota/consumption"
467+
get(endpoint_path)
468+
end
469+
444470
# Fetch data, get content of specified URL.
445471
#
446472
# @param endpoint_path [String]

spec/line/bot/client_get_spec.rb

Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,18 @@
2727
}
2828
EOS
2929

30+
QUOTA_CONTENT = <<"EOS"
31+
{
32+
"type":"none"
33+
}
34+
EOS
35+
36+
QUOTA_CONSUMPTION_CONTENT = <<"EOS"
37+
{
38+
"totalUsage":1
39+
}
40+
EOS
41+
3042
WebMock.allow_net_connect!
3143

3244
describe Line::Bot::Client do
@@ -120,11 +132,45 @@ def generate_client
120132
expect(delivery['success']).to eq 1
121133
end
122134

135+
it "gets the number of broadcast messages sent" do
136+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/broadcast?date={send_date}'
137+
stub_request(:get, uri_template).to_return(body: DELIVERY_NUMBER_CONTENT, status: 200)
138+
139+
client = generate_client
140+
response = client.get_message_delivery_broadcast("20190101")
141+
142+
delivery = JSON.parse(response.body)
143+
expect(delivery['status']).to eq "ready"
144+
expect(delivery['success']).to eq 1
145+
end
146+
123147
it "gets number of messages sent whithout date will raise error" do
124148
client = generate_client
125149

126150
expect { client.get_message_delivery_reply }.to raise_error(ArgumentError)
127151
expect { client.get_message_delivery_push }.to raise_error(ArgumentError)
128152
expect { client.get_message_delivery_multicast }.to raise_error(ArgumentError)
129153
end
154+
155+
it 'gets number of quota' do
156+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/quota'
157+
stub_request(:get, uri_template).to_return(body: QUOTA_CONTENT, status: 200)
158+
159+
client = generate_client
160+
response = client.get_quota
161+
162+
quota = JSON.parse(response.body)
163+
expect(quota['type']).to eq 'none'
164+
end
165+
166+
it 'gets number of quota consumption' do
167+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/quota/consumption'
168+
stub_request(:get, uri_template).to_return(body: QUOTA_CONSUMPTION_CONTENT, status: 200)
169+
170+
client = generate_client
171+
response = client.get_quota_consumption
172+
173+
quota = JSON.parse(response.body)
174+
expect(quota['totalUsage']).to eq 1
175+
end
130176
end

0 commit comments

Comments
 (0)