| 1 | package WebService::Async::CustomerIO::Customer; | ||||||||||||
| 2 | |||||||||||||
| 3 | 5 | ▶ | use strict; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 4 | 5 | ▶ | use warnings; | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 5 | |||||||||||||
| 6 | =head1 NAME | ||||||||||||
| 7 | |||||||||||||
| 8 | WebService::Async::CustomerIO::Customer - Class for working with customer. | ||||||||||||
| 9 | |||||||||||||
| 10 | =head1 SYNOPSIS | ||||||||||||
| 11 | |||||||||||||
| 12 | =head1 DESCRIPTION | ||||||||||||
| 13 | |||||||||||||
| 14 | =cut | ||||||||||||
| 15 | |||||||||||||
| 16 | 5 | ▶ | use Carp qw(); | ||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||
| 17 | |||||||||||||
| 18 | 5 | our $VERSION = '0.002'; ## VERSION | |||||||||||
| 19 | |||||||||||||
| 20 | =head2 new | ||||||||||||
| 21 | |||||||||||||
| 22 | Creates customer object. This method just creates an object, to sent this data to api, after creation should be called upsert method. | ||||||||||||
| 23 | |||||||||||||
| 24 | Usage: C<< new(%params) -> obj >> | ||||||||||||
| 25 | |||||||||||||
| 26 | parameters: | ||||||||||||
| 27 | |||||||||||||
| 28 | =over 4 | ||||||||||||
| 29 | |||||||||||||
| 30 | =item * C<id> - the unique identifier for the customer. | ||||||||||||
| 31 | |||||||||||||
| 32 | =item * C<email> - optional. the email address of the user. | ||||||||||||
| 33 | |||||||||||||
| 34 | =item * C<created_at> - optional. the unix timestamp from when the user was created in your system | ||||||||||||
| 35 | |||||||||||||
| 36 | =item * C<attributes> - hashref which contains custom attributes to define the customer. | ||||||||||||
| 37 | |||||||||||||
| 38 | =back | ||||||||||||
| 39 | |||||||||||||
| 40 | =cut | ||||||||||||
| 41 | |||||||||||||
| 42 | 7 | ▶ | sub new { | ||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||
| 43 | 7 | my ($cls, %param) = @_; | |||||||||||
| 44 | |||||||||||||
| 45 | 7 | ▶ | $param{$_} or Carp::croak "Missing required argument: $_" for (qw(id api_client)); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 46 | |||||||||||||
| 47 | 5 | return bless \%param, $cls; | |||||||||||
| 48 | } | ||||||||||||
| 49 | |||||||||||||
| 50 | =head2 api | ||||||||||||
| 51 | |||||||||||||
| 52 | =cut | ||||||||||||
| 53 | |||||||||||||
| 54 | 11 | ▶ | sub api { return shift->{api_client} } | ||||||||||
|
Subroutine
api: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 55 | |||||||||||||
| 56 | =head2 id | ||||||||||||
| 57 | |||||||||||||
| 58 | =cut | ||||||||||||
| 59 | |||||||||||||
| 60 | 13 | ▶ | sub id { return shift->{id} } | ||||||||||
|
Subroutine
id: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 61 | |||||||||||||
| 62 | =head2 email | ||||||||||||
| 63 | |||||||||||||
| 64 | =cut | ||||||||||||
| 65 | |||||||||||||
| 66 | 1 | ▶ | sub email { return shift->{email} } | ||||||||||
|
Subroutine
email: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 67 | |||||||||||||
| 68 | =head2 created_at | ||||||||||||
| 69 | |||||||||||||
| 70 | =cut | ||||||||||||
| 71 | |||||||||||||
| 72 | 1 | ▶ | sub created_at { return shift->{created_at} } | ||||||||||
|
Subroutine
created_at: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 73 | |||||||||||||
| 74 | =head2 attributes | ||||||||||||
| 75 | |||||||||||||
| 76 | =cut | ||||||||||||
| 77 | |||||||||||||
| 78 | 2 | ▶ | sub attributes { return shift->{attributes} } | ||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 79 | |||||||||||||
| 80 | =head2 upsert | ||||||||||||
| 81 | |||||||||||||
| 82 | Create or update a customer | ||||||||||||
| 83 | |||||||||||||
| 84 | Usage: C<< upsert() -> Future() >> | ||||||||||||
| 85 | |||||||||||||
| 86 | =cut | ||||||||||||
| 87 | |||||||||||||
| 88 | 1 | ▶ | sub upsert { | ||||||||||
|
Subroutine
upsert: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 89 | 1 | my ($self) = @_; | |||||||||||
| 90 | 1 | my $user_id = $self->id; | |||||||||||
| 91 | |||||||||||||
| 92 | 1 | ▶ | my $attr = $self->attributes // {}; | ||||||||||
|
Condition50%1/2
$self->attributes // {}
MC/DC0%0/1
$self->attributes // {}
$self->attributes
Truth table50%1/2
A
A= $self->attributes
| |||||||||||||
| 93 | my %user_params = | ||||||||||||
| 94 | 1 | map { $_ => $attr->{$_} } | |||||||||||
| 95 | 1 | grep { defined $attr->{$_} } | |||||||||||
| 96 | keys %$attr; | ||||||||||||
| 97 | |||||||||||||
| 98 | 1 | @user_params{qw(email created_at)} = @{$self}{qw(email created_at)}; | |||||||||||
| 99 | |||||||||||||
| 100 | 1 | return $self->api->tracking_request( | |||||||||||
| 101 | PUT => $self->_get_uri, | ||||||||||||
| 102 | \%user_params | ||||||||||||
| 103 | ); | ||||||||||||
| 104 | } | ||||||||||||
| 105 | |||||||||||||
| 106 | =head2 set_attribute | ||||||||||||
| 107 | |||||||||||||
| 108 | Set a customer attribute | ||||||||||||
| 109 | |||||||||||||
| 110 | Usage: C<< set_attribute($name, $value) -> Future() >> | ||||||||||||
| 111 | |||||||||||||
| 112 | =cut | ||||||||||||
| 113 | |||||||||||||
| 114 | 2 | ▶ | sub set_attribute { | ||||||||||
|
Subroutine
set_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 115 | 2 | my ($self, $name, $val) = @_; | |||||||||||
| 116 | |||||||||||||
| 117 | 2 | return $self->api->tracking_request( | |||||||||||
| 118 | PUT => $self->_get_uri, | ||||||||||||
| 119 | {$name => $val}); | ||||||||||||
| 120 | } | ||||||||||||
| 121 | |||||||||||||
| 122 | =head2 remove_attribute | ||||||||||||
| 123 | |||||||||||||
| 124 | Remove customer attribute | ||||||||||||
| 125 | |||||||||||||
| 126 | Usage: C<< remove_attribute($name, $value) -> Future() >> | ||||||||||||
| 127 | |||||||||||||
| 128 | =cut | ||||||||||||
| 129 | |||||||||||||
| 130 | 1 | ▶ | sub remove_attribute { | ||||||||||
|
Subroutine
remove_attribute: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 131 | 1 | my ($self, $name) = @_; | |||||||||||
| 132 | |||||||||||||
| 133 | 1 | return $self->set_attribute($name, ''); | |||||||||||
| 134 | } | ||||||||||||
| 135 | |||||||||||||
| 136 | =head2 suppress | ||||||||||||
| 137 | |||||||||||||
| 138 | Suppress the customer. All events related to this customer wil be ignored by API. | ||||||||||||
| 139 | |||||||||||||
| 140 | Usage: C<< suppress() -> Future() >> | ||||||||||||
| 141 | |||||||||||||
| 142 | =cut | ||||||||||||
| 143 | |||||||||||||
| 144 | 1 | ▶ | sub suppress { | ||||||||||
|
Subroutine
suppress: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 145 | 1 | my ($self) = @_; | |||||||||||
| 146 | |||||||||||||
| 147 | 1 | return $self->api->tracking_request(POST => $self->_get_uri('suppress')); | |||||||||||
| 148 | } | ||||||||||||
| 149 | |||||||||||||
| 150 | =head2 unsuppress | ||||||||||||
| 151 | |||||||||||||
| 152 | Unsuppress the customer. | ||||||||||||
| 153 | |||||||||||||
| 154 | Usage: C<< unsuppress() -> Future() >> | ||||||||||||
| 155 | |||||||||||||
| 156 | =cut | ||||||||||||
| 157 | |||||||||||||
| 158 | 1 | ▶ | sub unsuppress { | ||||||||||
|
Subroutine
unsuppress: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 159 | 1 | my ($self) = @_; | |||||||||||
| 160 | |||||||||||||
| 161 | 1 | return $self->api->tracking_request(POST => $self->_get_uri('unsuppress')); | |||||||||||
| 162 | } | ||||||||||||
| 163 | |||||||||||||
| 164 | =head2 upsert_device | ||||||||||||
| 165 | |||||||||||||
| 166 | Create or update a customer device | ||||||||||||
| 167 | |||||||||||||
| 168 | Usage: C<< upsert_device(%params) -> Future() >> | ||||||||||||
| 169 | |||||||||||||
| 170 | Parameters: | ||||||||||||
| 171 | |||||||||||||
| 172 | =over 4 | ||||||||||||
| 173 | |||||||||||||
| 174 | =item * C<id> - The unique token for the user device. | ||||||||||||
| 175 | |||||||||||||
| 176 | =item * C<platform> - The platform for the user device. Allowed values are 'ios' and 'android'. | ||||||||||||
| 177 | |||||||||||||
| 178 | =item * C<last_used> - Optional. UNIX timestamp representing the last used time for the device. If this is not included we default to the time of the device identify. | ||||||||||||
| 179 | |||||||||||||
| 180 | =back | ||||||||||||
| 181 | |||||||||||||
| 182 | =cut | ||||||||||||
| 183 | |||||||||||||
| 184 | 5 | ▶ | sub upsert_device { | ||||||||||
|
Subroutine
upsert_device: called CC=4 SCAR=13.9
Pod
documented
| |||||||||||||
| 185 | 5 | my ($self, %param) = @_; | |||||||||||
| 186 | |||||||||||||
| 187 | 5 | ▶ | $param{$_} or Carp::croak "Missing required argument: $_" for (qw(device_id platform)); | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 188 | |||||||||||||
| 189 | Carp::croak 'Invalid value for platform: ' . $param{platform} | ||||||||||||
| 190 | 3 | ▶ | if $param{platform} !~ /^(?:ios|android)$/; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 191 | |||||||||||||
| 192 | my $device = { | ||||||||||||
| 193 | id => $param{device_id}, | ||||||||||||
| 194 | platform => $param{platform}, | ||||||||||||
| 195 | last_used => $param{last_used}, | ||||||||||||
| 196 | 2 | }; | |||||||||||
| 197 | |||||||||||||
| 198 | 2 | return $self->api->tracking_request( | |||||||||||
| 199 | PUT => $self->_get_uri('devices'), | ||||||||||||
| 200 | {device => $device}); | ||||||||||||
| 201 | } | ||||||||||||
| 202 | |||||||||||||
| 203 | =head2 delete_device | ||||||||||||
| 204 | |||||||||||||
| 205 | Delete a customer device | ||||||||||||
| 206 | |||||||||||||
| 207 | Usage: C<< delete_device($id) -> Future() >> | ||||||||||||
| 208 | |||||||||||||
| 209 | =cut | ||||||||||||
| 210 | |||||||||||||
| 211 | 2 | ▶ | sub delete_device { | ||||||||||
|
Subroutine
delete_device: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 212 | 2 | my ($self, $device_id) = @_; | |||||||||||
| 213 | |||||||||||||
| 214 | 2 | ▶ | $device_id or Carp::croak "Missing required argument: device_id"; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 215 | |||||||||||||
| 216 | 1 | return $self->api->tracking_request(DELETE => $self->_get_uri('devices', $device_id)); | |||||||||||
| 217 | } | ||||||||||||
| 218 | |||||||||||||
| 219 | =head2 emit_event | ||||||||||||
| 220 | |||||||||||||
| 221 | Track a customer event | ||||||||||||
| 222 | |||||||||||||
| 223 | Usage: C<< emit_event(%params) -> Future() >> | ||||||||||||
| 224 | |||||||||||||
| 225 | Parameters: | ||||||||||||
| 226 | |||||||||||||
| 227 | - name: The name of the event to track | ||||||||||||
| 228 | - type: Optional. Used to change event type. For Page View events set to "page". | ||||||||||||
| 229 | - data: Optional. Custom data to include with the event. | ||||||||||||
| 230 | |||||||||||||
| 231 | =cut | ||||||||||||
| 232 | |||||||||||||
| 233 | 2 | ▶ | sub emit_event { | ||||||||||
|
Subroutine
emit_event: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||
| 234 | 2 | my ($self, %param) = @_; | |||||||||||
| 235 | |||||||||||||
| 236 | 2 | ▶ | Carp::croak 'Missing required argument: name' unless $param{name}; | ||||||||||
|
Branch: 1 branch
| |||||||||||||
| 237 | |||||||||||||
| 238 | 1 | return $self->api->tracking_request( | |||||||||||
| 239 | POST => $self->_get_uri('events'), | ||||||||||||
| 240 | \%param | ||||||||||||
| 241 | ); | ||||||||||||
| 242 | } | ||||||||||||
| 243 | |||||||||||||
| 244 | =head2 delete_customer | ||||||||||||
| 245 | |||||||||||||
| 246 | Delete a customer | ||||||||||||
| 247 | |||||||||||||
| 248 | Usage: C<< delete_customer() -> Future() >> | ||||||||||||
| 249 | |||||||||||||
| 250 | =cut | ||||||||||||
| 251 | |||||||||||||
| 252 | 1 | ▶ | sub delete_customer { | ||||||||||
|
Subroutine
delete_customer: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||
| 253 | 1 | my $self = shift; | |||||||||||
| 254 | |||||||||||||
| 255 | 1 | return $self->api->tracking_request(DELETE => $self->_get_uri()); | |||||||||||
| 256 | } | ||||||||||||
| 257 | |||||||||||||
| 258 | 10 | ▶ | sub _get_uri { | ||||||||||
|
Subroutine
_get_uri: called CC=1 SCAR=0.0
| |||||||||||||
| 259 | 10 | my ($self, @path) = @_; | |||||||||||
| 260 | |||||||||||||
| 261 | 10 | return join q{/} => ('customers', $self->id, @path); | |||||||||||
| 262 | } | ||||||||||||
| 263 | |||||||||||||
| 264 | 5 | 1; | |||||||||||