|
197 | 197 | end |
198 | 198 | end |
199 | 199 |
|
| 200 | + describe 'GET /v2/bot/insight/message/event/aggregation' do |
| 201 | + let(:client) { Line::Bot::V2::Insight::ApiClient.new(channel_access_token: channel_access_token) } |
| 202 | + let(:response_code) { 200 } |
| 203 | + |
| 204 | + it 'returns the message event aggregation successfully' do |
| 205 | + response_body = { |
| 206 | + "overview": { |
| 207 | + "uniqueImpression": 40, |
| 208 | + "uniqueClick": 30, |
| 209 | + "uniqueMediaPlayed": 25, |
| 210 | + "uniqueMediaPlayed100Percent": nil |
| 211 | + }, |
| 212 | + "messages": [ |
| 213 | + { |
| 214 | + "seq": 1, |
| 215 | + "impression": 42, |
| 216 | + "uniqueImpression": 40, |
| 217 | + "mediaPlayed": 30, |
| 218 | + "mediaPlayed25Percent": nil, |
| 219 | + "mediaPlayed50Percent": nil, |
| 220 | + "mediaPlayed75Percent": nil, |
| 221 | + "mediaPlayed100Percent": nil, |
| 222 | + "uniqueMediaPlayed": 25, |
| 223 | + "uniqueMediaPlayed25Percent": nil, |
| 224 | + "uniqueMediaPlayed50Percent": nil, |
| 225 | + "uniqueMediaPlayed75Percent": nil, |
| 226 | + "uniqueMediaPlayed100Percent": nil |
| 227 | + } |
| 228 | + ], |
| 229 | + "clicks": [ |
| 230 | + { |
| 231 | + "seq": 1, |
| 232 | + "url": "https://developers.line.biz/", |
| 233 | + "click": 35, |
| 234 | + "uniqueClick": 25, |
| 235 | + "uniqueClickOfRequest": nil |
| 236 | + }, |
| 237 | + { |
| 238 | + "seq": 1, |
| 239 | + "url": "https://lineapiusecase.com/", |
| 240 | + "click": 29, |
| 241 | + "uniqueClick": nil, |
| 242 | + "uniqueClickOfRequest": nil |
| 243 | + } |
| 244 | + ] |
| 245 | + }.to_json |
| 246 | + |
| 247 | + stub_request(:get, "https://api.line.me/v2/bot/insight/message/event/aggregation") |
| 248 | + .with( |
| 249 | + headers: { |
| 250 | + 'Authorization' => "Bearer #{channel_access_token}" |
| 251 | + }, |
| 252 | + query: { |
| 253 | + "customAggregationUnit" => "a_bc_de", |
| 254 | + "from" => "20210301", |
| 255 | + "to" => "20210331" |
| 256 | + } |
| 257 | + ) |
| 258 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 259 | + |
| 260 | + body = client.get_statistics_per_unit( |
| 261 | + custom_aggregation_unit: 'a_bc_de', |
| 262 | + from: '20210301', |
| 263 | + to: '20210331' |
| 264 | + ) |
| 265 | + |
| 266 | + expect(body.overview.unique_impression).to eq(40) |
| 267 | + expect(body.overview.unique_click).to eq(30) |
| 268 | + expect(body.overview.unique_media_played100_percent).to be_nil |
| 269 | + |
| 270 | + expect(body.messages[0].seq).to eq(1) |
| 271 | + expect(body.messages[0].impression).to eq(42) |
| 272 | + expect(body.messages[0].unique_media_played25_percent).to be_nil |
| 273 | + |
| 274 | + expect(body.clicks[0].seq).to eq(1) |
| 275 | + expect(body.clicks[0].url).to eq('https://developers.line.biz/') |
| 276 | + expect(body.clicks[0].unique_click_of_request).to be_nil |
| 277 | + end |
| 278 | + end |
| 279 | + |
200 | 280 | describe 'GET /v2/bot/insight/followers' do |
201 | 281 | let(:client) { Line::Bot::V2::Insight::ApiClient.new(channel_access_token: channel_access_token) } |
202 | 282 | let(:response_code) { 200 } |
|
616 | 696 | expect(body.sent_messages[0].quote_token).to eq('IStG5h1Tz7b...') |
617 | 697 | end |
618 | 698 |
|
| 699 | + it 'requees with custom aggregation unit that contains underscore' do |
| 700 | + stub_request(:post, "https://api.line.me/v2/bot/message/push") |
| 701 | + .with( |
| 702 | + headers: { |
| 703 | + 'Authorization' => "Bearer test-channel-access-token" |
| 704 | + }, |
| 705 | + body: { |
| 706 | + "to" => "USER_ID", |
| 707 | + "messages" => [ |
| 708 | + { |
| 709 | + "type" => "text", |
| 710 | + "text" => " Hello, world! b_a san!", |
| 711 | + "customAggregationUnits" => [ |
| 712 | + "aa_bb_11" |
| 713 | + ] |
| 714 | + } |
| 715 | + ], |
| 716 | + "notificationDisabled" => false, |
| 717 | + }.to_json |
| 718 | + ) |
| 719 | + .to_return(status: response_code, body: response_body, headers: { 'Content-Type' => 'application/json' }) |
| 720 | + |
| 721 | + request = Line::Bot::V2::MessagingApi::PushMessageRequest.new( |
| 722 | + to: 'USER_ID', |
| 723 | + messages: [ |
| 724 | + Line::Bot::V2::MessagingApi::TextMessage.new( |
| 725 | + text: ' Hello, world! b_a san!', |
| 726 | + custom_aggregation_units: [ |
| 727 | + 'aa_bb_11' |
| 728 | + ] |
| 729 | + ) |
| 730 | + ] |
| 731 | + ) |
| 732 | + body, status_code, headers = client.push_message_with_http_info(push_message_request: request) |
| 733 | + |
| 734 | + expect(status_code).to eq(200) |
| 735 | + expect(body).to be_a(Line::Bot::V2::MessagingApi::PushMessageResponse) |
| 736 | + expect(body.sent_messages).to be_a(Array) |
| 737 | + expect(body.sent_messages[0]).to be_a(Line::Bot::V2::MessagingApi::SentMessage) |
| 738 | + expect(body.sent_messages[0].id).to eq('461230966842064897') |
| 739 | + expect(body.sent_messages[0].quote_token).to eq('IStG5h1Tz7b...') |
| 740 | + end |
| 741 | + |
619 | 742 | it 'request with x_line_retry_key: nil' do |
620 | 743 | client = Line::Bot::V2::MessagingApi::ApiClient.new(channel_access_token: 'test-channel-access-token-retry-key-nil') |
621 | 744 | retry_key = nil |
|
0 commit comments