line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Async::CustomerIO::Trigger; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
82
|
|
4
|
3
|
|
|
3
|
|
14
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
78
|
|
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
WebService::Async::CustomerIO::Trigger - Class for working with triggers end points |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 SYNOPSIS |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 DESCRIPTION |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=cut |
15
|
|
|
|
|
|
|
|
16
|
3
|
|
|
3
|
|
15
|
use Carp qw(); |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
1602
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $VERSION = '0.002'; ## VERSION |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head2 new |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
Creates a new API client object |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
Usage: C<< new(%params) -> obj >> |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
Parameters: |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over 4 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item * C |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
=item * C |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
=back |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
=cut |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub new { |
39
|
7
|
|
|
7
|
1
|
7171
|
my ($cls, %param) = @_; |
40
|
|
|
|
|
|
|
|
41
|
7
|
|
66
|
|
|
254
|
$param{$_} or Carp::croak "Missing required argument: $_" for (qw(campaign_id api_client)); |
42
|
|
|
|
|
|
|
|
43
|
5
|
|
|
|
|
22
|
return bless \%param, $cls; |
44
|
|
|
|
|
|
|
} |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=head2 api |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=cut |
49
|
|
|
|
|
|
|
|
50
|
4
|
|
|
4
|
1
|
26
|
sub api { return shift->{api_client} } |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=head2 id |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
=cut |
55
|
|
|
|
|
|
|
|
56
|
7
|
|
|
7
|
1
|
787
|
sub id { return shift->{id} } |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=head2 campaign_id |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
=cut |
61
|
|
|
|
|
|
|
|
62
|
4
|
|
|
4
|
1
|
28
|
sub campaign_id { return shift->{campaign_id} } |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 activate |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Trigger broadcast campaign |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Usage: C<< activate(%param) -> Future($obj) >> |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=cut |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub activate { |
73
|
1
|
|
|
1
|
1
|
4
|
my ($self, $params) = @_; |
74
|
|
|
|
|
|
|
|
75
|
1
|
50
|
|
|
|
3
|
Carp::croak 'This trigger is already activated' if $self->id; |
76
|
|
|
|
|
|
|
|
77
|
1
|
|
|
|
|
2
|
my $campaign_id = $self->campaign_id; |
78
|
|
|
|
|
|
|
return $self->api->api_request('POST', "campaigns/$campaign_id/triggers", $params, 'trigger')->then( |
79
|
|
|
|
|
|
|
sub { |
80
|
1
|
|
|
1
|
|
239
|
my ($response) = @_; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
return Future->fail("UNEXPECTED_RESPONSE_FORMAT", 'customerio', $response) |
83
|
1
|
50
|
|
|
|
4
|
if !defined $response->{id}; |
84
|
|
|
|
|
|
|
|
85
|
1
|
|
|
|
|
2
|
$self->{id} = $response->{id}; |
86
|
|
|
|
|
|
|
|
87
|
1
|
|
|
|
|
4
|
return Future->done($response); |
88
|
1
|
|
|
|
|
3
|
}); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 status |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Retrieve status of a broadcast |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Usage: C<< status() -> Future($response) >> |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=cut |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
sub status { |
100
|
1
|
|
|
1
|
1
|
8
|
my ($self) = @_; |
101
|
|
|
|
|
|
|
|
102
|
1
|
50
|
|
|
|
8
|
Carp::croak 'This trigger has not been activated yet' unless $self->id; |
103
|
|
|
|
|
|
|
|
104
|
1
|
|
|
|
|
6
|
return $self->api->api_request(GET => 'campaigns/' . $self->campaign_id . '/triggers/' . $self->id); |
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
=head2 get_errors |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
Retrieve per-user data file processing errors. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
Usage: C<< get_errors($start, $limit) -> Future(%$result) >> |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=cut |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub errors { |
116
|
1
|
|
|
1
|
0
|
5
|
my ($self, $start, $limit) = @_; |
117
|
|
|
|
|
|
|
|
118
|
1
|
|
|
|
|
3
|
my $trigger_id = $self->id; |
119
|
1
|
|
|
|
|
3
|
my $campaign_id = $self->campaign_id; |
120
|
|
|
|
|
|
|
|
121
|
1
|
50
|
|
|
|
4
|
Carp::croak 'Trying to get errors for unsaved trigger' unless defined $trigger_id; |
122
|
1
|
50
|
33
|
|
|
18
|
Carp::croak "Invalid value for start $start" if defined $start && int($start) < 0; |
123
|
1
|
50
|
33
|
|
|
7
|
Carp::croak "Invalid value for limit $limit" if defined $limit && int($limit) <= 0; |
124
|
|
|
|
|
|
|
|
125
|
1
|
50
|
|
|
|
4
|
return $self->api->api_request( |
|
|
50
|
|
|
|
|
|
126
|
|
|
|
|
|
|
GET => "campaigns/$campaign_id/triggers/$trigger_id/errors", |
127
|
|
|
|
|
|
|
{(defined $start ? (start => int($start)) : ()), (defined $limit ? (limit => int($limit)) : ()),}, |
128
|
|
|
|
|
|
|
); |
129
|
|
|
|
|
|
|
} |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
1; |