Plagger::Plugin::Notify::NetSend - Notify feed updates to Windows Messenger Service


Plagger documentation Contained in the Plagger distribution.

Index


Code Index:

NAME

Top

Plagger::Plugin::Notify::NetSend - Notify feed updates to Windows Messenger Service

SYNOPSIS

Top

  - module: Notify::NetSend
    config:
      target_netbios_name: client
      source_netbios_name: plagger
      target_ip: 192.168.0.1

DESCRIPTION

Top

This plugin notifies feed updates to Windows Messenger Service

AUTHOR

Top

Jiro Nishiguchi

SEE ALSO

Top

Plagger, Net::NetSend


Plagger documentation Contained in the Plagger distribution.

package Plagger::Plugin::Notify::NetSend;
use strict;
use warnings;
use base qw(Plagger::Plugin);

use Encode;
use Net::NetSend;

sub register {
    my ($self, $context) = @_;
    $context->register_hook(
        $self,
        'publish.feed' => \&update,
    );
}

sub update {
    my ($self, $context, $args) = @_;
    my $target_netbios_name = $self->conf->{target_netbios_name};
    $target_netbios_name ||= Net::NetSend::getNbName($self->conf->{target_ip});
    unless ($target_netbios_name) {
        $context->log(error => "No netbios name found: $@");
        return;
    }
    my $body = $self->templatize($context, $args->{feed});
    my $success = Net::NetSend::sendMsg(
        $target_netbios_name,
        $self->conf->{source_netbios_name},
        $self->conf->{target_ip},
        encode('shift-jis', $body),
    );
    $context->log(error => "Error in delivery! \n$@") unless $success;
}

sub templatize {
    my ($self, $context, $feed) = @_;
    my $tt = $context->template();
    $tt->process('net_send_notify.tt', {
        feed => $feed,
    }, \my $out) or $context->error($tt->error);
    $out;
}

1;
__END__