| 1 | package Mojo::Sendgrid; | ||||||||||
| 2 | 1 | ▶ | use Mojo::Base 'Mojo::EventEmitter'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | |||||||||||
| 4 | 1 | ▶ | use Mojo::Sendgrid::Mail; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | |||||||||||
| 6 | 1 | our $VERSION = '0.05'; | |||||||||
| 7 | |||||||||||
| 8 | 0 | ▶ | has apikey => sub { $ENV{SENDGRID_APIKEY} or die "config apikey missing" }; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||
| 9 | 0 | ▶ | has apiurl => sub { $ENV{SENDGRID_APIURL} || 'https://api.sendgrid.com/api/mail.send.json' }; | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=13.0
Branch: 1 branch
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | sub mail { Mojo::Sendgrid::Mail->new(sendgrid => shift, @_) } | ||||||||
|
Subroutine
mail: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 12 | |||||||||||
| 13 | 1 | 1; | |||||||||
| 14 | |||||||||||
| 15 | =encoding utf8 | ||||||||||
| 16 | |||||||||||
| 17 | =head1 NAME | ||||||||||
| 18 | |||||||||||
| 19 | Mojo::Sendgrid - Sendgrid API implementation for the Mojolicious framework | ||||||||||
| 20 | |||||||||||
| 21 | =head1 VERSION | ||||||||||
| 22 | |||||||||||
| 23 | 0.05 | ||||||||||
| 24 | |||||||||||
| 25 | =head1 SYNOPSIS | ||||||||||
| 26 | |||||||||||
| 27 | use Mojo::Sendgrid; | ||||||||||
| 28 | |||||||||||
| 29 | my $sendgrid = Mojo::Sendgrid->new( | ||||||||||
| 30 | config => { | ||||||||||
| 31 | apikey => 'get your key from api.sendgrid.com', | ||||||||||
| 32 | #apiurl => 'you do not need to set this', | ||||||||||
| 33 | }, | ||||||||||
| 34 | ); | ||||||||||
| 35 | |||||||||||
| 36 | $sendgrid->on(mail_send => sub { | ||||||||||
| 37 | my ($sendgrid, $ua, $tx) = @_; | ||||||||||
| 38 | say $tx->res->body; | ||||||||||
| 39 | }); | ||||||||||
| 40 | |||||||||||
| 41 | say $sendgrid->mail( | ||||||||||
| 42 | to => q(a@b.com), | ||||||||||
| 43 | from => q(x@y.com), | ||||||||||
| 44 | subject => time, | ||||||||||
| 45 | text => time | ||||||||||
| 46 | )->send; | ||||||||||
| 47 | |||||||||||
| 48 | Mojo::IOLoop->start; | ||||||||||
| 49 | |||||||||||
| 50 | =head1 DESCRIPTION | ||||||||||
| 51 | |||||||||||
| 52 | L<Mojo::Sendgrid> is an implementation of the Sendgrid API and is non-blocking | ||||||||||
| 53 | thanks to L<Mojo::IOLoop> from the wonderful L<Mojolicious> framework. | ||||||||||
| 54 | |||||||||||
| 55 | It currently implements the mail endpoint of the Web API v2. | ||||||||||
| 56 | |||||||||||
| 57 | This class inherits from L<Mojo::EventEmitter>. | ||||||||||
| 58 | |||||||||||
| 59 | =head1 EVENTS | ||||||||||
| 60 | |||||||||||
| 61 | Mojo::Sendgrid inherits all events from Mojo::EventEmitter and can emit the following new ones. | ||||||||||
| 62 | |||||||||||
| 63 | =head2 mail_* | ||||||||||
| 64 | |||||||||||
| 65 | See <Mojo::Sendgrid::Mail> for full list | ||||||||||
| 66 | |||||||||||
| 67 | =head1 ATTRIBUTES | ||||||||||
| 68 | |||||||||||
| 69 | =head2 config | ||||||||||
| 70 | |||||||||||
| 71 | Holds the configuration hash. | ||||||||||
| 72 | |||||||||||
| 73 | =head2 apikey | ||||||||||
| 74 | |||||||||||
| 75 | Accesses the apikey element of L</config>. | ||||||||||
| 76 | Can be overridden by the environment variable SENDGRID_APIKEY. | ||||||||||
| 77 | This attribute is required to have a value. | ||||||||||
| 78 | |||||||||||
| 79 | =head2 apiurl | ||||||||||
| 80 | |||||||||||
| 81 | Accesses the apiurl element of L</config>. | ||||||||||
| 82 | Can be overridden by the environment variable SENDGRID_APIURL. | ||||||||||
| 83 | This attribute by default uses the Web API v2 URL documented by Sendgrid. | ||||||||||
| 84 | |||||||||||
| 85 | =head1 METHODS | ||||||||||
| 86 | |||||||||||
| 87 | =head2 mail | ||||||||||
| 88 | |||||||||||
| 89 | $self = $self->mail(%args); | ||||||||||
| 90 | |||||||||||
| 91 | The mail endpoint of the Sendgrid Web API v2. | ||||||||||
| 92 | |||||||||||
| 93 | =head1 COPYRIGHT | ||||||||||
| 94 | |||||||||||
| 95 | This program is free software, you can redistribute it and/or modify it under | ||||||||||
| 96 | the terms of the Artistic License version 2.0. | ||||||||||
| 97 | |||||||||||
| 98 | =head1 AUTHOR | ||||||||||
| 99 | |||||||||||
| 100 | Stefan Adams - C<sadams@cpan.org> | ||||||||||
| 101 | |||||||||||
| 102 | =cut | ||||||||||