aboutsummaryrefslogtreecommitdiffstats
path: root/perllib/Integrations/AngusSOAP.pm
blob: 5f100993ba6e74f46830ae70164b37aa36a761b6 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
package Integrations::AngusSOAP;

# Generated by SOAP::Lite (v0.715) for Perl -- soaplite.com
# Copyright (C) 2000-2006 Paul Kulchenko, Byrne Reese
# -- generated at [Thu Dec 17 15:16:47 2015]
# -- generated from https://webserviceslive.angus.gov.uk/acwebservices.cfc?wsdl
# -- generated with the stubmaker.pl script from SOAP::Lite

# Angus provide endpoints for testing and production, make sure we're using the right one.
use FixMyStreet;
my $TEST_ENDPOINT = 'https://webservicestest.angus.gov.uk/acwebservices.cfc';
my $LIVE_ENDPOINT = 'https://webserviceslive.angus.gov.uk/acwebservices.cfc';
my $ENDPOINT = FixMyStreet->config('STAGING_SITE') ? $TEST_ENDPOINT : $LIVE_ENDPOINT;

# It can be helpful to override the endpoint URL e.g. for dev or testing
$ENDPOINT = FixMyStreet->config('ANGUS_ENDPOINT') ? FixMyStreet->config('ANGUS_ENDPOINT') : $ENDPOINT;

my %methods = (
'GetLocaleInfo' => {
    endpoint => $ENDPOINT,
    soapaction => '',
    namespace => 'http://DefaultNamespace',
    parameters => [
      SOAP::Data->new(name => 'authenticationtoken', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'uprn', type => 'xsd:string', attr => {}),
    ], # end parameters
  }, # end GetLocaleInfo
'AuthenticateJADU' => {
    endpoint => $ENDPOINT,
    soapaction => '',
    namespace => 'http://DefaultNamespace',
    parameters => [
    ], # end parameters
  }, # end AuthenticateJADU
'CreateServiceRequest' => {
    endpoint => $ENDPOINT,
    soapaction => '',
    namespace => 'http://DefaultNamespace',
    parameters => [
      SOAP::Data->new(name => 'authenticationtoken', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'CallerId', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'CallerAddressId', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'DeliveryId', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'DeliveryAddressId', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'CRMRequestType', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'JADUXFormRef', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'PaymentRef', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'JADUFormFields', type => 'xsd:string', attr => {}),
    ], # end parameters
  }, # end CreateServiceRequest
'PropertySearch' => {
    endpoint => $ENDPOINT,
    soapaction => '',
    namespace => 'http://DefaultNamespace',
    parameters => [
      SOAP::Data->new(name => 'authenticationtoken', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'postcode', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'streetname', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'town', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'UPRN', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'USRN', type => 'xsd:string', attr => {}),
    ], # end parameters
  }, # end PropertySearch
'CreateCustomer' => {
    endpoint => $ENDPOINT,
    soapaction => '',
    namespace => 'http://DefaultNamespace',
    parameters => [
      SOAP::Data->new(name => 'authenticationtoken', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'title', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'forename', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'surname', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'uprn', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'HouseNo', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'HouseName', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'StreetName', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'Locale', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'Town', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'County', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'Northing', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'Easting', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'postcode', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'email', type => 'xsd:string', attr => {}),
      SOAP::Data->new(name => 'telephone', type => 'xsd:string', attr => {}),
    ], # end parameters
  }, # end CreateCustomer
); # end my %methods

use SOAP::Lite;
use Exporter;
use Carp ();

use vars qw(@ISA $AUTOLOAD @EXPORT_OK %EXPORT_TAGS);
@ISA = qw(Exporter SOAP::Lite);
@EXPORT_OK = (keys %methods);
%EXPORT_TAGS = ('all' => [@EXPORT_OK]);

sub _call {
    my ($self, $method) = (shift, shift);
    my $name = UNIVERSAL::isa($method => 'SOAP::Data') ? $method->name : $method;
    my %method = %{$methods{$name}};
    $self->proxy($method{endpoint} || Carp::croak "No server address (proxy) specified")
        unless $self->proxy;
    my @templates = @{$method{parameters}};
    my @parameters = ();
    foreach my $param (@_) {
        if (@templates) {
            my $template = shift @templates;
            my ($prefix,$typename) = SOAP::Utils::splitqname($template->type);
            my $method = 'as_'.$typename;
            # TODO - if can('as_'.$typename) {...}
            my $result = $self->serializer->$method($param, $template->name, $template->type, $template->attr);
            push(@parameters, $template->value($result->[2]));
        }
        else {
            push(@parameters, $param);
        }
    }
    $self->endpoint($method{endpoint})
       ->ns($method{namespace})
       ->on_action(sub{qq!"$method{soapaction}"!});
  $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/soap/","wsdlsoap");
  $self->serializer->register_ns("http://DefaultNamespace","intf");
  $self->serializer->register_ns("http://xml.apache.org/xml-soap","apachesoap");
  $self->serializer->register_ns("http://rpc.xml.coldfusion","tns1");
  $self->serializer->register_ns("http://DefaultNamespace","impl");
  $self->serializer->register_ns("http://schemas.xmlsoap.org/wsdl/","wsdl");
  $self->serializer->register_ns("http://schemas.xmlsoap.org/soap/encoding/","soapenc");
  $self->serializer->register_ns("http://www.w3.org/2001/XMLSchema","xsd");
    my $som = $self->SUPER::call($method => @parameters);
    if ($self->want_som) {
        return $som;
    }
    UNIVERSAL::isa($som => 'SOAP::SOM') ? wantarray ? $som->paramsall : $som->result : $som;
}

sub BEGIN {
    no strict 'refs';
    for my $method (qw(want_som)) {
        my $field = '_' . $method;
        *$method = sub {
            my $self = shift->new;
            @_ ? ($self->{$field} = shift, return $self) : return $self->{$field};
        }
    }
}
no strict 'refs';
for my $method (@EXPORT_OK) {
    my %method = %{$methods{$method}};
    *$method = sub {
        my $self = UNIVERSAL::isa($_[0] => __PACKAGE__)
            ? ref $_[0]
                ? shift # OBJECT
                # CLASS, either get self or create new and assign to self
                : (shift->self || __PACKAGE__->self(__PACKAGE__->new))
            # function call, either get self or create new and assign to self
            : (__PACKAGE__->self || __PACKAGE__->self(__PACKAGE__->new));
        $self->_call($method, @_);
    }
}

sub AUTOLOAD {
    my $method = substr($AUTOLOAD, rindex($AUTOLOAD, '::') + 2);
    return if $method eq 'DESTROY' || $method eq 'want_som';
    die "Unrecognized method '$method'. List of available method(s): @EXPORT_OK\n";
}

1;