ElasticEmail
view release on metacpan or search on metacpan
lib/ElasticEmail.pm view on Meta::CPAN
package ElasticEmail;
use 5.006;
use strict;
use warnings;
package Api;
use LWP::UserAgent;
use File::Basename;
our $mainApi= new Api("00000000-0000-0000-0000-000000000000", 'example@email.com', 'https://api.elasticemail.com/v2/');
sub new
{
my $class = shift;
my $self = {
apikey => shift,
username => shift,
url => shift,
};
bless $self, $class;
return $self;
}
sub Request
{
my ($self, $urlLocal, $requestType, $one_ref, $two_ref) = @_;
my @allTheData = $one_ref ? @{$one_ref} : ();
my @postFilesPaths = $two_ref ? @{$two_ref} : ();
my $ua = LWP::UserAgent->new;
my $response;
if ($requestType eq "GET"){
my $fullURL = $self->{url}."/".$urlLocal."?apikey=".$self->{apikey};
$response = $ua->get($fullURL);
}
elsif($requestType eq "POST"){
my $fullURL = $self->{ url}."/".$urlLocal;
my $num = 0;
my $file;
foreach $file(@postFilesPaths){
my $localFileName = fileparse($file);
my $fieldName = 'file'.$num;
push(@{$allTheData[0]}, ($fieldName, [$file, $localFileName]));
$num++;
}
$response = $ua->post($fullURL, Content_Type => 'multipart/form-data', Content => @allTheData);
}
my $content = $response->decoded_content();
return $content;
}
#
# Methods for managing your account and subaccounts.
#
package Api::Account;
# Create new subaccount and provide most important data about it.
# string apikey - ApiKey that gives you access to our SMTP and HTTP API's.
# string email - Proper email address.
# string password - Current password.
# string confirmPassword - Repeat new password.
# bool requiresEmailCredits - True, if account needs credits to send emails. Otherwise, false (default False)
# bool enableLitmusTest - True, if account is able to send template tests to Litmus. Otherwise, false (default False)
# bool requiresLitmusCredits - True, if account needs credits to send emails. Otherwise, false (default False)
# int maxContacts - Maximum number of contacts the account can have (default 0)
# bool enablePrivateIPRequest - True, if account can request for private IP on its own. Otherwise, false (default True)
# bool sendActivation - True, if you want to send activation email to this account. Otherwise, false (default False)
# string returnUrl - URL to navigate to after account creation (default None)
# ApiTypes::SendingPermission? sendingPermission - Sending permission setting for account (default None)
# bool? enableContactFeatures - True, if you want to use Advanced Tools. Otherwise, false (default None)
# string poolName - Private IP required. Name of the custom IP Pool which Sub Account should use to send its emails. Leave empty for the default one or if no Private IPs have been bought (default None)
# int emailSizeLimit - Maximum size of email including attachments in MB's (default 10)
# Returns string
sub AddSubAccount
{
shift;
my @params = [apikey => $Api::mainApi->{apikey},
email => shift,
password => shift,
confirmPassword => shift,
requiresEmailCredits => shift,
enableLitmusTest => shift,
requiresLitmusCredits => shift,
maxContacts => shift,
enablePrivateIPRequest => shift,
sendActivation => shift,
returnUrl => shift,
sendingPermission => shift,
enableContactFeatures => shift,
poolName => shift,
emailSizeLimit => shift];
return $Api::mainApi->Request('account/addsubaccount', "GET", \@params);
}
# Add email, template or litmus credits to a sub-account
# string apikey - ApiKey that gives you access to our SMTP and HTTP API's.
# int credits - Amount of credits to add
# string notes - Specific notes about the transaction
# ApiTypes::CreditType creditType - Type of credits to add (Email or Litmus) (default ApiTypes.CreditType.Email)
# string subAccountEmail - Email address of sub-account (default None)
# string publicAccountID - Public key of sub-account to add credits to. Use subAccountEmail or publicAccountID not both. (default None)
sub AddSubAccountCredits
{
shift;
my @params = [apikey => $Api::mainApi->{apikey},
credits => shift,
( run in 1.536 second using v1.01-cache-2.11-cpan-9789f410c06 )