diff options
Diffstat (limited to 'perllib/Open311/Endpoint/Service')
-rw-r--r-- | perllib/Open311/Endpoint/Service/Attribute.pm | 82 | ||||
-rw-r--r-- | perllib/Open311/Endpoint/Service/Request.pm | 107 |
2 files changed, 189 insertions, 0 deletions
diff --git a/perllib/Open311/Endpoint/Service/Attribute.pm b/perllib/Open311/Endpoint/Service/Attribute.pm new file mode 100644 index 000000000..f88919408 --- /dev/null +++ b/perllib/Open311/Endpoint/Service/Attribute.pm @@ -0,0 +1,82 @@ +package Open311::Endpoint::Service::Attribute; +use Moo; +use MooX::HandlesVia; +use Types::Standard ':all'; +use namespace::clean; + +# from http://wiki.open311.org/GeoReport_v2#GET_Service_Definition + +# A unique identifier for the attribute +has code => ( + is => 'ro', + isa => Str, +); + +# true denotes that user input is needed +# false means the attribute is only used to present information to the user within the description field +# +# NB: unsure what false means for the rest of the options here, e.g. should remainder of fields by Maybe[] ? +has variable => ( + is => 'ro', + isa => Bool, + default => sub { 1 }, +); + +# Denotes the type of field used for user input. +has datatype => ( + is => 'ro', + isa => Enum[qw/ string number datetime text singlevaluelist multivaluelist /], +); + +has required => ( + is => 'ro', + isa => Bool, +); + +# A description of the datatype which helps the user provide their input +has datatype_description => ( + is => 'ro', + isa => Str, +); + +# A description of the attribute field with instructions for the user to find +# and identify the requested information +has description => ( + is => 'ro', + isa => Str, +); + +# NB: we don't model the "Order" field here, as that's really for the Service +# object to return + +# only relevant for singlevaluelist or multivaluelist +has values => ( + is => 'ro', + isa => HashRef, + default => sub { {} }, + handles_via => 'Hash', + handles => { + get_value => 'get', + get_values => 'keys', + has_values => 'count', + values_kv => 'kv', + } +); + +sub schema_definition { + my $self = shift; + + my @values = map +{ type => '//str', value => $_ }, $self->get_values; + my %schema_types = ( + string => '//str', + number => '//num', + datetime => '//str', # TODO + text => '//str', + singlevaluelist => { type => '//any', of => [@values] }, + multivaluelist => { type => '//arr', of => [@values] }, + ); + + return $schema_types{ $self->datatype }; +} + +1; diff --git a/perllib/Open311/Endpoint/Service/Request.pm b/perllib/Open311/Endpoint/Service/Request.pm new file mode 100644 index 000000000..b56cee393 --- /dev/null +++ b/perllib/Open311/Endpoint/Service/Request.pm @@ -0,0 +1,107 @@ +package Open311::Endpoint::Service::Request; +use Moo; +use Types::Standard ':all'; +use namespace::clean; + +has service => ( + is => 'ro', + isa => InstanceOf['Open311::Endpoint::Service'], + handles => [ + qw/ service_code service_name / + ], +); + +has service_request_id => ( + is => 'ro', + isa => Maybe[Str], + predicate => 1, +); + +has token => ( + is => 'ro', + isa => Maybe[Str], + predicate => 1, +); + +has service_notice => ( + is => 'ro', + isa => Maybe[Str], + predicate => 1, +); + +has account_id => ( + is => 'ro', + isa => Maybe[Str], + predicate => 1, +); + +has status => ( + is => 'rw', + isa => Enum[qw/ open closed /], + default => sub { 'open' }, +); + +has description => ( + is => 'ro', + isa => Maybe[Str], +); + +has agency_responsible => ( + is => 'ro', + isa => Maybe[Str], +); + +has requested_datetime => ( + is => 'ro', + isa => Maybe[ InstanceOf['DateTime'] ], +); + +has updated_datetime => ( + is => 'ro', + isa => Maybe[ InstanceOf['DateTime'] ], +); + +has expected_datetime => ( + is => 'ro', + isa => Maybe[ InstanceOf['DateTime'] ], +); + +has address => ( + is => 'ro', + isa => Str, + default => sub { '' }, +); + +has address_id => ( + is => 'ro', + isa => Str, + default => sub { '' }, +); + +has zipcode => ( + is => 'ro', + isa => Str, + default => sub { '' }, +); + +has latlong => ( + is => 'ro', + isa => Tuple[ Num, Num ], + default => sub { [0,0] }, + handles_via => 'Array', + handles => { + #lat => [ get => 0 ], + #long => [ get => 1 ], + } +); + +sub lat { shift->latlong->[0] } +sub long { shift->latlong->[1] } + +has media_url => ( + is => 'ro', + isa => Str, + default => sub { '' }, +); + +1; |