File Coverage

blib/lib/WebService/30Boxes/API/Event.pm
Criterion Covered Total %
statement 9 97 9.2
branch 0 44 0.0
condition n/a
subroutine 3 25 12.0
pod 22 22 100.0
total 34 188 18.0


line stmt bran cond sub pod time code
1             package WebService::30Boxes::API::Event;
2              
3 1     1   6 use strict;
  1         2  
  1         45  
4 1     1   6 use warnings;
  1         2  
  1         50  
5 1     1   15 use Carp qw/croak/;
  1         2  
  1         3531  
6              
7             our $VERSION = '1.05';
8              
9             sub new {
10 0     0 1   my ($class, $result, $success, $error_code, $error_message) = @_;
11 0 0         croak "The response from 30Boxes was not a success" unless $result->{'success'};
12              
13             #%{$result->{'_xml'}->{'eventList'} is a hash with listEnd, listStart, userId, event as keys
14             #%{$result->{'_xml'}->{'eventList'}->{'event'}} is a hash with event ids as keys
15 0           my $self = { listEnd => $result->{'_xml'}->{'eventList'}->{'listEnd'},
16             listStart => $result->{'_xml'}->{'eventList'}->{'listStart'},
17             userId => $result->{'_xml'}->{'eventList'}->{'userId'},
18             event => $result->{'_xml'}->{'eventList'}->{'event'},
19 0           eventIds => [sort keys %{$result->{'_xml'}->{'eventList'}->{'event'}}],
20             eventIndex => -1,
21             success => $success,
22             error_code => $error_code,
23             error_message => $error_message,
24             };
25 0           bless $self, $class;
26 0           return $self;
27             }
28              
29             #return an array of event ids
30             sub get_eventIds {
31 0     0 1   my ($self) = @_;
32 0           return @{$self->{'eventIds'}};
  0            
33             }
34              
35             #return a reference to an array of event ids
36             sub get_ref_eventIds {
37 0     0 1   my ($self) = @_;
38 0           return $self->{'eventIds'};
39             }
40              
41             #get the end date of the list - yyyy-mm-dd
42             sub get_listEnd {
43 0     0 1   my ($self) = @_;
44 0           return $self->{'listEnd'};
45             }
46            
47             #get the start date of the list - yyyy-mm-dd
48             sub get_listStart {
49 0     0 1   my ($self) = @_;
50 0           return $self->{'listStart'};
51             }
52            
53             #get the current user id
54             sub get_userId {
55 0     0 1   my ($self) = @_;
56 0           return $self->{'userId'};
57             }
58              
59             #advance the eventIndex
60             sub nextEventId {
61 0     0 1   my ($self) = @_;
62 0 0         return 0 if $self->{'eventIndex'} == scalar(@{$self->{'eventIds'}}) - 1;
  0            
63 0           return $self->{'eventIds'}->[$self->{'eventIndex'}++];
64             }
65            
66             #get the date when the recurring event stops repeating - yyyy-mm-dd
67             #0000-00-00 if none
68             #if an event spans over multiple days but it is not recurring, the final date will be returned
69             sub get_repeatEndDate {
70 0     0 1   my ($self, $eventId) = @_;
71 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
72 0           return $self->{'event'}->{$eventId}->{'repeatEndDate'};
73             }
74              
75             #return a list of the days that are skipped
76             sub get_repeatSkipDates {
77 0     0 1   my ($self, $eventId) = @_;
78 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
79 0           my $temp = $self->{'event'}->{$eventId}->{'repeatSkipDates'};
80 0 0         if (ref $temp){return qw//;}
  0            
81 0           $temp =~ s/\s+/ /;
82 0           return split(/ /, $temp);
83             }
84              
85             #return the repeat type for the event
86             #returns 'no' if none
87             sub get_repeatType {
88 0     0 1   my ($self, $eventId) = @_;
89 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
90 0           return $self->{'event'}->{$eventId}->{'repeatType'};
91             }
92              
93             #return the repeat interval for the event
94             #this together with get_repeatType tell you all you need to know about how the event repeats
95             sub get_repeatInterval {
96 0     0 1   my ($self, $eventId) = @_;
97 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
98 0           $self->{'event'}->{$eventId}->{'repeatICal'} =~ /INTERVAL=(\d+)/;
99 0           my $interval = $1;
100 0           return $interval;
101             }
102              
103             #returns the number of minutes before the event when the reminder will be sent
104             #-1 if no reminder
105             sub get_reminder {
106 0     0 1   my ($self, $eventId) = @_;
107 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
108 0           return $self->{'event'}->{$eventId}->{'reminder'};
109             }
110              
111             #returns a list of tags
112             sub get_tags {
113 0     0 1   my ($self, $eventId) = @_;
114 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
115 0           my $temp = $self->{'event'}->{$eventId}->{'tags'};
116 0 0         return "" if ref($temp);
117 0           $temp =~ s/\s+/ /;
118 0           return split(/ /, $temp);
119             }
120              
121             #gets the end date
122             sub get_endDate {
123 0     0 1   my ($self, $eventId) = @_;
124 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
125 0           my $temp = $self->{'event'}->{$eventId}->{'end'};
126 0           return (split(/ /, $temp))[0];
127             }
128              
129             #gets the end time - hh:mm:ss
130             sub get_endTime {
131 0     0 1   my ($self, $eventId) = @_;
132 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
133 0           my $temp = $self->{'event'}->{$eventId}->{'end'};
134 0           return (split(/ /, $temp))[1];
135             }
136              
137             #returns 1 if it is an all day event, 0 otherwise
138             sub isAllDayEvent {
139 0     0 1   my ($self, $eventId) = @_;
140 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
141 0           return $self->{'event'}->{$eventId}->{'allDayEvent'};
142             }
143              
144             #gets the title for the event
145             sub get_title {
146 0     0 1   my ($self, $eventId) = @_;
147 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
148 0           return $self->{'event'}->{$eventId}->{'summary'};
149             }
150              
151             #gets the notes for the event in the form of a string
152             #if the notes span over multiple lines, the order in which they are returned is undefined
153             sub get_notes {
154 0     0 1   my ($self, $eventId) = @_;
155 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
156 0           my $temp = $self->{'event'}->{$eventId}->{'notes'};
157 0 0         if (not ref $temp){
158 0           return $temp;
159             }
160              
161 0 0         return "" if not defined $temp->{'content'};
162              
163 0           my $temp2 = $temp->{'content'};
164              
165 0           return join("\n", @{$temp2});
  0            
166             }
167              
168              
169             sub get_privacy {
170 0     0 1   my ($self, $eventId) = @_;
171 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
172 0           return $self->{'event'}->{$eventId}->{'privacy'};
173             }
174              
175             #gets the start date - yyyy-mm-dd
176             sub get_startDate {
177 0     0 1   my ($self, $eventId) = @_;
178 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
179 0           my $temp = $self->{'event'}->{$eventId}->{'start'};
180 0           return (split(/ /, $temp))[0];
181             }
182              
183             #gets the start time - hh:mm:ss
184             sub get_startTime {
185 0     0 1   my ($self, $eventId) = @_;
186 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
187 0           my $temp = $self->{'event'}->{$eventId}->{'start'};
188 0           return (split(/ /, $temp))[1];
189             }
190              
191             sub get_externalUID {
192 0     0 1   my ($self, $eventId) = @_;
193 0 0         $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
194 0           my $temp = $self->{'event'}->{$eventId}->{'externalUID'};
195 0 0         return "" if ref($temp);#it's a hash if empty
196 0           $temp =~ s/\s+/ /;
197 0           return split(/ /, $temp);
198             }
199              
200             1;
201             __END__