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   223956 use strict;
  3         22  
  3         92  
3 3     3   15 use warnings;
  3         4  
  3         94  
4              
5 3     3   715 use LINE::Bot::API::Client;
  3         6  
  3         80  
6 3     3   1206 use LINE::Bot::API::Response::NarrowcastStatus;
  3         9  
  3         92  
7              
8             use constant {
9 3         898 DEFAULT_MESSAGING_API_ENDPOINT => 'https://api.line.me/v2/bot/',
10 3     3   16 };
  3         6  
11              
12             sub new {
13 3     3 0 4163 my ($class, %args) = @_;
14              
15 3         25 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     158 messaging_api_endpoint => $args{messaging_api_endpoint} // DEFAULT_MESSAGING_API_ENDPOINT,
21             }, $class;
22             }
23              
24             sub request {
25 3     3 0 17 my ($self, $method, $path, @payload) = @_;
26              
27             return $self->{client}->$method(
28 3         27 $self->{messaging_api_endpoint} . $path,
29             @payload,
30             );
31             }
32              
33             sub send_message {
34 2     2 1 1479 my ($self, $messages, $recipient, $demographic, $limit, $options) = @_;
35              
36 2         5 my @headers = ();
37 2 100 66     12 if ($options && defined($options->{'retry_key'})) {
38 1         4 push @headers, 'X-Line-Retry-Key' => $options->{'retry_key'};
39             }
40              
41 2         16 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         8 LINE::Bot::API::Response::Common->new(%{ $res });
  2         14  
55             }
56              
57             sub get_narrowcast_message_status {
58 1     1 1 1436 my ($self, $request_id) = @_;
59              
60 1         5 my $res = $self->request(
61             get => "message/progress/narrowcast?requestId=${request_id}"
62             );
63              
64 1         3 LINE::Bot::API::Response::NarrowcastStatus->new(%{ $res });
  1         11  
65             }
66              
67             1;
68             __END__