Webservice-Sendy-API
view release on metacpan or search on metacpan
#!/usr/bin/env perl
package local::bin::sendy;
use v5.10;
use strict;
use Dispatch::Fu;
use Webservice::Sendy::API qw//;
use Util::H2O::More qw/ddd Getopt2h2o ini2h2o o2d/;
my $VERSION = '0.8';
use constant {
EXIT_SUCCESS => 0,
EXIT_ERROR => 1,
};
my $HOME = (getpwuid($<))[7];
my $CONFIG = "$HOME/.sendy.ini";
my $subcommand = shift @ARGV;
sub do_help() {
print STDERR <<EOF;
sendy Utility version $local::bin::sendy::VERSION - for Sendy 6.1.2+, bundled with Webservice::Sendy::API (https://metacpan.org)
This utility is distributed with the Perl library, Webservice::Sendy::API. It uses
the library to implement the following subcommands. It is a good example of how
to use the Perl module directly, since this utility and the module are maintained
together.
Subcommands:
count - list count
create - create campaign; draft, send now, or schedule send
brands - list brands
delete - delete email address from list
lists - list lists in a given brand Id
subscribe - subscribe email address given a list Id
status - get status of an email address, given a list Id
unsubscribe - unsubscribe email address given a list Id
help - print this help
"-h" - print this help
"-v" - print version banner of this utility, then exit
For more details, type:
perldoc Webservice::Sendy::API
EOF
}
#>>>
dispatch { # Dispatch::Fu
xdefault shift, q{help};
} $subcommand,
count => sub { get_active_subscriber_count(\@ARGV) },
create => sub { create_campaign(\@ARGV) },
brands => sub { get_brands(\@ARGV) },
delete => sub { delete_subscriber(\@ARGV) },
lists => sub { get_lists(\@ARGV) },
subscribe => sub { subscribe(\@ARGV) },
status => sub { get_subscription_status(\@ARGV) },
unsubscribe => sub { unsubscribe(\@ARGV) },
help => \&do_help,
"-h" => \&do_help,
"-v" => sub { printf "sendy Utility version %s - bundled with Webservice::Sendy::API (https://metacpan.org)\n", $local::bin::sendy::VERSION },
;
#<<<
sub create_campaign {
my ($argv) = @_;
my @opts = qw/config=s from_name=s from_email=s reply_to=s title=s subject=s plain_text=s html_text=s html_file=s
list_ids=s segment_ids=s exclude_list_ids=s brand_id=s query_string=s schedule_date_time=s
schedule_timezone=s no_track_opens no_track_clicks send_campaign/;
# NOTE: As much as I despise "reverse options," until Getopt2h2o supports "flag!" syntax, I will have
# to use it here; default values in initial HASH ref are also necessary here
( run in 1.774 second using v1.01-cache-2.11-cpan-39bf76dae61 )