This commit was generated by cvs2svn to compensate for changes in r4407,
[freeside.git] / rt / lib / RT / URI / freeside / XMLRPC.pm
1 # BEGIN LICENSE BLOCK
2
3 # Copyright (c) 2004 Kristian Hoffmann <khoff@fire2wire.com>
4 # Based on the original RT::URI::base and RT::URI::fsck_com_rt.
5
6 # Copyright (c) 1996-2003 Jesse Vincent <jesse@bestpractical.com>
7
8 # (Except where explictly superceded by other copyright notices)
9
10 # This work is made available to you under the terms of Version 2 of
11 # the GNU General Public License. A copy of that license should have
12 # been provided with this software, but in any event can be snarfed
13 # from www.gnu.org.
14
15 # This work is distributed in the hope that it will be useful, but
16 # WITHOUT ANY WARRANTY; without even the implied warranty of
17 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
18 # General Public License for more details.
19
20 # Unless otherwise specified, all modifications, corrections or
21 # extensions to this work which alter its source code become the
22 # property of Best Practical Solutions, LLC when submitted for
23 # inclusion in the work.
24
25
26 # END LICENSE BLOCK
27
28 use strict;
29 no warnings qw(redefine);
30
31 use vars qw($XMLRPC_URL $_FS_VERSION);
32
33 use Frontier::Client;
34
35 =head1 NAME
36
37 RT::URI::freeside::XMLRPC
38
39 =head1 DESCRIPTION
40
41 Overlay for the RT::URI::freeside URI handler implementing the XMLRPC integration type.
42
43 See L<RT::URI::freeside> for public/private interface documentation.
44
45 =cut
46
47
48 sub _XMLRPCRequest { #Subroutine
49
50   my $method = shift;
51   my @args = @_;
52
53   my $result;
54   eval {
55     my $server = new Frontier::Client ( url => $XMLRPC_URL );
56     $result = $server->call($method, @args);
57   };
58
59   if (not $@ and ref($result) eq 'ARRAY') {
60     return (scalar(@$result) == 1) ? @$result[0] : @$result;
61   } else {
62     $RT::Logger->debug("Freeside XMLRPC: " . $result || $@);
63     return ();
64   }
65
66 }
67
68 sub _FreesideGetRecord {
69
70   my $self = shift;
71   my ($table, $pkey) = ($self->{'fstable'}, $self->{'fspkey'});
72   my $record;
73
74   $RT::Logger->debug("Called XMLRPC::_FreesideGetRecord()");
75
76   #FIXME: Need a better way to get primary keys.
77   # Maybe create a method for it and cache them like version?
78   my %table_pkeys = (
79     cust_main => 'custnum',
80   );
81     
82   my $method = 'Record.qsearchs';
83   my @args = ($table, { $table_pkeys{$table} => $pkey });
84   my ($record) = &_XMLRPCRequest($method, @args);
85
86   return $record;
87
88 }
89
90
91 sub FreesideGetConfig {
92
93   return _XMLRPCRequest('Conf.config', @_);
94
95 }
96
97
98 sub FreesideVersion {
99
100   return $_FS_VERSION if ($_FS_VERSION =~ /^\d+\.\d+\.\d+/);
101
102   $RT::Logger->debug("Requesting freeside version...");
103   ($_FS_VERSION) = &_XMLRPCRequest('version');
104   $RT::Logger->debug("Cached freeside version: ${_FS_VERSION}");
105  
106   return $_FS_VERSION;
107
108 }
109
110 sub smart_search { #Subroutine
111
112   return _XMLRPCRequest('cust_main.smart_search', @_);
113
114 }
115
116 sub small_custview {
117
118   return _XMLRPCRequest('CGI.small_custview', @_);
119
120 }
121
122 1;