Skip to content

Commit 2533ee9

Browse files
authored
Merge pull request #103 from bugtender/add-get-number-of-messages-sent-methods
Add get number of messages sent methods
2 parents fdc9e44 + 55ace84 commit 2533ee9

File tree

2 files changed

+81
-0
lines changed

2 files changed

+81
-0
lines changed

lib/line/bot/client.rb

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -243,6 +243,36 @@ def get_rich_menu(rich_menu_id)
243243
get(endpoint_path)
244244
end
245245

246+
# Gets the number of messages sent with the /bot/message/reply endpoint.
247+
#
248+
# @param date [String] Date the messages were sent (format: yyyyMMdd)
249+
#
250+
# @return [Net::HTTPResponse]
251+
def get_message_delivery_reply(date)
252+
endpoint_path = "/bot/message/delivery/reply?date=#{date}"
253+
get(endpoint_path)
254+
end
255+
256+
# Gets the number of messages sent with the /bot/message/push endpoint.
257+
#
258+
# @param date [String] Date the messages were sent (format: yyyyMMdd)
259+
#
260+
# @return [Net::HTTPResponse]
261+
def get_message_delivery_push(date)
262+
endpoint_path = "/bot/message/delivery/push?date=#{date}"
263+
get(endpoint_path)
264+
end
265+
266+
# Gets the number of messages sent with the /bot/message/multicast endpoint.
267+
#
268+
# @param date [String] Date the messages were sent (format: yyyyMMdd)
269+
#
270+
# @return [Net::HTTPResponse]
271+
def get_message_delivery_multicast(date)
272+
endpoint_path = "/bot/message/delivery/multicast?date=#{date}"
273+
get(endpoint_path)
274+
end
275+
246276
# Create a rich menu
247277
#
248278
# @param rich_menu [Hash] The rich menu represented as a rich menu object

spec/line/bot/client_get_spec.rb

Lines changed: 51 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,13 @@
2020
}
2121
EOS
2222

23+
DELIVERY_NUMBER_CONTENT = <<"EOS"
24+
{
25+
"status": "ready",
26+
"success": 1
27+
}
28+
EOS
29+
2330
WebMock.allow_net_connect!
2431

2532
describe Line::Bot::Client do
@@ -76,4 +83,48 @@ def generate_client
7683
contact = JSON.parse(response.body)
7784
expect(contact['displayName']).to eq "Brown"
7885
end
86+
87+
it "gets the number of reply messages sent" do
88+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/reply?date={sended_date}'
89+
stub_request(:get, uri_template).to_return(body: DELIVERY_NUMBER_CONTENT, status: 200)
90+
91+
client = generate_client
92+
response = client.get_message_delivery_reply("20190101")
93+
94+
delivery = JSON.parse(response.body)
95+
expect(delivery['status']).to eq "ready"
96+
expect(delivery['success']).to eq 1
97+
end
98+
99+
it "gets the number of push messages sent" do
100+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/push?date={sended_date}'
101+
stub_request(:get, uri_template).to_return(body: DELIVERY_NUMBER_CONTENT, status: 200)
102+
103+
client = generate_client
104+
response = client.get_message_delivery_push("20190101")
105+
106+
delivery = JSON.parse(response.body)
107+
expect(delivery['status']).to eq "ready"
108+
expect(delivery['success']).to eq 1
109+
end
110+
111+
it "gets the number of multicast messages sent" do
112+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/message/delivery/multicast?date={send_date}'
113+
stub_request(:get, uri_template).to_return(body: DELIVERY_NUMBER_CONTENT, status: 200)
114+
115+
client = generate_client
116+
response = client.get_message_delivery_multicast("20190101")
117+
118+
delivery = JSON.parse(response.body)
119+
expect(delivery['status']).to eq "ready"
120+
expect(delivery['success']).to eq 1
121+
end
122+
123+
it "gets number of messages sent whithout date will raise error" do
124+
client = generate_client
125+
126+
expect { client.get_message_delivery_reply }.to raise_error(ArgumentError)
127+
expect { client.get_message_delivery_push }.to raise_error(ArgumentError)
128+
expect { client.get_message_delivery_multicast }.to raise_error(ArgumentError)
129+
end
79130
end

0 commit comments

Comments
 (0)