Skip to content

Commit 0e395fb

Browse files
authored
Add comments for clients (#468)
This change adds comments for sdk users in code related to the client. (1) The internal HTTP client is exposed, but this change adds caution against using it. If a breaking change is made to this, the version will be raised, ignoring semver. (2) For the user-facing HTTP client, this change adds comments with examples using YARD. Comments on the class methods will be improved in a separate PR.
1 parent 1e72402 commit 0e395fb

13 files changed

Lines changed: 222 additions & 0 deletions

File tree

generator/src/main/resources/line-bot-sdk-ruby-generator/api.pebble

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,33 @@ module Line
1313
module V2
1414
module {{ packageName | camelize }}
1515
class Api{{ operations.classname.indexOf('Blob') != -1 ? 'Blob' : '' }}Client
16+
# Initializes a new {Line::Bot::V2::{{ packageName | camelize }}::Api{{ operations.classname.indexOf('Blob') != -1 ? 'Blob' : '' }}Client} instance.
17+
#
18+
# @param base_url [String] The base URL for requests (optional).
19+
# Defaults to '{{endpoint(operations.classname)}}' if none is provided.
20+
# You can override this for testing or to use a mock server.
21+
{%- if packageName == 'module_attach' %}
22+
# @param channel_id [String] The channel ID for Basic authentication.
23+
# @param channel_secret [String] The channel secret for Basic authentication.
24+
{%- elseif packageName != 'channel_access_token' %}
25+
# @param channel_access_token [String] The channel access token for authorization.
26+
{%- endif %}
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::{{ packageName | camelize }}::Api{{ operations.classname.indexOf('Blob') != -1 ? 'Blob' : '' }}Client.new(
32+
{%- if packageName == 'module_attach' %}
33+
# channel_id: "YOUR_CHANNEL_ID",
34+
# channel_secret: "YOUR_CHANNEL_SECRET",
35+
{%- elseif packageName != 'channel_access_token' %}
36+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
37+
{%- endif %}
38+
# http_options: {
39+
# open_timeout: 5,
40+
# read_timeout: 5,
41+
# }
42+
# )
1643
def initialize(base_url: nil{% if packageName == 'channel_access_token' %}{% elseif packageName == 'module_attach' %}, channel_id:, channel_secret:{% else %}, channel_access_token:{% endif %}, http_options: {})
1744
@http_client = HttpClient.new(
1845
base_url: base_url || '{{endpoint(operations.classname)}}'{% if packageName == 'channel_access_token' %}{% elseif packageName == 'module_attach' %},

lib/line/bot/v2/channel_access_token/api/channel_access_token_client.rb

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,21 @@ module Bot
1818
module V2
1919
module ChannelAccessToken
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::ChannelAccessToken::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
27+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
28+
#
29+
# @example
30+
# @client ||= Line::Bot::V2::ChannelAccessToken::ApiClient.new(
31+
# http_options: {
32+
# open_timeout: 5,
33+
# read_timeout: 5,
34+
# }
35+
# )
2136
def initialize(base_url: nil, http_options: {})
2237
@http_client = HttpClient.new(
2338
base_url: base_url || 'https://api.line.me',

lib/line/bot/v2/http_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,43 +6,60 @@
66
module Line
77
module Bot
88
module V2
9+
# This class is not intended for line-bot-sdk-ruby users. Breaking changes may occur; use at your own risk.
10+
911
class HttpClient
12+
# Initializes a new HttpClient instance.
13+
#
14+
# @param base_url [String] The base URL for requests.
15+
# @param http_headers [Hash] The default HTTP headers.
16+
# @param http_options [Hash] The HTTP options (same as Net::HTTP options).
17+
# https://docs.ruby-lang.org/en/3.4/Net/HTTP.html#method-i-options
18+
#
19+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
1020
def initialize(base_url:, http_headers: {}, http_options: {})
1121
@base_url = base_url
1222
@http_headers = { 'User-Agent' => "LINE-BotSDK-Ruby/#{Line::Bot::V2::VERSION}" }.merge(http_headers)
1323
@http_options = http_options
1424
end
1525

26+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
1627
def get(path:, query_params: nil, headers: nil)
1728
request = build_request(Net::HTTP::Get, path, query_params, headers)
1829
perform_request(request)
1930
end
2031

32+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
2133
def post(path:, query_params: nil, body_params: nil, headers: nil)
2234
request = build_request(Net::HTTP::Post, path, query_params, headers, body_params)
2335
perform_request(request)
2436
end
2537

38+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
2639
def put(path:, query_params: nil, body_params: nil, headers: nil)
2740
request = build_request(Net::HTTP::Put, path, query_params, headers, body_params)
2841
perform_request(request)
2942
end
3043

44+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
3145
def delete(path:, query_params: nil, headers: nil)
3246
request = build_request(Net::HTTP::Delete, path, query_params, headers)
3347
perform_request(request)
3448
end
3549

50+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
3651
def post_form(path:, query_params: nil, form_params: nil, headers: nil)
3752
request = build_form_request(Net::HTTP::Post, path, query_params, form_params, headers)
3853
perform_request(request)
3954
end
4055

56+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
4157
def post_form_multipart(path:, query_params: nil, form_params: nil, headers: nil)
4258
request = build_multipart_request(Net::HTTP::Post::Multipart, path, query_params, form_params, headers)
4359
perform_request(request)
4460
end
4561

62+
# NOTE: line-bot-sdk-ruby users should not use this. Breaking changes may occur, so use at your own risk.
4663
def put_form_multipart(path:, query_params: nil, form_params: nil, headers: nil)
4764
request = build_multipart_request(Net::HTTP::Put::Multipart, path, query_params, form_params, headers)
4865
perform_request(request)

lib/line/bot/v2/insight/api/insight_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module Insight
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::Insight::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::Insight::ApiClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api.line.me',

lib/line/bot/v2/liff/api/liff_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module Liff
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::Liff::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::Liff::ApiClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api.line.me',

lib/line/bot/v2/manage_audience/api/manage_audience_blob_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module ManageAudience
2020
class ApiBlobClient
21+
# Initializes a new {Line::Bot::V2::ManageAudience::ApiBlobClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api-data.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::ManageAudience::ApiBlobClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api-data.line.me',

lib/line/bot/v2/manage_audience/api/manage_audience_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module ManageAudience
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::ManageAudience::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::ManageAudience::ApiClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api.line.me',

lib/line/bot/v2/messaging_api/api/messaging_api_blob_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module MessagingApi
2020
class ApiBlobClient
21+
# Initializes a new {Line::Bot::V2::MessagingApi::ApiBlobClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api-data.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::MessagingApi::ApiBlobClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api-data.line.me',

lib/line/bot/v2/messaging_api/api/messaging_api_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module MessagingApi
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::MessagingApi::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::MessagingApi::ApiClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api.line.me',

lib/line/bot/v2/module/api/line_module_client.rb

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,23 @@ module Bot
1818
module V2
1919
module Module
2020
class ApiClient
21+
# Initializes a new {Line::Bot::V2::Module::ApiClient} instance.
22+
#
23+
# @param base_url [String] The base URL for requests (optional).
24+
# Defaults to 'https://api.line.me' if none is provided.
25+
# You can override this for testing or to use a mock server.
26+
# @param channel_access_token [String] The channel access token for authorization.
27+
# @param http_options [Hash] HTTP options (same as Net::HTTP options).
28+
# See: https://docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.
29+
#
30+
# @example
31+
# @client ||= Line::Bot::V2::Module::ApiClient.new(
32+
# channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
33+
# http_options: {
34+
# open_timeout: 5,
35+
# read_timeout: 5,
36+
# }
37+
# )
2138
def initialize(base_url: nil, channel_access_token:, http_options: {})
2239
@http_client = HttpClient.new(
2340
base_url: base_url || 'https://api.line.me',

0 commit comments

Comments
 (0)