2ce55633994d061c039d92becccdd00e7ae11925
[freeside.git] / FS / FS / part_export / infostreet.pm
1 package FS::part_export::infostreet;
2
3 use vars qw(@ISA);
4 use FS::part_export;
5
6 @ISA = qw(FS::part_export);
7
8 sub rebless { shift; }
9
10 sub _export_insert {
11   my( $self, $svc_acct ) = (shift, shift);
12   $self->infostreet_queue( $svc_acct->svcnum,
13     'createUser', $svc_acct->username, $svc_acct->_password );
14 }
15
16 sub _export_replace {
17   my( $self, $new, $old ) = (shift, shift, shift);
18   return "can't change username with InfoStreet"
19     if $old->username ne $new->username;
20   return '' unless $old->_password ne $new->_password;
21   $self->infostreet_queue( $new->svcnum,
22     'passwd', $new->username, $new->_password );
23 }
24
25 sub _export_delete {
26   my( $self, $svc_acct ) = (shift, shift);
27   $self->infostreet_queue( $svc_acct->svcnum,
28     'purgeAccount,releaseUsername', $svc_acct->username );
29 }
30
31 sub infostreet_queue {
32   my( $self, $svcnum, $method ) = (shift, shift, shift);
33   my $queue = new FS::queue {
34     'svcnum' => $svcnum,
35     'job'    => 'FS::part_export::infostreet::infostreet_command',
36   };
37   $queue->insert(
38     $self->option('url'),
39     $self->option('login'),
40     $self->option('password'),
41     $self->option('groupID'),
42     $method,
43     @_,
44   );
45 }
46
47 sub infostreet_command { #subroutine, not method
48   my($url, $username, $password, $groupID, $method, @args) = @_;
49
50   #quelle hack
51   if ( $method =~ /,/ ) {
52     foreach my $part ( split(/,\s*/, $method) ) {
53       infostreet_command($url, $username, $password, $groupID, $part, @args);
54     }
55     return;
56   }
57
58   eval "use Frontier::Client;";
59
60   my $conn = Frontier::Client->new( url => $url );
61   my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
62   my %key_result = _infostreet_parse($key_result);
63   die $key_result{error} unless $key_result{success};
64   my $key = $key_result{data};
65
66   #my $result = $conn->call($method, $key, @args);
67   my $result = $conn->call($method, $key, map { $conn->string($_) } @args);
68   my %result = _infostreet_parse($result);
69   die $result{error} unless $result{success};
70
71 }
72
73 sub _infostreet_parse { #subroutine, not method
74   my $arg = shift;
75   map {
76     my $value = $arg->{$_};
77     #warn ref($value);
78     $value = $value->value()
79       if ref($value) && $value->isa('Frontier::RPC2::DataType');
80     $_=>$value;
81   } keys %$arg;
82 }
83
84