Class: Line::Bot::V2::Insight::ApiClient

Inherits:
Object
  • Object
show all
Defined in:
lib/line/bot/v2/insight/api/insight_client.rb,
sig/line/bot/v2/insight/api/insight_client.rbs

Instance Method Summary collapse

Constructor Details

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

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

Examples:

@client ||= Line::Bot::V2::Insight::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 'https://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: https://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/insight/api/insight_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

#get_friends_demographicsLine::Bot::V2::Insight::GetFriendsDemographicsResponse, ...

Retrieves the demographic attributes for a LINE Official Account's friends.You can only retrieve information about friends for LINE Official Accounts created by users in Japan (JP), Thailand (TH), Taiwan (TW) and Indonesia (ID). This requests to GET https://api.line.me/v2/bot/insight/demographic When you want to get HTTP status code or response headers, use {#get_friends_demographics_with_http_info} instead of this.

Returns:

See Also:



83
84
85
86
87
88
89
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 83

def get_friends_demographics(
)
  response_body, _status_code, _headers = get_friends_demographics_with_http_info(
  )

  response_body
end

#get_friends_demographics_with_http_infoArray(Line::Bot::V2::Insight::GetFriendsDemographicsResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Retrieves the demographic attributes for a LINE Official Account's friends.You can only retrieve information about friends for LINE Official Accounts created by users in Japan (JP), Thailand (TH), Taiwan (TW) and Indonesia (ID). This requests to GET https://api.line.me/v2/bot/insight/demographic This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Returns:

See Also:



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

def get_friends_demographics_with_http_info(
)
  path = "/v2/bot/insight/demographic"

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

  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::Insight::GetFriendsDemographicsResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_message_event(request_id:) ⇒ Line::Bot::V2::Insight::GetMessageEventResponse, ...

Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account. This requests to GET https://api.line.me/v2/bot/insight/message/event When you want to get HTTP status code or response headers, use {#get_message_event_with_http_info} instead of this.

Parameters:

  • request_id (String)

    Request ID of a narrowcast message or broadcast message. Each Messaging API request has a request ID.

Returns:

See Also:



133
134
135
136
137
138
139
140
141
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 133

def get_message_event(
  request_id:
)
  response_body, _status_code, _headers = get_message_event_with_http_info(
    request_id: request_id
  )

  response_body
end

#get_message_event_with_http_info(request_id:) ⇒ Array(Line::Bot::V2::Insight::GetMessageEventResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Returns statistics about how users interact with narrowcast messages or broadcast messages sent from your LINE Official Account. This requests to GET https://api.line.me/v2/bot/insight/message/event This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • request_id (String)

    Request ID of a narrowcast message or broadcast message. Each Messaging API request has a request ID.

Returns:

  • (Array(Line::Bot::V2::Insight::GetMessageEventResponse, 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:



99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 99

def get_message_event_with_http_info( 
  request_id:
)
  path = "/v2/bot/insight/message/event"
  query_params = {
    "requestId": request_id
  }.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::Insight::GetMessageEventResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_number_of_followers(date: nil) ⇒ Line::Bot::V2::Insight::GetNumberOfFollowersResponse, ...

Returns the number of users who have added the LINE Official Account on or before a specified date. This requests to GET https://api.line.me/v2/bot/insight/followers When you want to get HTTP status code or response headers, use {#get_number_of_followers_with_http_info} instead of this.

Parameters:

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

    Date for which to retrieve the number of followers. Format: yyyyMMdd (e.g. 20191231) Timezone: UTC+9

Returns:

See Also:



185
186
187
188
189
190
191
192
193
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 185

def get_number_of_followers(
  date: nil
)
  response_body, _status_code, _headers = get_number_of_followers_with_http_info(
    date: date
  )

  response_body
end

#get_number_of_followers_with_http_info(date: nil) ⇒ Array(Line::Bot::V2::Insight::GetNumberOfFollowersResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Returns the number of users who have added the LINE Official Account on or before a specified date. This requests to GET https://api.line.me/v2/bot/insight/followers This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

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

    Date for which to retrieve the number of followers. Format: yyyyMMdd (e.g. 20191231) Timezone: UTC+9

Returns:

  • (Array(Line::Bot::V2::Insight::GetNumberOfFollowersResponse, 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
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 151

def get_number_of_followers_with_http_info( 
  date: nil
)
  path = "/v2/bot/insight/followers"
  query_params = {
    "date": date
  }.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::Insight::GetNumberOfFollowersResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_number_of_message_deliveries(date:) ⇒ Line::Bot::V2::Insight::GetNumberOfMessageDeliveriesResponse, ...

Returns the number of messages sent from LINE Official Account on a specified day. This requests to GET https://api.line.me/v2/bot/insight/message/delivery When you want to get HTTP status code or response headers, use {#get_number_of_message_deliveries_with_http_info} instead of this.

Parameters:

  • date (String)

    Date for which to retrieve number of sent messages. - Format: yyyyMMdd (e.g. 20191231) - Timezone: UTC+9

Returns:

See Also:



237
238
239
240
241
242
243
244
245
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 237

def get_number_of_message_deliveries(
  date:
)
  response_body, _status_code, _headers = get_number_of_message_deliveries_with_http_info(
    date: date
  )

  response_body
end

#get_number_of_message_deliveries_with_http_info(date:) ⇒ Array(Line::Bot::V2::Insight::GetNumberOfMessageDeliveriesResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

Returns the number of messages sent from LINE Official Account on a specified day. This requests to GET https://api.line.me/v2/bot/insight/message/delivery This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • date (String)

    Date for which to retrieve number of sent messages. - Format: yyyyMMdd (e.g. 20191231) - Timezone: UTC+9

Returns:

See Also:



203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 203

def get_number_of_message_deliveries_with_http_info( 
  date:
)
  path = "/v2/bot/insight/message/delivery"
  query_params = {
    "date": date
  }.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::Insight::GetNumberOfMessageDeliveriesResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_rich_menu_insight_daily(rich_menu_id:, from:, to:) ⇒ Line::Bot::V2::Insight::GetRichMenuInsightDailyResponse, ...

Gets rich menu statistics broken down by day for the specified period, for a rich menu created via the Messaging API. Returns the daily impression count for the whole rich menu and the daily click count for each tappable area. When the total number of unique clicks during the period is below the privacy threshold, only richMenuId is returned and the other fields are omitted. This requests to GET https://api.line.me/v2/bot/insight/richmenu/richMenuId/daily When you want to get HTTP status code or response headers, use {#get_rich_menu_insight_daily_with_http_info} instead of this.

Parameters:

  • rich_menu_id (String)

    ID of the rich menu created via the Messaging API.

  • from (String)

    Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9

  • to (String)

    End date of the aggregation period (inclusive). The end date can be specified for up to 99 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9

Returns:

See Also:



316
317
318
319
320
321
322
323
324
325
326
327
328
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 316

def get_rich_menu_insight_daily(
  rich_menu_id:,
  from:,
  to:
)
  response_body, _status_code, _headers = get_rich_menu_insight_daily_with_http_info(
    rich_menu_id: rich_menu_id,
    from: from,
    to: to
  )

  response_body
end

#get_rich_menu_insight_daily_with_http_info(rich_menu_id:, from:, to:) ⇒ Array(Line::Bot::V2::Insight::GetRichMenuInsightDailyResponse, Integer, Hash{String => String}), ...

Gets rich menu statistics broken down by day for the specified period, for a rich menu created via the Messaging API. Returns the daily impression count for the whole rich menu and the daily click count for each tappable area. When the total number of unique clicks during the period is below the privacy threshold, only richMenuId is returned and the other fields are omitted. This requests to GET https://api.line.me/v2/bot/insight/richmenu/richMenuId/daily This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • rich_menu_id (String)

    ID of the rich menu created via the Messaging API.

  • from (String)

    Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9

  • to (String)

    End date of the aggregation period (inclusive). The end date can be specified for up to 99 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9

Returns:

See Also:



259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 259

def get_rich_menu_insight_daily_with_http_info( 
  rich_menu_id:, 
  from:, 
  to:
)
  path = Line::Bot::V2::Utils.build_path("/v2/bot/insight/richmenu/{richMenuId}/daily", {
    "richMenuId": rich_menu_id
  })
  query_params = {
    "from": from,
    "to": to
  }.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::Insight::GetRichMenuInsightDailyResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  when 400
    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::Insight::ErrorResponse.create(json)
    [response_body, 400, response.each_header.to_h]
  when 404
    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::Insight::ErrorResponse.create(json)
    [response_body, 404, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_rich_menu_insight_summary(rich_menu_id:, from:, to:) ⇒ Line::Bot::V2::Insight::GetRichMenuInsightSummaryResponse, ...

Gets a summary of rich menu statistics for the specified period, for a rich menu created via the Messaging API. Returns the total impression count for the whole rich menu and the click count for each tappable area, aggregated over the entire period as a single result. When the total number of unique clicks during the period is below the privacy threshold, only richMenuId is returned and the other fields are omitted. This requests to GET https://api.line.me/v2/bot/insight/richmenu/richMenuId/summary When you want to get HTTP status code or response headers, use {#get_rich_menu_insight_summary_with_http_info} instead of this.

Parameters:

  • rich_menu_id (String)

    ID of the rich menu created via the Messaging API.

  • from (String)

    Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9

  • to (String)

    End date of the aggregation period (inclusive). The end date can be specified for up to 396 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9

Returns:

See Also:



399
400
401
402
403
404
405
406
407
408
409
410
411
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 399

def get_rich_menu_insight_summary(
  rich_menu_id:,
  from:,
  to:
)
  response_body, _status_code, _headers = get_rich_menu_insight_summary_with_http_info(
    rich_menu_id: rich_menu_id,
    from: from,
    to: to
  )

  response_body
end

#get_rich_menu_insight_summary_with_http_info(rich_menu_id:, from:, to:) ⇒ Array(Line::Bot::V2::Insight::GetRichMenuInsightSummaryResponse, Integer, Hash{String => String}), ...

Gets a summary of rich menu statistics for the specified period, for a rich menu created via the Messaging API. Returns the total impression count for the whole rich menu and the click count for each tappable area, aggregated over the entire period as a single result. When the total number of unique clicks during the period is below the privacy threshold, only richMenuId is returned and the other fields are omitted. This requests to GET https://api.line.me/v2/bot/insight/richmenu/richMenuId/summary This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • rich_menu_id (String)

    ID of the rich menu created via the Messaging API.

  • from (String)

    Start date of the aggregation period (inclusive). Must be within the most recent 3 years. Format: yyyyMMdd (e.g. 20260213) Time zone: UTC+9

  • to (String)

    End date of the aggregation period (inclusive). The end date can be specified for up to 396 days after the start date. Format: yyyyMMdd (e.g. 20260215) Time zone: UTC+9

Returns:

See Also:



342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 342

def get_rich_menu_insight_summary_with_http_info( 
  rich_menu_id:, 
  from:, 
  to:
)
  path = Line::Bot::V2::Utils.build_path("/v2/bot/insight/richmenu/{richMenuId}/summary", {
    "richMenuId": rich_menu_id
  })
  query_params = {
    "from": from,
    "to": to
  }.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::Insight::GetRichMenuInsightSummaryResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  when 400
    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::Insight::ErrorResponse.create(json)
    [response_body, 400, response.each_header.to_h]
  when 404
    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::Insight::ErrorResponse.create(json)
    [response_body, 404, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end

#get_statistics_per_unit(custom_aggregation_unit:, from:, to:) ⇒ Line::Bot::V2::Insight::GetStatisticsPerUnitResponse, ...

You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account. This requests to GET https://api.line.me/v2/bot/insight/message/event/aggregation When you want to get HTTP status code or response headers, use {#get_statistics_per_unit_with_http_info} instead of this.

Parameters:

  • custom_aggregation_unit (String)

    Name of aggregation unit specified when sending the message. Case-sensitive. For example, Promotion_a and Promotion_A are regarded as different unit names.

  • from (String)

    Start date of aggregation period. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9

  • to (String)

    End date of aggregation period. The end date can be specified for up to 30 days later. For example, if the start date is 20210301, the latest end date is 20210331. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9

Returns:

See Also:



463
464
465
466
467
468
469
470
471
472
473
474
475
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 463

def get_statistics_per_unit(
  custom_aggregation_unit:,
  from:,
  to:
)
  response_body, _status_code, _headers = get_statistics_per_unit_with_http_info(
    custom_aggregation_unit: custom_aggregation_unit,
    from: from,
    to: to
  )

  response_body
end

#get_statistics_per_unit_with_http_info(custom_aggregation_unit:, from:, to:) ⇒ Array(Line::Bot::V2::Insight::GetStatisticsPerUnitResponse, Integer, Hash{String => String}), Array((String|nil), Integer, Hash{String => String})

You can check the per-unit statistics of how users interact with push messages and multicast messages sent from your LINE Official Account. This requests to GET https://api.line.me/v2/bot/insight/message/event/aggregation This returns an array containing response, HTTP status code, and header in order. Please specify all header keys in lowercase.

Parameters:

  • custom_aggregation_unit (String)

    Name of aggregation unit specified when sending the message. Case-sensitive. For example, Promotion_a and Promotion_A are regarded as different unit names.

  • from (String)

    Start date of aggregation period. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9

  • to (String)

    End date of aggregation period. The end date can be specified for up to 30 days later. For example, if the start date is 20210301, the latest end date is 20210331. Format: yyyyMMdd (e.g. 20210301) Time zone: UTC+9

Returns:

  • (Array(Line::Bot::V2::Insight::GetStatisticsPerUnitResponse, 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:



423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 423

def get_statistics_per_unit_with_http_info( 
  custom_aggregation_unit:, 
  from:, 
  to:
)
  path = "/v2/bot/insight/message/event/aggregation"
  query_params = {
    "customAggregationUnit": custom_aggregation_unit,
    "from": from,
    "to": to
  }.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::Insight::GetStatisticsPerUnitResponse.create(json)
    [response_body, 200, response.each_header.to_h]
  else
    [response.body, response.code.to_i, response.each_header.to_h]
  end
end