5342106b467032fcbd3ba4fa1426da77162aea15
[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   'notes'   => <<'END'
21 Fields from the service can be substituted in the URL as $field.
22 END
23 );
24
25 sub rebless { shift; }
26
27 sub export_getstatus {
28   my( $self, $svc_x, $htmlref, $hashref ) = @_;
29
30   my $url;
31   my $urlopt = $self->option('url');
32   no strict 'vars';
33   {
34     no strict 'refs';
35     ${$_} = $svc_x->getfield($_) foreach $svc_x->fields;
36     if ( $svc_x->table eq 'svc_dsl' ) {
37       ${$_} = $svc_x->$_() foreach (qw( gateway_access_or_phonenum ));
38     }
39
40     $url = eval(qq("$urlopt"));
41   }
42
43   my $req = HTTP::Request::Common::GET( $url );
44   my $ua = LWP::UserAgent->new;
45   my $response = $ua->request($req);
46
47   $$htmlref = $response->is_error ? $response->error_as_HTML
48                                   : $response->content;
49
50   #hash data note yet implemented for this status export
51
52 }
53
54 1;