@@ -54,6 +54,9 @@ You can code with type support in the corresponding IDE or editor.
5454
5555### Basic Usage
5656
57+ The unified ` Line::Bot::V2::Client ` wraps all individual API clients into a single object.
58+ You no longer need to create separate clients for MessagingApi, Insight, Liff, etc.
59+
5760``` ruby
5861# app.rb
5962require ' sinatra'
@@ -62,13 +65,7 @@ require 'line-bot-api'
6265set :environment , :production
6366
6467def client
65- @client ||= Line ::Bot ::V2 ::MessagingApi ::ApiClient .new (
66- channel_access_token: ENV .fetch(" LINE_CHANNEL_ACCESS_TOKEN" )
67- )
68- end
69-
70- def blob_client
71- @blob_client ||= Line ::Bot ::V2 ::MessagingApi ::ApiBlobClient .new (
68+ @client ||= Line ::Bot ::V2 ::Client .new (
7269 channel_access_token: ENV .fetch(" LINE_CHANNEL_ACCESS_TOKEN" )
7370 )
7471end
@@ -109,9 +106,9 @@ post '/callback' do
109106 )
110107 client.reply_message(reply_message_request: request)
111108 end
112-
109+
113110 when Line ::Bot ::V2 ::Webhook ::ImageMessageContent , Line ::Bot ::V2 ::Webhook ::VideoMessageContent
114- response = blob_client .get_message_content(message_id: event.message.message_id)
111+ response = client .get_message_content(message_id: event.message.message_id)
115112 tf = Tempfile .open (" content" )
116113 tf.write(response)
117114 end
@@ -123,6 +120,9 @@ post '/callback' do
123120end
124121```
125122
123+ > ** Note:** You can still use the individual clients (e.g. ` Line::Bot::V2::MessagingApi::ApiClient ` ) if you prefer.
124+ > For channel access token operations, use ` Line::Bot::V2::ChannelAccessToken::ApiClient ` directly.
125+
126126### Main classes
127127You may use this classes to use LINE Messaging API features.
128128
@@ -132,6 +132,26 @@ You may use this classes to use LINE Messaging API features.
132132
133133### Clients
134134
135+ #### Unified Client (recommended)
136+
137+ ` Line::Bot::V2::Client ` wraps all API clients below (except ChannelAccessToken and ModuleAttach) into one object.
138+ You only need a single ` channel_access_token ` to call any API.
139+
140+ ``` ruby
141+ client = Line ::Bot ::V2 ::Client .new (
142+ channel_access_token: ENV .fetch(" LINE_CHANNEL_ACCESS_TOKEN" )
143+ )
144+
145+ # MessagingApi, Insight, Liff, ManageAudience, Module, Shop — all available:
146+ client.push_message(push_message_request: request)
147+ client.get_number_of_followers(date: ' 20240101' )
148+ client.get_message_content(message_id: ' 12345' )
149+ ```
150+
151+ #### Individual Clients
152+
153+ You can also use the individual clients directly if you need finer control.
154+
135155| Class(YARD documentation) | API EndPoint | LINE Developers |
136156| ----------------------------------------------------------------------------------------------------------------------------------------| ---------------------------------------------------| --------------------------------------------------------------------------------------------------------------------|
137157| [ Line::Bot::V2::ChannelAccessToken::ApiClient] ( https://line.github.io/line-bot-sdk-ruby/Line/Bot/V2/ChannelAccessToken/ApiClient.html ) | https://api.line.me/ ** (related to oauth) | https://developers.line.biz/en/reference/messaging-api/#channel-access-token |
@@ -173,7 +193,7 @@ require 'json'
173193require ' line-bot-api'
174194
175195def client
176- @client ||= Line ::Bot ::V2 ::MessagingApi :: ApiClient .new (
196+ @client ||= Line ::Bot ::V2 ::Client .new (
177197 channel_access_token: ENV .fetch(" LINE_CHANNEL_ACCESS_TOKEN" ),
178198 )
179199end
@@ -219,7 +239,7 @@ This is useful, for example, in migrating from v1 or building Flex Message.
219239** But this is not recommended because you lose type checking by RBS.**
220240
221241``` ruby
222- client = Line ::Bot ::V2 ::MessagingApi :: ApiClient .new (
242+ client = Line ::Bot ::V2 ::Client .new (
223243 channel_access_token: ENV .fetch(" LINE_CHANNEL_ACCESS_TOKEN" ),
224244)
225245
0 commit comments