API-Drip-Request

 view release on metacpan or  search on metacpan

bin/drip_client.pl  view on Meta::CPAN

Requires: -email or -id, -action

Accepts: -prospect


=back

=head2 Additional Parameters

The parameters B<-email>, B<-id>, B<-new_email>, B<-user_id>, B<-time_zone>,
B<-lifetime_vaule>, B<-ip_address>, B<-prospect>, B<-action> are documented at
L<https://www.getdrip.com/docs/rest-api> and may be used with the above
operations.

=over

=item B<workflow>

Integer ID of a workflow.


=back

=head1 DESCRIPTION

B<drip_client.pl> is a command-line interface to the API::Drip library.   It's
a handy way to verify your connection to Drip is working as expected, and
possibly to do some light-weight manipulation of your data.

=cut

use v5.14;
use strict;
use lib '/usr/pair/perl/lib';
use Pair::Result ':all';

use Data::Printer;
use Getopt::Long;
use Pod::Usage;
use Readonly;

my %OPT = ( # Add defaults here.
);

GetOptions( \%OPT,
    'help|h|?',
    'man',
    'verbose|verb|v+',
    'conf=s',
    'addsub', 'getsub', 'delsub', 'getwork', 'startwork', 'event',
    'workflow=i', 'action=s',
    'email=s', 'id=s', 'new_email=s', 'user_id=s', 'time_zone=s', 'lifetime_vaule=i', 'ip_address=s', 'prospect'
) or pod2usage(2);
pod2usage(1) if $OPT{help};
pod2usage(-exitval => 0, -verbose => 2) if $OPT{man};
p %OPT if $OPT{verbose};

use API::Drip::Request;
my $client = API::Drip::Request->new( $OPT{conf} ? ( DRIP_CLIENT_CONF => $OPT{conf} ) : () );

eval {
    if ( $OPT{getsub} ) {  get_subscribers() and exit }
    if ( $OPT{addsub} ) {  add_subscribers( %OPT ) and exit }
    if ( $OPT{delsub} ) {  delete_subscribers( %OPT ) and exit }
    if ( $OPT{getwork} ) { get_workflows( %OPT ) and exit }
    if ( $OPT{startwork} ) { start_workflow( %OPT ) and exit }
    if ( $OPT{event} ) { record_event( %OPT ) and exit }
};
if ( $@ ) {
    warn "Request failed:";
    p $@;
}

exit;

sub record_event {
    my %OPT = @_;

    $OPT{email} or $OPT{id} or pod2usage( "Either -email or -id is required for -event" );
    $OPT{action} or pod2usage( "-action is required for -event" );

    my $content = _build_hash( %OPT, keys => [qw(email id action prospect)] );
    my $result = $client->do_request( POST => 'events', { events => [ $content ] } );
    p $result;
}


sub get_workflows {
    my %OPT = @_;

    my $result = $client->do_request( GET => 'workflows' );
    p $result;
}


sub start_workflow {
    my %OPT = @_;
    $OPT{workflow} or pod2usage( "Required parameter -workflow missing for -startwork" );

    my $subscriber = _build_hash( %OPT, keys => [qw( email id user_id time_zone prospect )] );

    my $endpoint = 'workflows/' . $OPT{workflow} . '/subscribers';

    my $result = $client->do_request( POST => $endpoint, { subscribers => [ $subscriber ] } );
    p $result;
}


sub delete_subscribers {
    my %OPT = @_;
    my $id = $OPT{email} || $OPT{id};

    die "email or id required in delete subscriber" unless $id;

    my $result = $client->do_request( DELETE => "subscribers/$id" );
    p $result;

}

sub add_subscribers {
    my %OPT = @_;



( run in 1.020 second using v1.01-cache-2.11-cpan-98e64b0badf )