File Coverage

blib/lib/Mojo/Sendgrid.pm
Criterion Covered Total %
statement 7 7 100.0
branch n/a
condition n/a
subroutine 3 3 100.0
pod 1 1 100.0
total 11 11 100.0


line stmt bran cond sub pod time code
1             package Mojo::Sendgrid;
2 1     1   262076 use Mojo::Base 'Mojo::EventEmitter';
  1         2  
  1         4  
3              
4 1     1   421 use Mojo::Sendgrid::Mail;
  1         2  
  1         6  
5              
6             our $VERSION = '0.05';
7              
8             has apikey => sub { $ENV{SENDGRID_APIKEY} or die "config apikey missing" };
9             has apiurl => sub { $ENV{SENDGRID_APIURL} || 'https://api.sendgrid.com/api/mail.send.json' };
10              
11 3     3 1 9329 sub mail { Mojo::Sendgrid::Mail->new(sendgrid => shift, @_) }
12              
13             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 is an implementation of the Sendgrid API and is non-blocking
53             thanks to L from the wonderful L framework.
54              
55             It currently implements the mail endpoint of the Web API v2.
56              
57             This class inherits from L.
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 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.
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.
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
101              
102             =cut