# debugger says:
# DB<1> s
#HTTP::Tiny::Handle::new(/usr/share/perl5/HTTP/Tiny.pm:891):
#891: return bless {
#892: rbuf => '',
#893: timeout => 60,
#894: max_line_size => 16384,
#895: max_header_lines => 64,
#896: verify_SSL => 0,
#897: SSL_options => {},
#898: %args
# DB<1> q
# BEGIN my script:
#!/usr/bin/env perl
use strict;
use warnings;
#use Mozilla::CA; # I expect the request to fail with this commented out
use WebService::Discord::Webhook;
use Data::Dumper; # Uncomment for debugging
# Webhook URL
my $url = 'https://discordapp.com/api/webhooks/BIG/' .
'LONG-URL';
# Create webhook object
my $webhook = WebService::Discord::Webhook->new(
url => $url,
verify_SSL => '1'
);
print Dumper($webhook->get());
# END my script
# perl module contains this:
sub new {
my $class = shift;
my %params;
if ( scalar @_ > 1 ) {
%params = @_;
} else {
$params{url} = shift;
}
# check parameters
my ( $id, $token );
if ( $params{url} ) {
if ( $params{url} =~ m{discordapp\.com/api/webhooks/(\d+)/([^/?]+)}i ) {
$id = $1;
$token = $2;
} else {
croak "Failed to parse ID and Token from URL";
}
} elsif ( $params{id} && $params{token} ) {
if ( $params{id} =~ m/^\d+$/ && $params{token} =~ m{^[^/?]+$} ) {
$id = $params{id};
$token = $params{token};
} else {
croak "Failed to validate ID and Token";
}
} else {
croak "Must provide either URL, or ID and Token";
}
# Create an LWP UserAgent for REST requests
my %attributes =
( agent =>
"p5-WebService-Discord-Webhook (https://github.com/greg-kennedy/p5-WebService-Discord-Webhook, $VERSION)"
);
if ( $params{timeout} ) { $attributes{timeout} = $params{timeout} }
if ( $params{verify_SSL} ) { $attributes{verify_SSL} = $params{verify_SSL} }
my $http = HTTP::Tiny->new(%attributes);
# create class with some params
my $self = bless { id => $id, token => $token, http => $http }, $class;
if ( $params{wait} ) { $self->{wait} = 1 }
# call get to populate additional details
#$self->get();
return $self;
}