Google-RestApi

 view release on metacpan or  search on metacpan

lib/Google/RestApi/DriveApi3/Comment.pm  view on Meta::CPAN

      file => HasApi,
      id   => Str, { optional => 1 },
    ],
  );
  return bless $check->(@_), $class;
}

sub _uri_base { 'comments' }
sub _parent_accessor { 'file' }

sub create {
  my $self = shift;
  state $check = signature(
    bless => !!0,
    named => [
      content        => Str,
      anchor         => Str, { optional => 1 },
      quoted_content => Str, { optional => 1 },
      _extra_        => slurpy HashRef,
    ],
  );
  my $p = named_extra($check->(@_));

  my %content = (
    content => delete $p->{content},
  );
  $content{anchor} = delete $p->{anchor} if defined $p->{anchor};
  $content{quotedFileContent}{value} = delete $p->{quoted_content} if defined $p->{quoted_content};

  DEBUG(sprintf("Creating comment on file '%s'", $self->file()->file_id()));
  my $result = $self->file()->api(
    uri     => 'comments',
    method  => 'post',
    params  => { fields => 'id, content, author, createdTime' },
    content => \%content,
  );
  return ref($self)->new(file => $self->file(), id => $result->{id});
}

sub get {
  my $self = shift;
  state $check = signature(
    bless => !!0,
    named => [
      fields          => Str, { default => 'id,content,author,createdTime,modifiedTime' },
      include_deleted => Bool, { default => 0 },
    ],
  );
  my $p = $check->(@_);

  $self->require_id('get');

  my %params = (
    fields => $p->{fields},
  );
  $params{includeDeleted} = $p->{include_deleted} ? 'true' : 'false';

  return $self->api(params => \%params);
}

sub update {
  my $self = shift;
  state $check = signature(
    bless => !!0,
    named => [
      content => Str,
      _extra_ => slurpy HashRef,
    ],
  );
  my $p = named_extra($check->(@_));

  $self->require_id('update');

  my %content = (
    content => delete $p->{content},
  );

  DEBUG(sprintf("Updating comment '%s' on file '%s'", $self->{id}, $self->file()->file_id()));
  return $self->api(
    method  => 'patch',
    content => \%content,
  );
}

sub delete {
  my $self = shift;

  $self->require_id('delete');

  DEBUG(sprintf("Deleting comment '%s' from file '%s'", $self->{id}, $self->file()->file_id()));
  return $self->api(method => 'delete');
}

sub reply {
  my $self = shift;
  state $check = signature(
    bless => !!0,
    named => [
      id => Str, { optional => 1 },
    ],
  );
  my $p = $check->(@_);

  $self->require_id('reply');

  return Reply->new(comment => $self, %$p);
}

sub replies {
  my $self = shift;
  state $check = signature(
    bless => !!0,
    named => [
      fields          => Str, { optional => 1 },
      include_deleted => Bool, { default => 0 },
      max_pages       => Int, { default => 0 },
      page_callback   => CodeRef, { optional => 1 },
      params          => HashRef, { default => {} },
    ],
  );
  my $p = $check->(@_);



( run in 1.248 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )