blob: 125daa55f80b0a5e4f0751fa9c949de52eeb00ff (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
|
package t::Mock::Twilio;
use Web::Simple;
has texts => (
is => 'ro',
default => sub { [] },
);
sub get_text_code {
my $self = shift;
my $text = shift @{$self->texts};
return unless $text;
my ($code) = $text->{Body} =~ /(\d+)/;
return $code;
}
sub dispatch_request {
my $self = shift;
sub (POST + /2010-04-01/Accounts/*/Messages.json + %*) {
my ($self, $sid, $data) = @_;
if ($data->{To} eq '+18165550101') {
return [ 400, [ 'Content-Type' => 'application/json' ],
[ '{"code":"21408", "message": "Unable to send"}' ] ];
}
push @{$self->texts}, $data;
return [ 200, [ 'Content-Type' => 'application/json' ], [ '{}' ] ];
},
}
__PACKAGE__->run_if_script;
|