use v5.10.0;
use warnings;
package JMAP::Tester::Role::Result;
# ABSTRACT: the kind of thing that you get back for a request
$JMAP::Tester::Role::Result::VERSION = '0.011';
use Moo::Role;

use JMAP::Tester::Abort ();

use namespace::clean;

#pod =head1 OVERVIEW
#pod
#pod This is the role consumed by the class of any object returned by JMAP::Tester's
#pod C<request> method.  Its only guarantee, for now, is an C<is_success> method,
#pod and an C<http_response> method.
#pod
#pod =cut

requires 'is_success';

has http_response => (
  is => 'ro',
);

sub assert_successful {
  my ($self) = @_;

  return $self if $self->is_success;

  my $str = $self->can('has_ident') && $self->has_ident
          ? $self->ident
          : "JMAP failure";

  die JMAP::Tester::Abort->new($str);
}

1;

__END__

=pod

=encoding UTF-8

=head1 NAME

JMAP::Tester::Role::Result - the kind of thing that you get back for a request

=head1 VERSION

version 0.011

=head1 OVERVIEW

This is the role consumed by the class of any object returned by JMAP::Tester's
C<request> method.  Its only guarantee, for now, is an C<is_success> method,
and an C<http_response> method.

=head1 AUTHOR

Ricardo SIGNES <rjbs@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2016 by FastMail, Ltd.

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
