Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Get calendar name #11

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 35 additions & 0 deletions lib/API/Google/GCal.pm
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@ use parent 'API::Google';
$gapi->get_calendars($user, ['id', 'summary']); # return only specified fields

$gapi->get_calendar_id_by_name($user, 'Contacts');
$gapi->get_calendar_name($user, $calendar_id);

my $event_data = {};
$event_data->{summary} = 'Exibition';
Expand All @@ -34,6 +35,7 @@ use parent 'API::Google';
$event_data->{start}{timeZone} = $event_data->{end}{timeZone} = $timeZone; # not obligatory

$gapi->add_event($user, $calendar_id, $event_data);
$gapi->delete_event($user, $calendar_id, $event_id);

my $freebusy_data = {
user => $user,
Expand Down Expand Up @@ -84,6 +86,21 @@ sub get_calendars {
}
}

=head2 get_calendar__name

$gapi->get_calendar_name($user, $id)

Get calendar name by its id. Name = "summary" parameter

=cut

sub get_calendar_name {
my ($self, $user, $id) = @_;
my $all = $self->get_calendars($user, ['id', 'summary']); # arr ref
my @n = grep { $_->{'id'} eq $id } @$all;
return $n[0]->{summary};
}

=head2 get_calendar_id_by_name

$gapi->get_calendar_id_by_name($user, $name)
Expand All @@ -101,6 +118,24 @@ sub get_calendar_id_by_name {
}


=head2 add_event

$gapi->add_event($user, $calendar_id, $event_data)

# https://developers.google.com/google-apps/calendar/v3/reference/events/delete

=cut

sub delete_event {
my ($self, $user, $calendar_id, $event_id) = @_;
$self->api_query({
method => 'delete',
route => $self->{api_base}.'/calendars/'.$calendar_id.'/events/'.$event_id,
user => $user
});
}


=head2 add_event

$gapi->add_event($user, $calendar_id, $event_data)
Expand Down