diff options
author | Hakim Cassimally <hakim@mysociety.org> | 2014-03-13 16:56:02 +0000 |
---|---|---|
committer | Hakim Cassimally <hakim@mysociety.org> | 2014-10-16 16:56:26 +0000 |
commit | d1fee928f02dbc30d3a38b746155ce5b12be4a1b (patch) | |
tree | 5e8bdccbd69863e69098b9aa900c1e71745f8eb5 /t/open311/endpoint/Endpoint1.pm | |
parent | 592f4c0ba0f822b55bb242cb12768ce771599d09 (diff) |
Open311 Endpoint
Subsystems include
* ::Spark encoding conventions for xml/json
* ::Schema using Rx to validate form of inputs and outputs,
including validation for, e.g., dates and CSV as part of Open311
Handles following paths:
* Open311 attributes for Service Definition
http://wiki.open311.org/GeoReport_v2#GET_Service_Definition
* POST service request
* GET Service Requests
* GET Service Request
Objects:
* ::Service
* ::Service::Request
Diffstat (limited to 't/open311/endpoint/Endpoint1.pm')
-rw-r--r-- | t/open311/endpoint/Endpoint1.pm | 114 |
1 files changed, 114 insertions, 0 deletions
diff --git a/t/open311/endpoint/Endpoint1.pm b/t/open311/endpoint/Endpoint1.pm new file mode 100644 index 000000000..ccd16c238 --- /dev/null +++ b/t/open311/endpoint/Endpoint1.pm @@ -0,0 +1,114 @@ +package t::open311::endpoint::Endpoint1; +use Web::Simple; +extends 'Open311::Endpoint'; +use Types::Standard ':all'; +use MooX::HandlesVia; + +use Open311::Endpoint::Service; +use t::open311::endpoint::ServiceType1; +use Open311::Endpoint::Service::Attribute; + +sub services { + return ( + t::open311::endpoint::ServiceType1->new( + service_code => 'POT', + service_name => 'Pothole Repairs', + description => 'Pothole Repairs Service', + attributes => [ + Open311::Endpoint::Service::Attribute->new( + code => 'depth', + required => 1, + datatype => 'number', + datatype_description => 'an integer', + description => 'depth of pothole, in centimetres', + ), + Open311::Endpoint::Service::Attribute->new( + code => 'shape', + required => 0, + datatype => 'singlevaluelist', + datatype_description => 'square | circle | triangle', + description => 'shape of the pothole', + values => { + square => 'Square', + circle => 'Circle', + triangle => 'Triangle', + }, + ), + ], + type => 'realtime', + keywords => [qw/ deep hole wow/], + group => 'highways', + ), + t::open311::endpoint::ServiceType1->new( + service_code => 'BIN', + service_name => 'Bin Enforcement', + description => 'Bin Enforcement Service', + attributes => [], + type => 'realtime', + keywords => [qw/ bin /], + group => 'sanitation', + ) + ); +} + +# FOR TESTING, we'll just maintain requests in a *global* array... +# obviously a real Service driver will use a DB or API call! +{ + our @SERVICE_REQUESTS; + has _requests => ( + is => 'ro', + isa => ArrayRef[ InstanceOf[ 'Open311::Endpoint::Service::Request' ] ], + default => sub { \@SERVICE_REQUESTS }, + handles_via => 'Array', + handles => { + next_request_id => 'count', + _add_request => 'push', + get_request => 'get', + get_requests => 'elements', + filter_requests => 'grep', + } + ); +} + +sub post_service_request { + my ($self, $service, $args) = @_; + + my $request = Open311::Endpoint::Service::Request->new( + + # NB: possible race condition between next_request_id and _add_request + # (this is fine for synchronous test-cases) + + service => $service, + service_request_id => $self->next_request_id, + status => 'open', + description => $args->{description}, + agency_responsible => '', + requested_datetime => DateTime->now(), + updated_datetime => DateTime->now(), + address => $args->{address_string} // '', + address_id => $args->{address_id} // '', + media_url => $args->{media_url} // '', + zipcode => $args->{zipcode} // '', + # NB: other info is passed in that would be stored by an Open311 + # endpoint, see Open311::Endpoint::Service::Request for full list, + # but we don't need to handle all of those in this test + ); + $self->_add_request( $request ); + + return ( $request ); +} + +sub get_service_requests { + my ($self, $args) = @_; + + my $service_code = $args->{service_code} or return $self->get_requests; + # we use ~~ as the service_code arg will be an arrayref like ['POT'] + return $self->filter_requests( sub { shift->service->service_code ~~ $service_code }); +} + +sub get_service_request { + my ($self, $service_request_id, $args) = @_; + return $self->get_request( $service_request_id ); +} + +1; |