1 package FS::part_event::Action::http;
2 use base qw( FS::part_event::Action );
9 use HTTP::Request::Common;
11 use FS::Misc::DateTime qw( iso8601 );
13 $me = '[FS::part_event::Action::http]';
15 #sub description { 'Send an HTTP or HTTPS GET or POST request'; }
16 sub description { 'Send an HTTP or HTTPS POST request'; }
18 sub eventtable_hashref {
26 'method' => { label => 'Method',
28 options => [qw( POST )], #GET )],
30 'url' => { label => 'URL',
34 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
37 'encoding' => { label => 'Encoding',
39 options => [qw( JSON )], #XML, Form, etc.
41 'content' => { label => 'Content', #nneed better inline docs on format
44 #'response_error_param' => 'Response error parameter',
45 'debug' => { label => 'Enable debugging',
52 sub default_weight { 57; }
55 'JSON' => 'application/json',
59 my( $self, $object ) = @_;
61 my $cust_main = $self->cust_main($object);
65 /^\s*(\S+)\s+(.*)$/ or /()()/;
66 my( $field, $value_expression ) = ( $1, $2 );
67 my $value = eval $value_expression;
70 } split(/\n/, $self->option('content') );
72 if ( $self->option('debug') ) {
73 warn "[$me] $_: ". $content{$_}. "\n" foreach keys %content;
76 my $content = encode_json( \%content );
79 push @lwp_opts, 'ssl_opts' => {
81 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
83 if $self->option('ssl_no_verify');
84 my $ua = LWP::UserAgent->new(@lwp_opts);
86 my $req = HTTP::Request::Common::POST(
88 Content_Type => $content_type{ $self->option('encoding') },
92 if ( $self->option('debug') ) {
93 #XXX dump raw request for debugging
95 my $response = $ua->request($req);
97 die $response->status_line if $response->is_error;
99 my $response_json = decode_json( $response->content );
100 die $response_json->{error} if $response_json->{error}; #XXX response_error_param