export host selection per service, RT#17914
[freeside.git] / FS / FS / part_export / http_status.pm
1 package FS::part_export::http_status;
2 use base qw( FS::part_export );
3
4 use strict;
5 use warnings;
6 use vars qw( %info );
7 use LWP::UserAgent;
8 use HTTP::Request::Common;
9
10 tie my %options, 'Tie::IxHash',
11   'url' => { label => 'URL', },
12   #'user'     => { label => 'Username', default=>'' },
13   #'password' => { label => 'Password', default => '' },
14 ;
15
16 %info = (
17   'svc'     => 'svc_dsl',
18   'desc'    => 'Retrieve status information via HTTP or HTTPS',
19   'options' => \%options,
20   'no_machine' => 1,
21   'notes'   => <<'END'
22 Fields from the service can be substituted in the URL as $field.
23 END
24 );
25
26 sub rebless { shift; }
27
28 sub export_getstatus {
29   my( $self, $svc_x, $htmlref, $hashref ) = @_;
30
31   my $url;
32   my $urlopt = $self->option('url');
33   no strict 'vars';
34   {
35     no strict 'refs';
36     ${$_} = $svc_x->getfield($_) foreach $svc_x->fields;
37     if ( $svc_x->table eq 'svc_dsl' ) {
38       ${$_} = $svc_x->$_() foreach (qw( gateway_access_or_phonenum ));
39     }
40
41     $url = eval(qq("$urlopt"));
42   }
43
44   my $req = HTTP::Request::Common::GET( $url );
45   my $ua = LWP::UserAgent->new;
46   my $response = $ua->request($req);
47
48   $$htmlref = $response->is_error ? $response->error_as_HTML
49                                   : $response->content;
50
51   #hash data note yet implemented for this status export
52
53 }
54
55 1;