Skip to content

Commit e6f98c5

Browse files
committed
Merge branch 'master' into feature/member_join_and_leave_event
2 parents 4f9ddad + 04881af commit e6f98c5

File tree

11 files changed

+202
-4
lines changed

11 files changed

+202
-4
lines changed

.travis.yml

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,15 @@ rvm:
44
- 2.3
55
- 2.4
66
- 2.5
7+
- 2.6
78
- ruby-head
89
before_install:
9-
- gem install bundler
10+
- if [ ${TRAVIS_RUBY_VERSION} = '2.2' ]; then
11+
gem install bundler -v '< 2';
12+
else
13+
gem update --system;
14+
gem install bundler;
15+
fi
1016
script:
1117
- bundle exec rubocop
1218
- bundle exec rspec

lib/line-bot-api.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
require 'line/bot'

lib/line/bot/api/version.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
module Line
1616
module Bot
1717
module API
18-
VERSION = "1.3.0"
18+
VERSION = "1.6.0"
1919
end
2020
end
2121
end

lib/line/bot/client.rb

Lines changed: 54 additions & 1 deletion
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
@@ -280,6 +310,14 @@ def get_user_rich_menu(user_id)
280310
get(endpoint_path)
281311
end
282312

313+
# Get default rich menu
314+
#
315+
# @return [Net::HTTPResponse]
316+
def get_default_rich_menu
317+
endpoint_path = '/bot/user/all/richmenu'
318+
get(endpoint_path)
319+
end
320+
283321
# Set default rich menu (Link a rich menu to all user)
284322
#
285323
# @param rich_menu_id [String] ID of an uploaded rich menu
@@ -353,6 +391,16 @@ def create_rich_menu_image(rich_menu_id, file)
353391
request.post
354392
end
355393

394+
# Issue a link token to a user
395+
#
396+
# @param user_id [String] ID of the user
397+
#
398+
# @return [Net::HTTPResponse]
399+
def create_link_token(user_id)
400+
endpoint_path = "/bot/user/#{user_id}/linkToken"
401+
post(endpoint_path)
402+
end
403+
356404
# Fetch data, get content of specified URL.
357405
#
358406
# @param endpoint_path [String]
@@ -418,7 +466,7 @@ def parse_events_from(request_body)
418466

419467
json['events'].map { |item|
420468
begin
421-
klass = Line::Bot::Event.const_get(item['type'].capitalize)
469+
klass = Line::Bot::Event.const_get(camelize(item['type']))
422470
klass.new(item)
423471
rescue NameError => e
424472
Line::Bot::Event::Base.new(item)
@@ -462,6 +510,11 @@ def secure_compare(a, b)
462510
b.each_byte { |byte| res |= byte ^ l.shift }
463511
res == 0
464512
end
513+
514+
# @return [String]
515+
def camelize(string)
516+
string.split(/_|(?=[A-Z])/).map(&:capitalize).join
517+
end
465518
end
466519
end
467520
end

lib/line/bot/event.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@
1313
# under the License.
1414

1515
require 'line/bot/event/base'
16+
require 'line/bot/event/account_link'
1617
require 'line/bot/event/beacon'
1718
require 'line/bot/event/follow'
1819
require 'line/bot/event/join'

lib/line/bot/event/account_link.rb

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# Copyright 2016 LINE
2+
#
3+
# LINE Corporation licenses this file to you under the Apache License,
4+
# version 2.0 (the "License"); you may not use this file except in compliance
5+
# with the License. You may obtain a copy of the License at:
6+
#
7+
# http://www.apache.org/licenses/LICENSE-2.0
8+
#
9+
# Unless required by applicable law or agreed to in writing, software
10+
# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
11+
# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
12+
# License for the specific language governing permissions and limitations
13+
# under the License.
14+
15+
module Line
16+
module Bot
17+
module Event
18+
class AccountLink < Base
19+
def result
20+
@src['link']['result']
21+
end
22+
23+
def nonce
24+
@src['link']['nonce']
25+
end
26+
end
27+
end
28+
end
29+
end

line-bot-api.gemspec

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ Gem::Specification.new do |spec|
2020
spec.required_ruby_version = '>= 2.0.0'
2121

2222
spec.add_development_dependency "addressable", "~> 2.3"
23-
spec.add_development_dependency "bundler", "~> 1.11"
23+
spec.add_development_dependency "bundler", "~> 1.11" if RUBY_VERSION < "2.3"
2424
spec.add_development_dependency 'rake', "~> 10.4"
2525
spec.add_development_dependency "rspec", "~> 3.0"
2626
spec.add_development_dependency "webmock", "~> 1.24"

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={sent_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={sent_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

spec/line/bot/client_parse_spec.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -145,6 +145,19 @@
145145
"type": "enter",
146146
"dm": "1234567890abcdef"
147147
}
148+
},
149+
{
150+
"type": "accountLink",
151+
"replyToken": "replyToken",
152+
"source": {
153+
"type": "user",
154+
"userId": "userid"
155+
},
156+
"timestamp": 12345678901234,
157+
"link": {
158+
"result": "ok",
159+
"nonce": "nonce"
160+
}
148161
}
149162
]
150163
}
@@ -251,6 +264,10 @@ def generate_client
251264
expect(events[11].type).to eq("enter")
252265
expect(events[11]['beacon']['dm']).to eq("1234567890abcdef")
253266
expect(events[11].deviceMessage).to eq("\x12\x34\x56\x78\x90\xab\xcd\xef".b)
267+
268+
expect(events[12]).to be_a(Line::Bot::Event::AccountLink)
269+
expect(events[12].result).to eq("ok")
270+
expect(events[12].nonce).to eq("nonce")
254271
end
255272

256273
it 'parses unknown event' do

spec/line/bot/link_token_spec.rb

Lines changed: 31 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
require 'spec_helper'
2+
require 'webmock/rspec'
3+
require 'json'
4+
5+
LINK_TOKEN_CONTENT = <<"EOS"
6+
{
7+
"linkToken":"abcdefg0123456789"
8+
}
9+
EOS
10+
11+
WebMock.allow_net_connect!
12+
13+
describe Line::Bot::Client do
14+
let(:client) {
15+
dummy_config = {
16+
channel_token: 'access token',
17+
}
18+
Line::Bot::Client.new do |config|
19+
config.channel_token = dummy_config[:channel_token]
20+
end
21+
}
22+
23+
it 'issues a link token' do
24+
uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/user/{user_id}/linkToken'
25+
stub_request(:post, uri_template).to_return(body: LINK_TOKEN_CONTENT, status: 200)
26+
27+
response = client.create_link_token('user_id')
28+
expect(WebMock).to have_requested(:post, Line::Bot::API::DEFAULT_ENDPOINT + '/bot/user/user_id/linkToken')
29+
expect(response.body).to eq LINK_TOKEN_CONTENT
30+
end
31+
end

0 commit comments

Comments
 (0)