API-Drip-Request
view release on metacpan or search on metacpan
12345678910111213141516171819202122232425262728293031323334353637383940use
v5.14;
use
strict;
use
warnings;
use
Module::Build;
my
$builder
= Module::Build->new(
module_name
=>
'API::Drip::Request'
,
license
=>
'perl_5'
,
dist_author
=>
q{Dan Wright <Dan@DWright.Org>}
,
dist_version_from
=>
'lib/API/Drip/Request.pm'
,
release_status
=>
'stable'
,
configure_requires
=> {
'Module::Build'
=>
'0'
, },
build_requires
=> {
'Test::More'
=>
'0'
, },
requires
=> {
'Carp'
=> 0,
'Data::Printer'
=> 0,
'File::HomeDir'
=> 0,
'File::Spec'
=> 0,
'HTTP::Request::Common'
=> 0,
'JSON'
=> 0,
'LWP::UserAgent'
=> 0,
'Params::ValidationCompiler'
=> 0,
'Readonly'
=> 0,
'Types::Standard'
=> 0,
'URI'
=> 0,
'YAML'
=> 0,
},
add_to_cleanup
=> [
'API-Drip-*'
],
meta_merge
=> {
'meta-spec'
=> {
version
=>
'2'
,
},
type
=>
'git'
,
}
},
}, );
$builder
->create_build_script();
891011121314151617181920212223242526272829303132333435363738"license"
: [
"perl_5"
],
"meta-spec"
: {
"version"
:
"2"
},
"name"
:
"API-Drip-Request"
,
"prereqs"
: {
"build"
: {
"requires"
: {
"Test::More"
:
"0"
}
},
"configure"
: {
"requires"
: {
"Module::Build"
:
"0"
}
},
"runtime"
: {
"requires"
: {
"Carp"
:
"0"
,
"Data::Printer"
:
"0"
,
"File::HomeDir"
:
"0"
,
"File::Spec"
:
"0"
,
"HTTP::Request::Common"
:
"0"
,
"JSON"
:
"0"
,
"LWP::UserAgent"
:
"0"
,
"Params::ValidationCompiler"
:
"0"
,
"Readonly"
:
"0"
,
"Types::Standard"
:
"0"
,
414243444546474849505152535455565758596061
}
}
},
"provides"
: {
"API::Drip::Request"
: {
"file"
:
"lib/API/Drip/Request.pm"
,
"version"
:
"0.05"
}
},
"release_status"
:
"stable"
,
"resources"
: {
"bugtracker"
: {
},
"repository"
: {
"type"
:
"git"
,
}
},
"version"
:
"0.05"
,
12345678910111213141516171819202122232425262728293031323334353637---
abstract:
'Perl interface to api.getdrip.com'
author:
-
'Dan Wright <Dan@DWright.Org>'
build_requires:
Test::More:
'0'
configure_requires:
Module::Build:
'0'
dynamic_config: 1
generated_by:
'Module::Build version 0.4224, CPAN::Meta::Converter version 2.150010'
license: perl
meta-spec:
version:
'1.4'
name: API-Drip-Request
provides:
API::Drip::Request:
file: lib/API/Drip/Request.pm
version:
'0.05'
requires:
Carp:
'0'
Data::Printer:
'0'
File::HomeDir:
'0'
File::Spec:
'0'
HTTP::Request::Common:
'0'
JSON:
'0'
LWP::UserAgent:
'0'
Params::ValidationCompiler:
'0'
Readonly:
'0'
Types::Standard:
'0'
URI:
'0'
YAML:
'0'
resources:
bugtracker: https://github.com/dwright/API-Drip/issues
repository: https://github.com/dwright/API-Drip.git
version:
'0.05'
x_serialization_backend:
'CPAN::Meta::YAML version 0.018'
bin/drip_client.pl view on Meta::CPAN
434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596=over
=item B<getsub>
Get a list of all subscribers.
=item B<addsub>
Add a subscriber. At a minimum, must also specify -email, or -id.
Accepts: -email, -id, -new_email, -user_id, -time_zone, -lifetime_value, -ip_address
=item B<delsub>
Delete a subscriber. Must specify -email, or -id.
=item B<getwork>
Get a list of all workflows.
=item B<startwork>
Start a user on a workflow
Requires: -workflow
Accepts: -email, -id, -user_id, -time_zone, -prospect
=item B<event>
Record that an event happened.
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
bin/drip_client.pl view on Meta::CPAN
116117118119120121122123124125126127128129130131132133134135136my
%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
}
bin/drip_client.pl view on Meta::CPAN
147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216exit
;
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
=
@_
;
my
$subscriber
= _build_hash(
%OPT
,
keys
=> [
qw( email id new_email user_id time_zone lifetime_value ip_address )
] );
die
"email or id required in add subscriber"
unless
$subscriber
->{email} or
$subscriber
->{id};
my
$result
=
$client
->do_request(
POST
=>
'subscribers'
, {
subscribers
=> [
$subscriber
]});
p
$result
;
}
sub
_build_hash {
my
%OPT
=
@_
;
my
$build
= {};
foreach
my
$key
( @{
$OPT
{
keys
}} ) {
next
unless
defined
$OPT
{
$key
};
$build
->{
$key
} =
$OPT
{
$key
};
}
return
$build
;
}
sub
get_subscribers {
my
$result
=
$client
->do_request(
GET
=>
'subscribers'
);
p
$result
;
}
lib/API/Drip/Request.pm view on Meta::CPAN
404142434445464748495051525354555657585960=head1 SYNOPSIS
use API::Drip::Request;
my $drip = API::Drip::Request->new();
$drip->do_request( POST => 'subscribers', { subscribers => [ { email => 'foo@example.com', ... }] } );
=head1 DESCRIPTION
Low-level perl interface to the Drip API as specified at https://www.getdrip.com/docs/rest-api
All of the methods in this module will throw exceptions on error.
=head1 SUBROUTINES/METHODS
=head2 new()
Creates the API::Drip::Request object. See L</"CONFIGURATION"> for accepted parameters.
Also accepts:
lib/API/Drip/Request.pm view on Meta::CPAN
117118119120121122123124125126127128129130131132133134135136137=item Endpoint (requird)
Specifies the path of the REST enpoint you want to query. Include everything after the account ID. For example, "subscribers", "subscribers/$subscriber_id/campaign_subscriptions", etc...
=item Content (optional)
Perl hashref of data that will be sent along with the request.
=back
On success, returns a Perl data structure corresponding to the data returned
from the server. Some operations (DELETE), do not return any data and may
return undef on success. On error, this method will die() with the
HTTP::Response object.
=cut
my
$request_validator
= validation_for(
params
=> [ {
type
=> Str()}, {
type
=> Str()}, {
type
=> HashRef(),
optional
=> 1} ] );
sub
do_request {
my
$self
=
shift
;
my
(
$method
,
$endpoint
,
$content
) =
$request_validator
->(
@_
);
lib/API/Drip/Request.pm view on Meta::CPAN
141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175
$self
->{debugger}->(
'Requesting: '
.
$uri
->as_string );
my
$request
= HTTP::Request->new(
$method
=>
$uri
->as_string, );
if
(
ref
(
$content
) ) {
$request
->content_type(
'application/vnd.api+json'
);
$request
->content( encode_json(
$content
) );
}
$request
->authorization_basic(
$self
->{DRIP_TOKEN},
''
);
$self
->{agent} //= LWP::UserAgent->new(
agent
=>
$self
->{DRIP_AGENT} );
my
$result
=
$self
->{agent}->request(
$request
);
unless
(
$result
->is_success ) {
$self
->{debugger}->(
"Request failed"
,
$result
->content);
die
$result
;
}
if
(
$result
->code == 204 ) {
$self
->{debugger}->(
"Success, no content"
);
return
undef
;
}
my
$decoded
=
eval
{decode_json(
$result
->content )};
if
( $@ ) {
$self
->{debugger}->(
'Failed to decode JSON:'
, $@,
$result
->content);
die
$result
;
}
return
$decoded
;
}
=head1 CONFIGURATION
Configuration data may be passed in through a number of different ways, which are searched in the following order of preference:
=over
( run in 0.819 second using v1.01-cache-2.11-cpan-87723dcf8b7 )