AI-PredictionClient

 view release on metacpan or  search on metacpan

lib/AI/PredictionClient/Roles/PredictionRole.pm  view on Meta::CPAN


has status => (is => 'rwp',);

has status_code => (is => 'rwp',);

has status_message => (is => 'rwp',);

sub serialize_request {
  my $self = shift;

  printf("Debug - Request: %s \n", Dumper(\$self->request_ds))
    if $self->debug_verbose;

  my $json = JSON->new;

  my $request_json = $json->encode($self->request_ds);
  printf("Debug - JSON Request: %s \n", Dumper(\$request_json))
    if $self->debug_verbose;

  return $request_json;
}

sub deserialize_reply {
  my $self              = shift;
  my $serialized_return = shift;

  printf("Debug - JSON Response: %s \n", Dumper(\$serialized_return))
    if $self->debug_verbose;

  my $json = JSON->new;

  my $returned_ds = $json->decode(
    ref($serialized_return) ? $$serialized_return : $serialized_return);
  $self->_set_status($returned_ds->{'Status'});
  $self->_set_status_code($returned_ds->{'StatusCode'});

  my $message_base = $returned_ds->{'StatusMessage'};
  my $message
    = ref($message_base)
    ? decode_base64($message_base->{'base64'}->[0])
    : $message_base;
  $self->_set_status_message($message ? $message : "");

  $self->_set_reply_ds($returned_ds->{'Result'});

  printf("Debug - Response: %s \n", Dumper(\$returned_ds))
    if $self->debug_verbose;

  if ($self->status =~ /^OK/i) {
    return 1;
  }
  return 0;
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

AI::PredictionClient::Roles::PredictionRole - Implements the Prediction service interface

=head1 VERSION

version 0.05

=head1 AUTHOR

Tom Stall <stall@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2017 by Tom Stall.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut



( run in 2.851 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )