Skip to content

Commit 2312ea5

Browse files
committed
NO-ISSUE upd
1 parent 0c43ce6 commit 2312ea5

6 files changed

Lines changed: 38 additions & 10 deletions

File tree

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -122,6 +122,7 @@ end
122122

123123
> **Note:** You can still use the individual clients (e.g. `Line::Bot::V2::MessagingApi::ApiClient`) if you prefer.
124124
> For channel access token operations, use `Line::Bot::V2::ChannelAccessToken::ApiClient` directly.
125+
> For module attach operations, use `Line::Bot::V2::ModuleAttach::ApiClient` directly.
125126
126127
### Main classes
127128
You may use this classes to use LINE Messaging API features.

lib/line/bot/v2/client.rb

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,13 @@
1515
module Line
1616
module Bot
1717
module V2
18-
# A single client for all LINE Bot APIs, except channel access token management.
18+
# A single client for all LINE Bot APIs, except channel access token and module attach management.
1919
#
2020
# It wraps the individual generated API clients and exposes their methods directly,
2121
# so callers can work with one object instead of juggling several client instances.
2222
#
2323
# For channel access token operations, use {Line::Bot::V2::ChannelAccessToken::ApiClient} directly.
24+
# For module attach operations, use {Line::Bot::V2::ModuleAttach::ApiClient} directly.
2425
class Client
2526
# @param channel_access_token [String] Channel access token issued for your LINE Official Account.
2627
# @param api_base_url [String, nil] Base URL for Messaging API style endpoints. Defaults to https://api.line.me.

migration_from_v1_to_v2_guide.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@ However, it's not recommended to always use it as it could lead to migration err
4747
## Clients
4848

4949
### Unified Client (recommended)
50-
`Line::Bot::V2::Client` wraps all API clients into a single object. You only need one client for MessagingApi, Insight, Liff, ManageAudience, Module, and Shop.
50+
`Line::Bot::V2::Client` wraps supported API clients into a single object. ChannelAccessToken and ModuleAttach are not included; use their individual clients directly.
5151

5252
```rb
5353
client = Line::Bot::V2::Client.new(
@@ -71,6 +71,7 @@ You can also use individual clients directly. There are several types depending
7171
and so on.
7272

7373
For channel access token operations, use `Line::Bot::V2::ChannelAccessToken::ApiClient` directly (not included in the unified client).
74+
For module attach operations, use `Line::Bot::V2::ModuleAttach::ApiClient` directly (not included in the unified client).
7475

7576

7677
## Migration examples

scripts/unified-client-generator/main.rb

Lines changed: 17 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,12 +20,13 @@ module UnifiedClientGenerator
2020
BUILTINS = Set['Array', 'File', 'Float', 'Hash', 'Integer', 'Object', 'String', 'Symbol'].freeze
2121

2222
CLIENT_CLASS_COMMENT = <<~COMMENT
23-
A single client for all LINE Bot APIs, except channel access token management.
23+
A single client for all LINE Bot APIs, except channel access token and module attach management.
2424
2525
It wraps the individual generated API clients and exposes their methods directly,
2626
so callers can work with one object instead of juggling several client instances.
2727
2828
For channel access token operations, use {Line::Bot::V2::ChannelAccessToken::ApiClient} directly.
29+
For module attach operations, use {Line::Bot::V2::ModuleAttach::ApiClient} directly.
2930
COMMENT
3031

3132
CLIENT_INITIALIZE_COMMENT = <<~COMMENT
@@ -74,16 +75,30 @@ def run(root_dir = File.expand_path('../..', __dir__))
7475

7576
# --- Validation ---
7677

78+
SUPPORTED_BASE_URLS = Set['https://api.line.me', 'https://api-data.line.me'].freeze
79+
7780
def validate_clients!(clients)
7881
raise 'No client files were found.' if clients.empty?
7982

8083
check_collisions!('Delegate name', clients.map(&:delegate_name))
8184
check_collisions!('Method name', clients.flat_map { |c| c.delegated_methods.map(&:name) })
8285

8386
allowed = Set['base_url', 'channel_access_token', 'http_options']
87+
8488
clients.each do |c|
85-
extra = Set.new(c.constructor_required_keywords + c.constructor_optional_keywords) - allowed
89+
req = Set.new(c.constructor_required_keywords)
90+
opt = Set.new(c.constructor_optional_keywords)
91+
all = req | opt
92+
93+
extra = all - allowed
8694
raise "Unsupported constructor keys in #{c.qualified_class_name}: #{extra.to_a.join(', ')}" unless extra.empty?
95+
96+
raise "Missing channel_access_token in #{c.qualified_class_name}" unless all.include?('channel_access_token')
97+
98+
unless SUPPORTED_BASE_URLS.include?(c.default_base_url)
99+
raise "Unsupported default_base_url #{c.default_base_url.inspect} in #{c.qualified_class_name}. " \
100+
"Supported: #{SUPPORTED_BASE_URLS.to_a.join(', ')}"
101+
end
87102
end
88103
end
89104

scripts/unified-client-generator/renderer.rb

Lines changed: 14 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -106,14 +106,23 @@ def build_generated_delegates(
106106
RUBY
107107
end
108108

109+
BASE_URL_MAP = {
110+
'https://api.line.me' => 'api_base_url',
111+
'https://api-data.line.me' => 'data_api_base_url'
112+
}.freeze
113+
109114
def render_factory_assignment(client)
110-
base_url_kw = { 'https://api.line.me' => 'api_base_url',
111-
'https://api-data.line.me' => 'data_api_base_url' }[client.default_base_url]
115+
base_url_kw = BASE_URL_MAP[client.default_base_url]
116+
117+
supports = lambda do |key|
118+
client.constructor_required_keywords.include?(key) ||
119+
client.constructor_optional_keywords.include?(key)
120+
end
112121

113122
args = []
114-
args << "base_url: #{base_url_kw}" if client.constructor_optional_keywords.include?('base_url') && base_url_kw
115-
args << 'channel_access_token: channel_access_token' if client.constructor_required_keywords.include?('channel_access_token')
116-
args << 'http_options: http_options' if client.constructor_optional_keywords.include?('http_options')
123+
args << "base_url: #{base_url_kw}" if supports.call('base_url') && base_url_kw
124+
args << 'channel_access_token: channel_access_token' if supports.call('channel_access_token')
125+
args << 'http_options: http_options' if supports.call('http_options')
117126

118127
"#{client.ivar_name} = #{client.qualified_class_name}.\n new(#{args.join(', ')})"
119128
end

sig/line/bot/v2/client.rbs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,12 +7,13 @@ module Line
77
module Bot
88
module V2
99
class Client
10-
# A single client for all LINE Bot APIs, except channel access token management.
10+
# A single client for all LINE Bot APIs, except channel access token and module attach management.
1111
#
1212
# It wraps the individual generated API clients and exposes their methods directly,
1313
# so callers can work with one object instead of juggling several client instances.
1414
#
1515
# For channel access token operations, use {Line::Bot::V2::ChannelAccessToken::ApiClient} directly.
16+
# For module attach operations, use {Line::Bot::V2::ModuleAttach::ApiClient} directly.
1617
@insight: Line::Bot::V2::Insight::ApiClient
1718
@liff: Line::Bot::V2::Liff::ApiClient
1819
@manage_audience: Line::Bot::V2::ManageAudience::ApiClient

0 commit comments

Comments
 (0)