1 package FS::part_export::http;
3 use base qw( FS::part_export );
4 use vars qw( %options %info );
7 tie %options, 'Tie::IxHash',
8 'method' => { label =>'Method',
10 #options =>[qw(POST GET)],
13 'url' => { label => 'URL', default => 'http://', },
15 label => 'Insert data',
18 'DomainName $svc_x->domain',
19 'Email ( grep { $_ !~ /^(POST|FAX)$/ } $svc_x->cust_svc->cust_pkg->cust_main->invoicing_list)[0]',
21 'reseller $svc_x->cust_svc->cust_pkg->part_pkg->pkg =~ /reseller/i',
25 label => 'Delete data',
31 label => 'Replace data',
39 'svc' => 'svc_domain',
40 'desc' => 'Send an HTTP or HTTPS GET or POST request',
41 'options' => \%options,
43 Send an HTTP or HTTPS GET or POST to the specified URL. For HTTPS support,
44 <a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
45 or <a href="http://search.cpan.org/dist/IO-Socket-SSL">IO::Socket::SSL</a>
50 sub rebless { shift; }
54 $self->_export_command('insert', @_);
59 $self->_export_command('delete', @_);
63 my( $self, $action, $svc_x ) = ( shift, shift, shift );
65 return unless $self->option("${action}_data");
67 my $cust_main = $svc_x->table eq 'cust_main'
69 : $svc_x->cust_svc->cust_pkg->cust_main;
71 $self->http_queue( $svc_x->svcnum,
72 $self->option('method'),
75 /^\s*(\S+)\s+(.*)$/ or /()()/;
76 my( $field, $value_expression ) = ( $1, $2 );
77 my $value = eval $value_expression;
80 } split(/\n/, $self->option("${action}_data") )
86 my( $self, $new, $old ) = ( shift, shift, shift );
88 return unless $self->option('replace_data');
90 my $new_cust_main = $new->table eq 'cust_main'
92 : $new->cust_svc->cust_pkg->cust_main;
93 my $cust_main = $new_cust_main; #so folks can use $new_cust_main or $cust_main
95 $self->http_queue( $new->svcnum,
96 $self->option('method'),
99 /^\s*(\S+)\s+(.*)$/ or /()()/;
100 my( $field, $value_expression ) = ( $1, $2 );
101 my $value = eval $value_expression;
104 } split(/\n/, $self->option('replace_data') )
110 my($self, $svcnum) = (shift, shift);
111 my $queue = new FS::queue { 'job' => "FS::part_export::http::http" };
112 $queue->svcnum($svcnum) if $svcnum;
113 $queue->insert( @_ );
117 my($method, $url, @data) = @_;
119 $method = lc($method);
121 eval "use LWP::UserAgent;";
122 die "using LWP::UserAgent: $@" if $@;
123 eval "use HTTP::Request::Common;";
124 die "using HTTP::Request::Common: $@" if $@;
126 my $ua = LWP::UserAgent->new;
128 #my $response = $ua->$method(
130 # 'Content-Type'=>'application/x-www-form-urlencoded'
132 my $req = HTTP::Request::Common::POST( $url, \@data );
133 my $response = $ua->request($req);
135 die $response->error_as_HTML if $response->is_error;