Class: Line::Bot::V2::Module::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/v2/module/api/line_module_client.rb

Instance Method Summary collapse

Constructor Details

#initialize(base_url: nil, channel_access_token:, http_options: {}) ⇒ ApiClient

Initializes a new Line::Bot::V2::Module::ApiClient instance.

Examples:

@client ||= Line::Bot::V2::Module::ApiClient.new(
  channel_access_token: "YOUR_CHANNEL_ACCESS_TOKEN",
  http_options: {
    open_timeout: 5,
    read_timeout: 5,
  }
)

Parameters:

  • base_url (String) (defaults to: nil)

    The base URL for requests (optional). Defaults to ‘api.line.me’ if none is provided. You can override this for testing or to use a mock server.

  • channel_access_token (String)

    The channel access token for authorization.

  • http_options (Hash) (defaults to: {})

    HTTP options (same as Net::HTTP options). See: docs.ruby-lang.org/en/3.4/Net/HTTP.html to understand the options.



38
39
40
41
42
43
44
45
46
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 38

def initialize(base_url: nil, channel_access_token:, http_options: {})
  @http_client = HttpClient.new(
    base_url: base_url || 'https://api.line.me',
    http_headers: {
      Authorization: "Bearer #{channel_access_token}"
    },
    http_options: http_options
  )
end

Instance Method Details

#acquire_chat_control(chat_id:, acquire_chat_control_request: nil) ⇒ String?

If the Standby Channel wants to take the initiative (Chat Control), it calls the Acquire Control API. The channel that was previously an Active Channel will automatically switch to a Standby Channel. This requests to POST https://api.line.me/v2/bot/chat/{chatId}/control/acquire When you want to get HTTP status code or response headers, use #acquire_chat_control_with_http_info instead of this.

Parameters:

  • chat_id (String)

    The ‘userId`, `roomId`, or `groupId`

  • acquire_chat_control_request (AcquireChatControlRequest, nil) (defaults to: nil)

Returns:

  • (String, nil)

    when HTTP status code is 200

  • (String, nil)

    when other HTTP status code is returned. This String is HTTP response body itself.

See Also:



86
87
88
89
90
91
92
93
94
95
96
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 86

def acquire_chat_control(
  chat_id:,
  acquire_chat_control_request: nil
)
  response_body, _status_code, _headers = acquire_chat_control_with_http_info(
    chat_id: chat_id,
    acquire_chat_control_request: acquire_chat_control_request
  )

  response_body
end

#acquire_chat_control_with_http_info(chat_id:, acquire_chat_control_request: nil) ⇒ Array((String|nil), Integer, Hash{String => String})

If the Standby Channel wants to take the initiative (Chat Control), it calls the Acquire Control API. The channel that was previously an Active Channel will automatically switch to a Standby Channel. This requests to POST https://api.line.me/v2/bot/chat/{chatId}/control/acquire This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • chat_id (String)

    The ‘userId`, `roomId`, or `groupId`

  • acquire_chat_control_request (AcquireChatControlRequest, nil) (defaults to: nil)

Returns:

  • (Array((String|nil), Integer, Hash{String => String}))

    when HTTP status code is 200

  • (Array((String|nil), Integer, Hash{String => String}))

    when other HTTP status code is returned. String is HTTP response body itself.

See Also:



57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 57

def acquire_chat_control_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  chat_id:, 
  acquire_chat_control_request: nil
)
  path = "/v2/bot/chat/{chatId}/control/acquire"
    .gsub(/{chatId}/, chat_id.to_s)

  response = @http_client.post(
    path: path,
    body_params: acquire_chat_control_request,
  )

  case response.code.to_i
  when 200
    [response.body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#detach_module(detach_module_request: nil) ⇒ String?

The module channel admin calls the Detach API to detach the module channel from a LINE Official Account. This requests to POST https://api.line.me/v2/bot/channel/detach When you want to get HTTP status code or response headers, use #detach_module_with_http_info instead of this.

Parameters:

Returns:

  • (String, nil)

    when HTTP status code is 200

  • (String, nil)

    when other HTTP status code is returned. This String is HTTP response body itself.

See Also:



132
133
134
135
136
137
138
139
140
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 132

def detach_module(
  detach_module_request: nil
)
  response_body, _status_code, _headers = detach_module_with_http_info(
    detach_module_request: detach_module_request
  )

  response_body
end

#detach_module_with_http_info(detach_module_request: nil) ⇒ Array((String|nil), Integer, Hash{String => String})

The module channel admin calls the Detach API to detach the module channel from a LINE Official Account. This requests to POST https://api.line.me/v2/bot/channel/detach This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

Returns:

  • (Array((String|nil), Integer, Hash{String => String}))

    when HTTP status code is 200

  • (Array((String|nil), Integer, Hash{String => String}))

    when other HTTP status code is returned. String is HTTP response body itself.

See Also:



106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 106

def detach_module_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  detach_module_request: nil
)
  path = "/v2/bot/channel/detach"

  response = @http_client.post(
    path: path,
    body_params: detach_module_request,
  )

  case response.code.to_i
  when 200
    [response.body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_modules(start: nil, limit: nil) ⇒ Line::Bot::V2::Module::GetModulesResponse, ...

Gets a list of basic information about the bots of multiple LINE Official Accounts that have attached module channels. This requests to GET https://api.line.me/v2/bot/list When you want to get HTTP status code or response headers, use #get_modules_with_http_info instead of this.

Parameters:

  • start (String, nil) (defaults to: nil)

    Value of the continuation token found in the next property of the JSON object returned in the response. If you can’t get all basic information about the bots in one request, include this parameter to get the remaining array.

  • limit (Integer, nil) (defaults to: nil)

    Specify the maximum number of bots that you get basic information from. The default value is 100. Max value: 100

Returns:

See Also:



188
189
190
191
192
193
194
195
196
197
198
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 188

def get_modules(
  start: nil,
  limit: nil
)
  response_body, _status_code, _headers = get_modules_with_http_info(
    start: start,
    limit: limit
  )

  response_body
end

#get_modules_with_http_info(start: nil, limit: nil) ⇒ Array(Line::Bot::V2::Module::GetModulesResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Gets a list of basic information about the bots of multiple LINE Official Accounts that have attached module channels. This requests to GET https://api.line.me/v2/bot/list This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • start (String, nil) (defaults to: nil)

    Value of the continuation token found in the next property of the JSON object returned in the response. If you can’t get all basic information about the bots in one request, include this parameter to get the remaining array.

  • limit (Integer, nil) (defaults to: nil)

    Specify the maximum number of bots that you get basic information from. The default value is 100. Max value: 100

Returns:

  • (Array(Line::Bot::V2::Module::GetModulesResponse, Integer, Hash{String => String}))

    when HTTP status code is 200

  • (Array((String|nil), Integer, Hash{String => String}))

    when other HTTP status code is returned. String is HTTP response body itself.

See Also:



151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 151

def get_modules_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  start: nil, 
  limit: nil
)
  path = "/v2/bot/list"
  query_params = {
    "start": start,
    "limit": limit
  }.compact

  response = @http_client.get(
    path: path,
    query_params: query_params,
  )

  case response.code.to_i
  when 200
    json = Line::Bot::V2::Utils.deep_underscore(JSON.parse(response.body))
    json.transform_keys! do |key|
      Line::Bot::V2::RESERVED_WORDS.include?(key) ? "_#{key}".to_sym : key
    end
    response_body = Line::Bot::V2::Module::GetModulesResponse.create(json) # steep:ignore InsufficientKeywordArguments
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#release_chat_control(chat_id:) ⇒ String?

To return the initiative (Chat Control) of Active Channel to Primary Channel, call the Release Control API. This requests to POST https://api.line.me/v2/bot/chat/{chatId}/control/release When you want to get HTTP status code or response headers, use #release_chat_control_with_http_info instead of this.

Parameters:

  • chat_id (String)

    The ‘userId`, `roomId`, or `groupId`

Returns:

  • (String, nil)

    when HTTP status code is 200

  • (String, nil)

    when other HTTP status code is returned. This String is HTTP response body itself.

See Also:



234
235
236
237
238
239
240
241
242
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 234

def release_chat_control(
  chat_id:
)
  response_body, _status_code, _headers = release_chat_control_with_http_info(
    chat_id: chat_id
  )

  response_body
end

#release_chat_control_with_http_info(chat_id:) ⇒ Array((String|nil), Integer, Hash{String => String})

To return the initiative (Chat Control) of Active Channel to Primary Channel, call the Release Control API. This requests to POST https://api.line.me/v2/bot/chat/{chatId}/control/release This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • chat_id (String)

    The ‘userId`, `roomId`, or `groupId`

Returns:

  • (Array((String|nil), Integer, Hash{String => String}))

    when HTTP status code is 200

  • (Array((String|nil), Integer, Hash{String => String}))

    when other HTTP status code is returned. String is HTTP response body itself.

See Also:



208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
# File 'lib/line/bot/v2/module/api/line_module_client.rb', line 208

def release_chat_control_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  chat_id:
)
  path = "/v2/bot/chat/{chatId}/control/release"
    .gsub(/{chatId}/, chat_id.to_s)

  response = @http_client.post(
    path: path,
  )

  case response.code.to_i
  when 200
    [response.body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end