iiplc/II/Send.pm

44 lines
920 B
Perl
Raw Normal View History

2014-06-11 15:55:00 +04:00
package II::Send;
use HTTP::Request::Common qw(POST);
use LWP::UserAgent;
use II::DB;
use Data::Dumper;
sub new {
my $class = shift;
2014-06-17 14:13:53 +04:00
my $db = II::DB->new();
2014-06-11 15:55:00 +04:00
my $self = {
_config => shift,
_echo => shift,
_base64 => shift,
2014-06-17 14:13:53 +04:00
_db => $db,
2014-06-11 15:55:00 +04:00
};
bless $self, $class;
return $self;
}
sub send {
2014-06-17 14:13:53 +04:00
my ( $self, $hash ) = @_;
2014-06-11 15:55:00 +04:00
my $config = $self->{_config};
my $echo = $self->{_echo};
my $base64 = $self->{_base64};
2014-06-17 14:13:53 +04:00
my $db = $self->{_db};
2014-06-11 15:55:00 +04:00
# Push message to server
my $host = $config->{host};
my $auth = $config->{key};
$host .= "u/point";
2015-01-30 09:21:35 +03:00
my $ua = LWP::UserAgent->new(agent => 'Mozilla/5.0 (X11; Linux x86_64; rv:35.0) Gecko/20100101 Firefox/35.0');
2014-06-17 14:13:53 +04:00
my $response
= $ua->post( $host, { 'pauth' => $auth, 'tmsg' => $base64 } );
2014-06-11 15:55:00 +04:00
2014-06-17 14:13:53 +04:00
if ( $response->{_rc} == 200 ) {
$db->update_out($hash);
}
2014-06-11 15:55:00 +04:00
}
1;