iiplc/II/Send.pm
Difrex(Denis Zheleztsov) b4463e7605 Fixes
2014-06-17 14:13:53 +04:00

44 lines
841 B
Perl

package II::Send;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use II::DB;
use Data::Dumper;
sub new {
my $class = shift;
my $db = II::DB->new();
my $self = {
_config => shift,
_echo => shift,
_base64 => shift,
_db => $db,
};
bless $self, $class;
return $self;
}
sub send {
my ( $self, $hash ) = @_;
my $config = $self->{_config};
my $echo = $self->{_echo};
my $base64 = $self->{_base64};
my $db = $self->{_db};
# Push message to server
my $host = $config->{host};
my $auth = $config->{key};
$host .= "u/point";
my $ua = LWP::UserAgent->new();
my $response
= $ua->post( $host, { 'pauth' => $auth, 'tmsg' => $base64 } );
if ( $response->{_rc} == 200 ) {
$db->update_out($hash);
}
}
1;