GithubHelp home page GithubHelp logo

toonvd / p5-web-service-mailgun Goto Github PK

View Code? Open in Web Editor NEW

This project forked from kan/p5-web-service-mailgun

0.0 2.0 0.0 45 KB

API client for https://mailgun.com/

License: Other

Perl 98.86% Dockerfile 1.14%

p5-web-service-mailgun's Introduction

Build Status Coverage Status

NAME

WebService::Mailgun - API client for Mailgun (https://mailgun.com/)

SYNOPSIS

use WebService::Mailgun;

my $mailgun = WebService::Mailgun->new(
    api_key => '<YOUR_API_KEY>',
    domain => '<YOUR_MAIL_DOMAIN>',
);

# send mail
my $res = $mailgun->message({
    from    => '[email protected]',
    to      => '[email protected]',
    subject => 'test',
    text    => 'text',
});

DESCRIPTION

WebService::Mailgun is API client for Mailgun (https://mailgun.com/).

METHOD

new(api_key => $api_key, domain => $domain, RaiseError => 0|1)

Create mailgun object.

RaiseError (default: 0)

The RaiseError attribute can be used to force errors to raise exceptions rather than simply return error codes in the normal way. It is "off" by default.

error

return recent error message.

error_status

return recent API result status_line.

message($args)

Send email message.

# send mail
my $res = $mailgun->message({
    from    => '[email protected]',
    to      => '[email protected]',
    subject => 'test',
    text    => 'text',
});

https://documentation.mailgun.com/api-sending.html#sending

lists()

Get list of mailing lists.

# get mailing lists
my $lists = $mailgun->lists();
# => ArrayRef of mailing list object.

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

add_list($args)

Add mailing list.

# add mailing list
my $res = $mailgun->add_list({
    address => '[email protected]', # Mailing list address
    name    => 'ml sample',      # Mailing list name (Optional)
    description => 'sample',     # description (Optional)
    access_level => 'members',   # readonly(default), members, everyone
});

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

list($address)

Get detail for mailing list.

# get mailing list detail
my $data = $mailgun->list('[email protected]');

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

update_list($address, $args)

Update mailing list detail.

# update mailing list
my $res = $mailgun->update_list('[email protected]' => {
    address => '[email protected]', # Mailing list address (Optional)
    name    => 'ml sample',      # Mailing list name (Optional)
    description => 'sample',     # description (Optional)
    access_level => 'members',   # readonly(default), members, everyone
});

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

delete_list($address)

Delete mailing list.

# delete mailing list
my $res = $mailgun->delete_list('[email protected]');

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

list_members($address)

Get members for mailing list.

# get members
my $res = $mailgun->list_members('[email protected]');

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

add_list_member($address, $args)

Add member for mailing list.

# add member
my $res = $mailgun->add_list_member('[email protected]' => {
    address => '[email protected]', # member address
    name    => 'username',         # member name (Optional)
    vars    => '{"age": 34}',      # member params(JSON string) (Optional)
    subscribed => 'yes',           # yes(default) or no
    upsert     => 'no',            # no (default). if yes, update exists member
});

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

add_list_members($address, $args)

Adds multiple members for mailing list.

use JSON::XS; # auto export 'encode_json'

# add members
my $res = $mailgun->add_list_members('[email protected]' => {
    members => encode_json [
        { address => '[email protected]' },
        { address => '[email protected]' },
        { address => '[email protected]' },
    ],
    upsert  => 'no',            # no (default). if yes, update exists member
});

# too simple
my $res = $mailgun->add_list_members('[email protected]' => {
    members => encode_json [qw/[email protected] [email protected]/],
});

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

list_member($address, $member_address)

Get member detail.

# update member
my $res = $mailgun->list_member('[email protected]', '[email protected]');

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

update_list_member($address, $member_address, $args)

Update member detail.

# update member
my $res = $mailgun->update_list_member('[email protected]', '[email protected]' => {
    address => '[email protected]', # member address (Optional)
    name    => 'username',         # member name (Optional)
    vars    => '{"age": 34}',      # member params(JSON string) (Optional)
    subscribed => 'yes',           # yes(default) or no
});

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

delete_list_members($address, $member_address)

Delete member for mailing list.

# delete member
my $res = $mailgun->delete_list_member('[email protected]' => '[email protected]');

https://documentation.mailgun.com/api-mailinglists.html#mailing-lists

event($args)

Get event data.

# get event data
my ($events, $purl) = $mailgun->event({ event => 'stored', limit => 50 });

Events

get_message_from_event($event)

Get stored message.

# get event data
my ($events, $purl) = $mailgun->event({ event => 'stored' });
my $msg = $mailgun->get_message_from_event($events->[0]);

Stored Message

Event Pooling

event method return previous url. it can use for fetch event.

# event Pooling
my ($events, $purl) = $mailgun->event({ event => 'stored', begin => localtime->epoch() });
// do something ...
$events = $mailgun->event($purl);
// ...

Event Polling

TODO

this API not implement yet.

SEE ALSO

WWW::Mailgun, https://documentation.mailgun.com/

LICENSE

Copyright (C) Kan Fushihara.

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

AUTHOR

Kan Fushihara [email protected]

p5-web-service-mailgun's People

Contributors

joshrabinowitz avatar kan avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.