Skip to content

Commit 8707b39

Browse files
committed
Support redesign features
1 parent 378a2b8 commit 8707b39

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
@@ -273,6 +273,16 @@ def get_message_delivery_multicast(date)
273273
get(endpoint_path)
274274
end
275275

276+
# Gets the number of messages sent with the /bot/message/multicast endpoint.
277+
#
278+
# @param date [String] Date the messages were sent (format: yyyyMMdd)
279+
#
280+
# @return [Net::HTTPResponse]
281+
def get_message_delivery_broadcast(date)
282+
endpoint_path = "/bot/message/delivery/broadcast?date=#{date}"
283+
get(endpoint_path)
284+
end
285+
276286
# Create a rich menu
277287
#
278288
# @param rich_menu [Hash] The rich menu represented as a rich menu object
@@ -420,6 +430,22 @@ def create_link_token(user_id)
420430
post(endpoint_path)
421431
end
422432

433+
# Get the target limit for additional messages
434+
#
435+
# @return [Net::HTTPResponse]
436+
def get_quota
437+
endpoint_path = "/bot/message/quota"
438+
get(endpoint_path)
439+
end
440+
441+
# Get number of messages sent this month
442+
#
443+
# @return [Net::HTTPResponse]
444+
def get_quota_consumption
445+
endpoint_path = "/bot/message/quota/consumption"
446+
get(endpoint_path)
447+
end
448+
423449
# Fetch data, get content of specified URL.
424450
#
425451
# @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)