Skip to content

Commit f5517fc

Browse files
committed
backward compatible
1 parent b248a3c commit f5517fc

File tree

2 files changed

+33
-1
lines changed

2 files changed

+33
-1
lines changed

lib/line/bot/client.rb

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,16 @@ def endpoint
5050
end
5151

5252
def blob_endpoint
53-
@blob_endpoint ||= Line::Bot::API::DEFAULT_BLOB_ENDPOINT
53+
unless @blob_endpoint
54+
if endpoint == Line::Bot::API::DEFAULT_ENDPOINT
55+
@blob_endpoint = Line::Bot::API::DEFAULT_BLOB_ENDPOINT
56+
else
57+
# for backward compatible
58+
@blob_endpoint = endpoint
59+
end
60+
end
61+
62+
@blob_endpoint
5463
end
5564

5665
# @return [Hash]

spec/line/bot/client_spec.rb

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,29 @@ def generate_client
3939
stub_request(:post, Line::Bot::API::DEFAULT_ENDPOINT).to_return { |request| {body: request.body, status: 200} }
4040
end
4141

42+
it 'default endpoint' do
43+
client = Line::Bot::Client.new
44+
expect(client.endpoint).to eq Line::Bot::API::DEFAULT_ENDPOINT
45+
expect(client.blob_endpoint).to eq Line::Bot::API::DEFAULT_BLOB_ENDPOINT
46+
end
47+
48+
it 'rewrite endpoint' do
49+
client = Line::Bot::Client.new do |config|
50+
config.endpoint = 'https://example.com/api/v1'
51+
config.blob_endpoint = 'https://example.com/api-data/v1'
52+
end
53+
expect(client.endpoint).to eq 'https://example.com/api/v1'
54+
expect(client.blob_endpoint).to eq 'https://example.com/api-data/v1'
55+
end
56+
57+
it 'rewrite endpoint and backward compatible' do
58+
client = Line::Bot::Client.new do |config|
59+
config.endpoint = 'https://example.com/api/v1'
60+
end
61+
expect(client.endpoint).to eq 'https://example.com/api/v1'
62+
expect(client.blob_endpoint).to eq 'https://example.com/api/v1' # rewrited
63+
end
64+
4265
it 'checks credentials on creating a client' do
4366
channel_token = dummy_config[:channel_token]
4467
client = Line::Bot::Client.new do |config|

0 commit comments

Comments
 (0)