File Coverage

blib/lib/LINE/Bot/Message/Narrowcast.pm
Criterion Covered Total %
statement 31 31 100.0
branch 2 2 100.0
condition 3 5 60.0
subroutine 9 9 100.0
pod 2 4 50.0
total 47 51 92.1


line stmt bran cond sub pod time code
1             package LINE::Bot::Message::Narrowcast;
2 3     3   276075 use strict;
  3         28  
  3         89  
3 3     3   18 use warnings;
  3         7  
  3         87  
4              
5 3     3   840 use LINE::Bot::API::Client;
  3         7  
  3         101  
6 3     3   1314 use LINE::Bot::API::Response::NarrowcastStatus;
  3         9  
  3         101  
7              
8             use constant {
9 3         1074 DEFAULT_MESSAGING_API_ENDPOINT => 'https://api.line.me/v2/bot/',
10 3     3   22 };
  3         7  
11              
12             sub new {
13 3     3 0 3745 my ($class, %args) = @_;
14              
15 3         27 my $client = LINE::Bot::API::Client->new(%args);
16             bless {
17             client => $client,
18             channel_secret => $args{channel_secret},
19             channel_access_token => $args{channel_access_token},
20 3   50     233 messaging_api_endpoint => $args{messaging_api_endpoint} // DEFAULT_MESSAGING_API_ENDPOINT,
21             }, $class;
22             }
23              
24             sub request {
25 3     3 0 14 my ($self, $method, $path, @payload) = @_;
26              
27             return $self->{client}->$method(
28 3         33 $self->{messaging_api_endpoint} . $path,
29             @payload,
30             );
31             }
32              
33             sub send_message {
34 2     2 1 1713 my ($self, $messages, $recipient, $demographic, $limit, $options) = @_;
35              
36 2         12 my @headers = ();
37 2 100 66     22 if ($options && defined($options->{'retry_key'})) {
38 1         4 push @headers, 'X-Line-Retry-Key' => $options->{'retry_key'};
39             }
40              
41 2         17 my $res = $self->request(
42             post => 'message/narrowcast',
43             \@headers,
44             +{
45             messages => $messages,
46             recipient => $recipient,
47             filter => {
48             demographic => $demographic,
49             },
50             limit => $limit,
51             },
52             );
53              
54 2         17 LINE::Bot::API::Response::Common->new(%{ $res });
  2         17  
55             }
56              
57             sub get_narrowcast_message_status {
58 1     1 1 2069 my ($self, $request_id) = @_;
59              
60 1         8 my $res = $self->request(
61             get => "message/progress/narrowcast?requestId=${request_id}"
62             );
63              
64 1         2 LINE::Bot::API::Response::NarrowcastStatus->new(%{ $res });
  1         15  
65             }
66              
67             1;
68             __END__