|
39 | 39 | } |
40 | 40 | EOS |
41 | 41 |
|
| 42 | +NUMBER_OF_MESSAGE_DELIVERY_CONTENT = <<"EOS" |
| 43 | +{ |
| 44 | + "status": "ready", |
| 45 | + "broadcast": 5385, |
| 46 | + "targeting": 522, |
| 47 | + "autoResponse": 123, |
| 48 | + "welcomeResponse": 456, |
| 49 | + "chat": 789, |
| 50 | + "apiBroadcast": 1123, |
| 51 | + "apiPush": 1234, |
| 52 | + "apiMulticast": 1567, |
| 53 | + "apiReply": 1890 |
| 54 | +} |
| 55 | +EOS |
| 56 | + |
| 57 | +NUMBER_OF_FOLLOWERS_CONTENT = <<"EOS" |
| 58 | +{ |
| 59 | + "status": "ready", |
| 60 | + "followers": 5385, |
| 61 | + "targetedReaches": 522, |
| 62 | + "blocks": 123 |
| 63 | +} |
| 64 | +EOS |
| 65 | + |
| 66 | +FRIEND_DEMOGRAPHIC_CONTENT = <<"EOS" |
| 67 | +{ |
| 68 | + "available": true, |
| 69 | + "genders": [ |
| 70 | + { |
| 71 | + "gender": "unknown", |
| 72 | + "percentage": 37.6 |
| 73 | + }, |
| 74 | + { |
| 75 | + "gender": "male", |
| 76 | + "percentage": 31.8 |
| 77 | + }, |
| 78 | + { |
| 79 | + "gender": "female", |
| 80 | + "percentage": 30.6 |
| 81 | + } |
| 82 | + ], |
| 83 | + "ages": [ |
| 84 | + { |
| 85 | + "age": "unknown", |
| 86 | + "percentage": 37.6 |
| 87 | + }, |
| 88 | + { |
| 89 | + "age": "from50", |
| 90 | + "percentage": 17.3 |
| 91 | + } |
| 92 | + ], |
| 93 | + "areas": [ |
| 94 | + { |
| 95 | + "area": "unknown", |
| 96 | + "percentage": 42.9 |
| 97 | + }, |
| 98 | + { |
| 99 | + "area": "徳島", |
| 100 | + "percentage": 2.9 |
| 101 | + } |
| 102 | + ], |
| 103 | + "appTypes": [ |
| 104 | + { |
| 105 | + "appType": "ios", |
| 106 | + "percentage": 62.4 |
| 107 | + }, |
| 108 | + { |
| 109 | + "appType": "android", |
| 110 | + "percentage": 27.7 |
| 111 | + }, |
| 112 | + { |
| 113 | + "appType": "others", |
| 114 | + "percentage": 9.9 |
| 115 | + } |
| 116 | + ], |
| 117 | + "subscriptionPeriods": [ |
| 118 | + { |
| 119 | + "subscriptionPeriod": "over365days", |
| 120 | + "percentage": 96.4 |
| 121 | + }, |
| 122 | + { |
| 123 | + "subscriptionPeriod": "within365days", |
| 124 | + "percentage": 1.9 |
| 125 | + }, |
| 126 | + { |
| 127 | + "subscriptionPeriod": "within180days", |
| 128 | + "percentage": 1.2 |
| 129 | + }, |
| 130 | + { |
| 131 | + "subscriptionPeriod": "within90days", |
| 132 | + "percentage": 0.5 |
| 133 | + }, |
| 134 | + { |
| 135 | + "subscriptionPeriod": "within30days", |
| 136 | + "percentage": 0.1 |
| 137 | + }, |
| 138 | + { |
| 139 | + "subscriptionPeriod": "within7days", |
| 140 | + "percentage": 0 |
| 141 | + } |
| 142 | + ] |
| 143 | +} |
| 144 | +EOS |
| 145 | + |
42 | 146 | WebMock.allow_net_connect! |
43 | 147 |
|
44 | 148 | describe Line::Bot::Client do |
@@ -173,4 +277,81 @@ def generate_client |
173 | 277 | quota = JSON.parse(response.body) |
174 | 278 | expect(quota['totalUsage']).to eq 1 |
175 | 279 | end |
| 280 | + |
| 281 | + it 'get number of message deliveries' do |
| 282 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/insight/message/delivery?date=20190701' |
| 283 | + stub_request(:get, uri_template).to_return(body: NUMBER_OF_MESSAGE_DELIVERY_CONTENT, status: 200) |
| 284 | + |
| 285 | + client = generate_client |
| 286 | + response = client.get_number_of_message_deliveries("20190701") |
| 287 | + |
| 288 | + json = JSON.parse(response.body, symbolize_names: true) |
| 289 | + expect(json).to eq( |
| 290 | + status: "ready", |
| 291 | + broadcast: 5385, |
| 292 | + targeting: 522, |
| 293 | + autoResponse: 123, |
| 294 | + welcomeResponse: 456, |
| 295 | + chat: 789, |
| 296 | + apiBroadcast: 1123, |
| 297 | + apiPush: 1234, |
| 298 | + apiMulticast: 1567, |
| 299 | + apiReply: 1890 |
| 300 | + ) |
| 301 | + end |
| 302 | + |
| 303 | + it 'get number of followers' do |
| 304 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/insight/followers?date=20190701' |
| 305 | + stub_request(:get, uri_template).to_return(body: NUMBER_OF_FOLLOWERS_CONTENT, status: 200) |
| 306 | + |
| 307 | + client = generate_client |
| 308 | + response = client.get_number_of_followers("20190701") |
| 309 | + |
| 310 | + json = JSON.parse(response.body, symbolize_names: true) |
| 311 | + expect(json).to eq( |
| 312 | + status: "ready", |
| 313 | + followers: 5385, |
| 314 | + targetedReaches: 522, |
| 315 | + blocks: 123 |
| 316 | + ) |
| 317 | + end |
| 318 | + |
| 319 | + it 'get friend demographics' do |
| 320 | + uri_template = Addressable::Template.new Line::Bot::API::DEFAULT_ENDPOINT + '/bot/insight/demographic' |
| 321 | + stub_request(:get, uri_template).to_return(body: FRIEND_DEMOGRAPHIC_CONTENT, status: 200) |
| 322 | + |
| 323 | + client = generate_client |
| 324 | + response = client.get_friend_demographics |
| 325 | + |
| 326 | + json = JSON.parse(response.body, symbolize_names: true) |
| 327 | + expect(json).to eq( |
| 328 | + available: true, |
| 329 | + genders: [ |
| 330 | + { gender: "unknown", percentage: 37.6 }, |
| 331 | + { gender: "male", percentage: 31.8 }, |
| 332 | + { gender: "female", percentage: 30.6 } |
| 333 | + ], |
| 334 | + ages: [ |
| 335 | + { age: "unknown", percentage: 37.6 }, |
| 336 | + { age: "from50", percentage: 17.3 }, |
| 337 | + ], |
| 338 | + areas: [ |
| 339 | + { area: "unknown", percentage: 42.9 }, |
| 340 | + { area: "徳島", percentage: 2.9 } |
| 341 | + ], |
| 342 | + appTypes: [ |
| 343 | + { appType: "ios", percentage: 62.4 }, |
| 344 | + { appType: "android", percentage: 27.7 }, |
| 345 | + { appType: "others", percentage: 9.9 } |
| 346 | + ], |
| 347 | + subscriptionPeriods: [ |
| 348 | + { subscriptionPeriod: "over365days", percentage: 96.4 }, |
| 349 | + { subscriptionPeriod: "within365days", percentage: 1.9 }, |
| 350 | + { subscriptionPeriod: "within180days", percentage: 1.2 }, |
| 351 | + { subscriptionPeriod: "within90days", percentage: 0.5 }, |
| 352 | + { subscriptionPeriod: "within30days", percentage: 0.1 }, |
| 353 | + { subscriptionPeriod: "within7days", percentage: 0 } |
| 354 | + ] |
| 355 | + ) |
| 356 | + end |
176 | 357 | end |
0 commit comments