]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/OpenILS/Application/Acq/EDI/Translator.pm
Patch from Joe Atzberger that does several things:
[working/Evergreen.git] / Open-ILS / src / perlmods / OpenILS / Application / Acq / EDI / Translator.pm
1 package OpenILS::Application::Acq::EDI::Translator;
2
3 use warnings;
4 use strict;
5
6 use RPC::XML::Client;
7 use Data::Dumper;
8
9 # DEFAULTS
10 my $proto = 'http://';
11 my $host  = $proto . 'localhost';
12 my $path  = '/EDI';
13 my $port  = 9191;
14 my $verbose = 0;
15
16 sub new {
17     my ($class, %args) = @_;
18     my $self = bless(\%args, $class);
19     $self->init;
20     return $self;
21 }
22
23 sub init {
24     my $self = shift;
25     $self->host_cleanup;
26 }
27
28 sub host_cleanup {
29     my $self = shift;
30     my $target = $self->{host} || $host;
31     $target =~ /^\S+:\/\// or $target  = ($self->{proto} || $proto) . $target;
32     $target =~ /:\d+$/     or $target .= ':' . ($self->{port} || $port);
33     $target .= ($self->{path} || $path);
34     $self->{verbose} and print "Cleanup: $self->{host} ==> $target\n";
35     $self->{host} = $target;
36     return $target;
37 }
38
39 sub client {
40     my $self = shift;
41     return $self->{client} ||= RPC::XML::Client->new($self->{host});     # TODO: auth
42 }
43
44 sub json2edi {
45     my $self = shift;
46     my $text = shift;
47     my $client = $self->client();
48     $self->{verbose} and print "Trying json2edi on host: $self->{host}\n";
49     my $resp = $client->send_request('edi2json', $text);
50     $self->{verbose} and print Dumper($resp);
51     return $resp;
52 }
53
54 sub edi2json {
55     my $self = shift;
56     my $text  = shift;
57     my $client = $self->client();
58     $self->{verbose} and print "Trying edi2json on host: $self->{host}\n";
59     my $resp = $client->send_request('json2edi', $text);
60     $self->{verbose} and print Dumper($resp);
61     return $resp;
62 }
63
64 1;
65