1 package FS::part_event::Action::http;
4 use base qw( FS::part_event::Action );
7 use HTTP::Request::Common;
9 use FS::Misc::DateTime qw( iso8601 );
11 #sub description { 'Send an HTTP or HTTPS GET or POST request'; }
12 sub description { 'Send an HTTP or HTTPS POST request'; }
14 sub eventtable_hashref {
22 'method' => { label => 'Method',
24 options => [qw( POST )], #GET )],
26 'url' => { label => 'URL',
30 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
33 'encoding' => { label => 'Encoding',
35 options => [qw( JSON )], #XML, Form, etc.
37 'content' => { label => 'Content', #nneed better inline docs on format
40 #'response_error_param' => 'Response error parameter',
44 sub default_weight { 57; }
47 'JSON' => 'application/json',
51 my( $self, $object ) = @_;
53 my $cust_main = $self->cust_main($object);
57 /^\s*(\S+)\s+(.*)$/ or /()()/;
58 my( $field, $value_expression ) = ( $1, $2 );
59 my $value = eval $value_expression;
62 } split(/\n/, $self->option('content') );
64 if ( $self->option('debug') ) {
65 warn "[$me] $_: ". $content{$_}. "\n" foreach keys %content;
68 my $content = encode_json( \%content );
71 push @lwp_opts, 'ssl_opts' => {
73 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
75 if $self->option('ssl_no_verify');
76 my $ua = LWP::UserAgent->new(@lwp_opts);
78 my $req = HTTP::Request::Common::POST(
80 Content_Type => $content_type{ $self->option('encoding') },
84 my $response = $ua->request($req);
86 die $response->status_line if $response->is_error;
88 my $response_json = decode_json( $response->content );
89 die $response_json->{error} if $response_json->{error}; #XXX response_error_param