1 package FS::part_event::Action::http;
2 use base qw( FS::part_event::Action );
8 use HTTP::Request::Common;
10 use FS::Misc::DateTime qw( iso8601 );
12 $me = '[FS::part_event::Action::http]';
14 #sub description { 'Send an HTTP or HTTPS GET or POST request'; }
15 sub description { 'Send an HTTP or HTTPS POST request'; }
17 sub eventtable_hashref {
25 'method' => { label => 'Method',
27 options => [qw( POST )], #GET )],
29 'url' => { label => 'URL',
33 'ssl_no_verify' => { label => 'Skip SSL certificate validation',
36 'encoding' => { label => 'Encoding',
38 options => [qw( JSON )], #XML, Form, etc.
40 'content' => { label => 'Content', #nneed better inline docs on format
43 #'response_error_param' => 'Response error parameter',
44 'debug' => { label => 'Enable debugging',
51 sub default_weight { 57; }
54 'JSON' => 'application/json',
58 my( $self, $object ) = @_;
60 my $cust_main = $self->cust_main($object);
64 /^\s*(\S+)\s+(.*)$/ or /()()/;
65 my( $field, $value_expression ) = ( $1, $2 );
66 my $value = eval $value_expression;
69 } split(/\n/, $self->option('content') );
71 if ( $self->option('debug') ) {
72 warn "[$me] $_: ". $content{$_}. "\n" foreach keys %content;
75 my $content = encode_json( \%content );
78 push @lwp_opts, 'ssl_opts' => {
80 SSL_verify_mode => IO::Socket::SSL::SSL_VERIFY_NONE,
82 if $self->option('ssl_no_verify');
83 my $ua = LWP::UserAgent->new(@lwp_opts);
85 my $req = HTTP::Request::Common::POST(
87 Content_Type => $content_type{ $self->option('encoding') },
91 if ( $self->option('debug') ) {
92 #XXX dump raw request for debugging
94 my $response = $ua->request($req);
96 die $response->status_line if $response->is_error;
98 my $response_json = decode_json( $response->content );
99 die $response_json->{error} if $response_json->{error}; #XXX response_error_param