1 package FS::part_event::Action::http;
4 use base qw( FS::part_event::Action );
6 use HTTP::Request::Common;
8 use FS::Misc::DateTime qw( iso8601 );
10 #sub description { 'Send an HTTP or HTTPS GET or POST request'; }
11 sub description { 'Send an HTTP or HTTPS POST request'; }
13 sub eventtable_hashref {
21 'method' => { label => 'Method',
23 options => [qw( POST )], #GET )],
25 'url' => { label => 'URL',
29 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
32 'encoding' => { label => 'Encoding',
34 options => [qw( JSON )], #XML, Form, etc.
36 'content' => { label => 'Content', #nneed better inline docs on format
39 #'response_error_param' => 'Response error parameter',
43 sub default_weight { 57; }
46 'JSON' => 'application/json',
50 my( $self, $object ) = @_;
52 my $cust_main = $self->cust_main($object);
56 /^\s*(\S+)\s+(.*)$/ or /()()/;
57 my( $field, $value_expression ) = ( $1, $2 );
58 my $value = eval $value_expression;
61 } split(/\n/, $self->option('content') );
63 my $content = encode_json( \%content );
66 push @lwp_opts, 'ssl_opts'=>{ 'verify_hostname'=>0 }
67 if $self->option('ssl_no_verify');
68 my $ua = LWP::UserAgent->new(@lwp_opts);
70 my $req = HTTP::Request::Common::POST(
72 Content_Type => $content_type{ $self->option('encoding') },
76 my $response = $ua->request($req);
78 die $response->status_line if $response->is_error;
80 my $response_json = decode_json( $response->content );
81 die $response_json->{error} if $response_json->{error}; #XXX response_error_param