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;
94 $self->http_queue( $svc_x->svcnum,
95 $self->option('method'),
98 /^\s*(\S+)\s+(.*)$/ or /()()/;
99 my( $field, $value_expression ) = ( $1, $2 );
102 } split(/\n/, $self->option('replace_data') )
108 my($self, $svcnum) = (shift, shift);
109 my $queue = new FS::queue { 'job' => "FS::part_export::http::http" };
110 $queue->svcnum($svcnum) if $svcnum;
111 $queue->insert( @_ );
115 my($method, $url, @data) = @_;
117 $method = lc($method);
119 eval "use LWP::UserAgent;";
120 die "using LWP::UserAgent: $@" if $@;
121 eval "use HTTP::Request::Common;";
122 die "using HTTP::Request::Common: $@" if $@;
124 my $ua = LWP::UserAgent->new;
126 #my $response = $ua->$method(
128 # 'Content-Type'=>'application/x-www-form-urlencoded'
130 my $req = HTTP::Request::Common::POST( $url, \@data );
131 my $response = $ua->request($req);
133 die $response->error_as_HTML if $response->is_error;