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

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

Instance Method Summary collapse

Constructor Details

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

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 ‘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/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( # steep:ignore MethodBodyTypeMismatch
)
  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) # 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

#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( # steep:ignore MethodBodyTypeMismatch 
  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) # 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

#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( # steep:ignore MethodBodyTypeMismatch 
  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) # 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

#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( # steep:ignore MethodBodyTypeMismatch 
  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) # 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

#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:



297
298
299
300
301
302
303
304
305
306
307
308
309
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 297

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:



257
258
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
# File 'lib/line/bot/v2/insight/api/insight_client.rb', line 257

def get_statistics_per_unit_with_http_info( # steep:ignore MethodBodyTypeMismatch 
  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) # 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