1 package FS::part_export::infostreet;
3 use vars qw(@ISA %info %infostreet2cust_main $DEBUG);
8 @ISA = qw(FS::part_export);
10 tie my %options, 'Tie::IxHash',
11 'url' => { label=>'XML-RPC Access URL', },
12 'login' => { label=>'InfoStreet login', },
13 'password' => { label=>'InfoStreet password', },
14 'groupID' => { label=>'InfoStreet groupID', },
19 'desc' => 'Real-time export to InfoStreet streetSmartAPI',
20 'options' => \%options,
24 <a href="http://www.infostreet.com/">InfoStreet</a> streetSmartAPI.
25 Requires installation of
26 <a href="http://search.cpan.org/dist/Frontier-Client">Frontier::Client</a> from CPAN.
32 %infostreet2cust_main = (
33 'firstName' => 'first',
35 'address1' => 'address1',
36 'address2' => 'address2',
40 'country' => 'country',
41 'phoneNumber' => 'daytime',
42 'faxNumber' => 'night', #noment-request...
45 sub rebless { shift; }
48 my( $self, $svc_acct ) = (shift, shift);
49 my $cust_main = $svc_acct->cust_svc->cust_pkg->cust_main;
51 local $SIG{HUP} = 'IGNORE';
52 local $SIG{INT} = 'IGNORE';
53 local $SIG{QUIT} = 'IGNORE';
54 local $SIG{TERM} = 'IGNORE';
55 local $SIG{TSTP} = 'IGNORE';
56 local $SIG{PIPE} = 'IGNORE';
57 my $oldAutoCommit = $FS::UID::AutoCommit;
58 local $FS::UID::AutoCommit = 0;
61 my $err_or_queue = $self->infostreet_err_or_queue( $svc_acct->svcnum,
62 'createUser', $svc_acct->username, $svc_acct->_password );
63 return $err_or_queue unless ref($err_or_queue);
64 my $jobnum = $err_or_queue->jobnum;
66 my %contact_info = ( map {
67 $_ => $cust_main->getfield( $infostreet2cust_main{$_} );
68 } keys %infostreet2cust_main );
70 my @emails = grep { $_ ne 'POST' } $cust_main->invoicing_list;
71 $contact_info{'email'} = $emails[0] if @emails;
73 #this one is kinda noment-specific
74 $contact_info{'organization'} = $cust_main->agent->agent;
76 $err_or_queue = $self->infostreet_queueContact( $svc_acct->svcnum,
77 $svc_acct->username, %contact_info );
78 return $err_or_queue unless ref($err_or_queue);
80 # If a quota has been specified set the quota because it is not the default
81 $err_or_queue = $self->infostreet_queueSetQuota( $svc_acct->svcnum,
82 $svc_acct->username, $svc_acct->quota ) if $svc_acct->quota;
83 return $err_or_queue unless ref($err_or_queue);
85 my $error = $err_or_queue->depend_insert( $jobnum );
86 return $error if $error;
88 $dbh->commit or die $dbh->errstr if $oldAutoCommit;
95 my( $self, $new, $old ) = (shift, shift, shift);
96 return "can't change username with InfoStreet"
97 if $old->username ne $new->username;
99 # If the quota has changed then do the export to setQuota
100 my $err_or_queue = $self->infostreet_queueSetQuota( $new->svcnum, $new->username, $new->quota )
101 if ( $old->quota != $new->quota );
102 return $err_or_queue unless ref($err_or_queue);
105 return '' unless $old->_password ne $new->_password;
106 $self->infostreet_queue( $new->svcnum,
107 'passwd', $new->username, $new->_password );
111 my( $self, $svc_acct ) = (shift, shift);
112 $self->infostreet_queue( $svc_acct->svcnum,
113 'purgeAccount,releaseUsername', $svc_acct->username );
116 sub _export_suspend {
117 my( $self, $svc_acct ) = (shift, shift);
118 $self->infostreet_queue( $svc_acct->svcnum,
119 'setStatus', $svc_acct->username, 'DISABLED' );
122 sub _export_unsuspend {
123 my( $self, $svc_acct ) = (shift, shift);
124 $self->infostreet_queue( $svc_acct->svcnum,
125 'setStatus', $svc_acct->username, 'ACTIVE' );
128 sub infostreet_queue {
129 my( $self, $svcnum, $method ) = (shift, shift, shift);
130 my $queue = new FS::queue {
132 'job' => 'FS::part_export::infostreet::infostreet_command',
135 $self->option('url'),
136 $self->option('login'),
137 $self->option('password'),
138 $self->option('groupID'),
145 sub infostreet_err_or_queue {
146 my( $self, $svcnum, $method ) = (shift, shift, shift);
147 my $queue = new FS::queue {
149 'job' => 'FS::part_export::infostreet::infostreet_command',
152 $self->option('url'),
153 $self->option('login'),
154 $self->option('password'),
155 $self->option('groupID'),
161 sub infostreet_queueContact {
162 my( $self, $svcnum ) = (shift, shift);
163 my $queue = new FS::queue {
165 'job' => 'FS::part_export::infostreet::infostreet_setContact',
168 $self->option('url'),
169 $self->option('login'),
170 $self->option('password'),
171 $self->option('groupID'),
176 sub infostreet_setContact {
177 my($url, $is_username, $is_password, $groupID, $username, %contact_info) = @_;
178 my $accountID = infostreet_command($url, $is_username, $is_password, $groupID,
179 'getAccountID', $username);
180 foreach my $field ( keys %contact_info ) {
181 infostreet_command($url, $is_username, $is_password, $groupID,
182 'setContactField', [ 'int'=>$accountID ], $field, $contact_info{$field} );
187 sub infostreet_queueSetQuota {
189 my( $self, $svcnum) = (shift, shift);
190 my $queue = new FS::queue {
192 'job' => 'FS::part_export::infostreet::infostreet_setQuota',
196 $self->option('url'),
197 $self->option('login'),
198 $self->option('password'),
199 $self->option('groupID'),
205 sub infostreet_setQuota {
206 my($url, $is_username, $is_password, $groupID, $username, $quota) = @_;
207 infostreet_command($url, $is_username, $is_password, $groupID, 'setQuota', $username, [ 'int'=> $quota ] );
211 sub infostreet_command { #subroutine, not method
212 my($url, $username, $password, $groupID, $method, @args) = @_;
214 warn "[FS::part_export::infostreet] $method ".join(' ', @args)."\n" if $DEBUG;
217 if ( $method =~ /,/ ) {
218 foreach my $part ( split(/,\s*/, $method) ) {
219 infostreet_command($url, $username, $password, $groupID, $part, @args);
224 eval "use Frontier::Client;";
227 eval 'sub Frontier::RPC2::String::repr {
230 $value =~ s/([&<>\"])/$Frontier::RPC2::char_entities{$1}/ge;
235 my $conn = Frontier::Client->new( url => $url );
236 my $key_result = $conn->call( 'authenticate', $username, $password, $groupID);
237 my %key_result = _infostreet_parse($key_result);
238 die $key_result{error} unless $key_result{success};
239 my $key = $key_result{data};
241 #my $result = $conn->call($method, $key, @args);
242 my $result = $conn->call( $method, $key,
245 my( $type, $value) = @{$_};
246 $conn->$type($value);
251 my %result = _infostreet_parse($result);
252 die $result{error} unless $result{success};
258 #sub infostreet_command_byid { #subroutine, not method;
259 # my($url, $username, $password, $groupID, $method, @args ) = @_;
265 sub _infostreet_parse { #subroutine, not method
268 my $value = $arg->{$_};
270 $value = $value->value()
271 if ref($value) && $value->isa('Frontier::RPC2::DataType');