diff options
author | Hakim Cassimally <hakim@mysociety.org> | 2014-07-15 14:15:46 +0000 |
---|---|---|
committer | Hakim Cassimally <hakim@mysociety.org> | 2014-10-16 16:56:27 +0000 |
commit | 56eab366fc60fe83024abb6819c146bc9bd47adc (patch) | |
tree | a12aa26e01855c297ebcaf6232319f3e41b1e669 /perllib/Open311/Endpoint.pm | |
parent | f47e9d48a2d26e92723ae96d3d65a1ba005f426f (diff) |
Open311 Warwick (Exor) Integration
::Integration::Warwick subclasses ::Integration::Exor
refactor request_class and new_request
Exor service
Warwickshire updates retrieval, with datetimes
stubbing out of Oracle constants, for local testing
We also edit FMS's core PopulateServiceList routine to hide system
fields from FMS:
Bromley/Warwickshire send metadata in their services/FOO.xml
advising that you can pass, e.g. attributes[easting].
FMS by default shows all of these to the user to fill in, however
we don't *want* the user to supply these, rather they are added
by the cobrand.
Bromley had an exception for this (keyed by $body->areas->id).
We write this more generally for Warwickshire too, keying instead
by $body->name (as this is far less likely to be overridden for
installs using global or custom Mapit's)
Diffstat (limited to 'perllib/Open311/Endpoint.pm')
-rw-r--r-- | perllib/Open311/Endpoint.pm | 39 |
1 files changed, 34 insertions, 5 deletions
diff --git a/perllib/Open311/Endpoint.pm b/perllib/Open311/Endpoint.pm index 0abb52aab..7916d090f 100644 --- a/perllib/Open311/Endpoint.pm +++ b/perllib/Open311/Endpoint.pm @@ -118,8 +118,6 @@ sub check_jurisdiction_id { return first { $jurisdiction_id eq $_ } $self->get_jurisdiction_ids; } - - =head2 Configurable arguments * default_service_notice - default for <service_notice> if not @@ -141,6 +139,7 @@ sub check_jurisdiction_id { service_request_id => ... # etc. } + * request_class - class to instantiate for requests via new_request =cut @@ -182,6 +181,17 @@ has jurisdiction_ids => ( } ); +has request_class => ( + is => 'ro', + isa => Str, + default => 'Open311::Endpoint::Service::Request', +); + +sub new_request { + my ($self, %args) = @_; + return $self->request_class->new( %args ); +} + =head2 Other accessors You may additionally wish to replace the following objects. @@ -241,6 +251,11 @@ has w3_dt => ( default => sub { DateTime::Format::W3CDTF->new }, ); +has time_zone => ( + is => 'ro', + default => 'Europe/London', +); + sub maybe_inflate_datetime { my ($self, $dt) = @_; return unless $dt; @@ -403,7 +418,7 @@ sub POST_Service_Request_input_schema { my $service = $self->service($service_code) or return; # we can't fetch service, so signal error TODO - my %attributes; + my %attributes = ( required => {}, optional => {} ); for my $attribute ($service->get_attributes) { my $section = $attribute->required ? 'required' : 'optional'; my $key = sprintf 'attribute[%s]', $attribute->code; @@ -440,7 +455,7 @@ sub POST_Service_Request_input_schema { phone => '//str', description => '//str', media_url => '//str', - %{ $attributes{optional} }, + %{ $attributes{optional} || {}}, (map %$_, @address_options), $self->get_jurisdiction_id_optional_clause, }, @@ -492,6 +507,13 @@ sub POST_Service_Request { my $service_code = $args->{service_code}; my $service = $self->service($service_code); + for my $k (keys %$args) { + if ($k =~ /^attribute\[(\w+)\]$/) { + my $value = delete $args->{$k}; + $args->{attributes}{$1} = $value; + } + } + my @service_requests = $self->post_service_request( $service, $args ); return { @@ -639,7 +661,12 @@ sub format_service_requests { ), ( map { - $_ => $self->w3_dt->format_datetime( $request->$_ ), + if (my $dt = $request->$_) { + $_ => $self->w3_dt->format_datetime( $dt ) + } + else { + () + } } qw/ requested_datetime @@ -729,8 +756,10 @@ sub call_api { $schema->assert_valid( $data ); }; if ($@) { + use Data::Dumper; return Open311::Endpoint::Result->error( 500, "Error in output for $api_name", + Dumper($data), split /\n/, $@, # map $_->struct, @{ $@->failures }, ); |