Google-RestApi
view release on metacpan or search on metacpan
lib/Google/RestApi/CalendarApi3/CalendarList.pm view on Meta::CPAN
use parent 'Google::RestApi::SubResource';
sub new {
my $class = shift;
state $check = signature(
bless => !!0,
named => [
calendar_api => HasApi,
id => Str, { optional => 1 },
],
);
return bless $check->(@_), $class;
}
sub _uri_base { 'users/me/calendarList' }
sub _parent_accessor { 'calendar_api' }
sub get {
my $self = shift;
state $check = signature(
bless => !!0,
named => [
fields => Str, { optional => 1 },
],
);
my $p = $check->(@_);
$self->require_id('get');
my %params;
$params{fields} = $p->{fields} if defined $p->{fields};
return $self->api(params => \%params);
}
sub insert {
my $self = shift;
state $check = signature(
bless => !!0,
named => [
id => Str,
_extra_ => slurpy HashRef,
],
);
my $p = named_extra($check->(@_));
my %content = (
id => delete $p->{id},
);
DEBUG(sprintf("Inserting calendar '%s' into calendar list", $content{id}));
my $result = $self->calendar_api()->api(
uri => 'users/me/calendarList',
method => 'post',
content => \%content,
);
return ref($self)->new(calendar_api => $self->calendar_api(), id => $result->{id});
}
sub update {
my $self = shift;
state $check = signature(
bless => !!0,
named => [
summary_override => Str, { optional => 1 },
color_id => Str, { optional => 1 },
hidden => Bool, { optional => 1 },
selected => Bool, { optional => 1 },
_extra_ => slurpy HashRef,
],
);
my $p = named_extra($check->(@_));
$self->require_id('update');
my %content;
$content{summaryOverride} = delete $p->{summary_override} if defined $p->{summary_override};
$content{colorId} = delete $p->{color_id} if defined $p->{color_id};
$content{hidden} = delete $p->{hidden} ? JSON::MaybeXS::true() : JSON::MaybeXS::false() if defined $p->{hidden};
$content{selected} = delete $p->{selected} ? JSON::MaybeXS::true() : JSON::MaybeXS::false() if defined $p->{selected};
DEBUG(sprintf("Updating calendar list entry '%s'", $self->{id}));
return $self->api(
method => 'patch',
content => \%content,
);
}
sub delete {
my $self = shift;
$self->require_id('delete');
DEBUG(sprintf("Deleting calendar list entry '%s'", $self->{id}));
return $self->api(method => 'delete');
}
sub calendar_list_id { shift->{id}; }
sub calendar_api { shift->{calendar_api}; }
1;
__END__
=head1 NAME
Google::RestApi::CalendarApi3::CalendarList - CalendarList object for Google Calendar.
=head1 SYNOPSIS
# Get a calendar list entry
my $cl = $cal_api->calendar_list(id => 'primary');
my $info = $cl->get();
# Insert a calendar into the user's list
my $cl = $cal_api->calendar_list()->insert(id => 'calendar_id@group.calendar.google.com');
# Update display settings
$cl->update(summary_override => 'My Custom Name', color_id => '7');
( run in 0.702 second using v1.01-cache-2.11-cpan-364913b4093 )