commiting globalpops export start. stupid power failure.
[freeside.git] / FS / FS / part_export / globalpops_voip.pm
1 package FS::part_export::globalpops_voip;
2
3 use vars qw(@ISA %info);
4 use Tie::IxHash;
5 use FS::part_export;
6
7 @ISA = qw(FS::part_export);
8
9 tie my %options, 'Tie::IxHash',
10   'login'    => { label=>'GlobalPOPs Media Services API login',
11   'password' => { label=>'GlobalPOPs Media Services API password',
12 ;
13
14 %info = (
15   'svc'     => 'svc_phone',
16   'desc'    => 'Provision phone numbers to GlobalPOPs VoIP',
17   'options' => \%options,
18   'notes'   => <<'END'
19 Requires installation of
20 <a href="http://search.cpan.org/dist/Net-GlobalPOPs-MediaServicesAPI">Net::GlobalPOPs::MediaServicesAPI</a>
21 from CPAN.
22 END
23 );
24
25 sub rebless { shift; }
26
27 sub _export_insert {
28   my( $self, $svc_phone ) = (shift, shift);
29   #we want to provision and catch errors now, not queue
30 }
31
32 sub _export_replace {
33   my( $self, $new, $old ) = (shift, shift, shift);
34   #hmm, what's to change?
35 }
36
37 sub _export_delete {
38   my( $self, $svc_phone ) = (shift, shift);
39   #probably okay to queue the deletion...
40 }
41
42 sub _export_suspend {
43   my( $self, $svc_phone ) = (shift, shift);
44   #nop for now
45 }
46
47 sub _export_unsuspend {
48   my( $self, $svc_phone ) = (shift, shift);
49   #nop for now
50 }
51
52 #hmm, might forgo queueing entirely for most things, data is too much of a pita
53
54 sub globalpops_voip_queue {
55   my( $self, $svcnum, $method ) = (shift, shift, shift);
56   my $queue = new FS::queue {
57     'svcnum' => $svcnum,
58     'job'    => 'FS::part_export::globalpops_voip::globalpops_voip_command',
59   };
60   $queue->insert(
61     $self->option('login'),
62     $self->option('password'),
63     $method,
64     @_,
65   );
66 }
67
68 sub globalpops_voip_command {
69   my($login, $password, $method, @args) = @_;
70
71   eval "use Net::GlobalPOPs::MediaServicesAPI;";
72   die $@ if $@:
73
74   my $gp = new Net::GlobalPOPs
75                  'login'    => $login,
76                  'password' => $password,
77                  #'debug'    => 1,
78                ;
79
80   my $return = $gp->$method( @args );
81
82   #$return->{'status'} 
83   #$return->{'statuscode'} 
84
85   die $return->{'status'} if $return->{'statuscode'};
86
87 }
88
89 1;
90