1 package FS::part_export::http;
3 use vars qw(@ISA %info);
7 @ISA = qw(FS::part_export);
9 tie my %options, 'Tie::IxHash',
10 'method' => { label =>'Method',
12 #options =>[qw(POST GET)],
15 'url' => { label => 'URL', default => 'http://', },
17 label => 'Insert data',
20 'DomainName $svc_x->domain',
21 'Email ( grep { $_ !~ /^(POST|FAX)$/ } $svc_x->cust_svc->cust_pkg->cust_main->invoicing_list)[0]',
23 'reseller $svc_x->cust_svc->cust_pkg->part_pkg->pkg =~ /reseller/i',
27 label => 'Delete data',
33 label => 'Replace data',
41 'svc' => 'svc_domain',
42 'desc' => 'Send an HTTP or HTTPS GET or POST request',
43 'options' => \%options,
45 Send an HTTP or HTTPS GET or POST to the specified URL. For HTTPS support,
46 <a href="http://search.cpan.org/dist/Crypt-SSLeay">Crypt::SSLeay</a>
47 or <a href="http://search.cpan.org/dist/IO-Socket-SSL">IO::Socket::SSL</a>
52 sub rebless { shift; }
56 $self->_export_command('insert', @_);
61 $self->_export_command('delete', @_);
65 my( $self, $action, $svc_x ) = ( shift, shift, shift );
67 return unless $self->option("${action}_data");
69 $self->http_queue( $svc_x->svcnum,
70 $self->option('method'),
73 /^\s*(\S+)\s+(.*)$/ or /()()/;
74 my( $field, $value_expression ) = ( $1, $2 );
75 my $value = eval $value_expression;
78 } split(/\n/, $self->option("${action}_data") )
84 my( $self, $new, $old ) = ( shift, shift, shift );
86 return unless $self->option('replace_data');
88 $self->http_queue( $svc_x->svcnum,
89 $self->option('method'),
92 /^\s*(\S+)\s+(.*)$/ or /()()/;
93 my( $field, $value_expression ) = ( $1, $2 );
96 } split(/\n/, $self->option('replace_data') )
102 my($self, $svcnum) = (shift, shift);
103 my $queue = new FS::queue {
105 'job' => "FS::part_export::http::http",
107 $queue->insert( @_ );
111 my($method, $url, @data) = @_;
113 $method = lc($method);
115 eval "use LWP::UserAgent;";
116 die "using LWP::UserAgent: $@" if $@;
117 eval "use HTTP::Request::Common;";
118 die "using HTTP::Request::Common: $@" if $@;
120 my $ua = LWP::UserAgent->new;
122 #my $response = $ua->$method(
124 # 'Content-Type'=>'application/x-www-form-urlencoded'
126 my $req = HTTP::Request::Common::POST( $url, \@data );
127 my $response = $ua->request($req);
129 die $response->error_as_HTML if $response->is_error;