API/Event.pm

filter: Statementstmt 11.1% 11 / 99 Branchbran 0.0% 0 / 44 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 12.0% 3 / 25 Podpod 100% 22 / 22 totaltotal 18.9% 36 / 190 CC 23 SCAR 20.3
CC
23
Cov
8%
get_notes
20.0
get_repeatSkipDates
12.0
get_tags
12.0
CRAP 7.6
« API.pm ↑ Summary API/Todo.pm »
1 package WebService::30Boxes::API::Event;
2  
3 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use Carp qw/croak/;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 our $VERSION = '1.05';
8  
9 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
10 0 my ($class, $result, $success, $error_code, $error_message) = @_;
11 0 ▶ croak "The response from 30Boxes was not a success" unless $result->{'success'};
Branch: 1 branch
BranchTrueFalseTotal
unless $result->{"success"} 0 0 0
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 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 0 ▶sub get_eventIds {
Subroutine get_eventIds: not called CC=1 SCAR=6.9
Pod documented
31 0 my ($self) = @_;
32 0 return @{$self->{'eventIds'}};
33 }
34  
35 #return a reference to an array of event ids
36 0 ▶sub get_ref_eventIds {
Subroutine get_ref_eventIds: not called CC=1 SCAR=6.9
Pod documented
37 0 my ($self) = @_;
38 0 return $self->{'eventIds'};
39 }
40  
41 #get the end date of the list - yyyy-mm-dd
42 0 ▶sub get_listEnd {
Subroutine get_listEnd: not called CC=1 SCAR=6.9
Pod documented
43 0 my ($self) = @_;
44 0 return $self->{'listEnd'};
45 }
46
47 #get the start date of the list - yyyy-mm-dd
48 0 ▶sub get_listStart {
Subroutine get_listStart: not called CC=1 SCAR=6.9
Pod documented
49 0 my ($self) = @_;
50 0 return $self->{'listStart'};
51 }
52
53 #get the current user id
54 0 ▶sub get_userId {
Subroutine get_userId: not called CC=1 SCAR=6.9
Pod documented
55 0 my ($self) = @_;
56 0 return $self->{'userId'};
57 }
58  
59 #advance the eventIndex
60 0 ▶sub nextEventId {
Subroutine nextEventId: not called CC=2 SCAR=17.9
Pod documented
61 0 my ($self) = @_;
62 0 ▶ return 0 if $self->{'eventIndex'} == scalar(@{$self->{'eventIds'}}) - 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"eventIndex"} == scalar(@{$self->{"eventIds"};}) - 1 0 0 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 0 ▶sub get_repeatEndDate {
Subroutine get_repeatEndDate: not called CC=2 SCAR=17.9
Pod documented
70 0 my ($self, $eventId) = @_;
71 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
72 0 return $self->{'event'}->{$eventId}->{'repeatEndDate'};
73 }
74  
75 #return a list of the days that are skipped
76 0 ▶sub get_repeatSkipDates {
Subroutine get_repeatSkipDates: not called CC=3 SCAR=24.8
Pod documented
77 0 my ($self, $eventId) = @_;
78 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
79 0 my $temp = $self->{'event'}->{$eventId}->{'repeatSkipDates'};
80 0 ▶ if (ref $temp){return qw//;}
Branch: 1 branch
BranchTrueFalseTotal
if (ref $temp) 0 0 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 0 ▶sub get_repeatType {
Subroutine get_repeatType: not called CC=2 SCAR=17.9
Pod documented
88 0 my ($self, $eventId) = @_;
89 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub get_repeatInterval {
Subroutine get_repeatInterval: not called CC=2 SCAR=17.9
Pod documented
96 0 my ($self, $eventId) = @_;
97 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub get_reminder {
Subroutine get_reminder: not called CC=2 SCAR=17.9
Pod documented
106 0 my ($self, $eventId) = @_;
107 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
108 0 return $self->{'event'}->{$eventId}->{'reminder'};
109 }
110  
111 #returns a list of tags
112 0 ▶sub get_tags {
Subroutine get_tags: not called CC=3 SCAR=24.8
Pod documented
113 0 my ($self, $eventId) = @_;
114 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
115 0 my $temp = $self->{'event'}->{$eventId}->{'tags'};
116 0 ▶ return "" if ref($temp);
Branch: 1 branch
BranchTrueFalseTotal
if ref $temp 0 0 0
117 0 $temp =~ s/\s+/ /;
118 0 return split(/ /, $temp);
119 }
120  
121 #gets the end date
122 0 ▶sub get_endDate {
Subroutine get_endDate: not called CC=2 SCAR=17.9
Pod documented
123 0 my ($self, $eventId) = @_;
124 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub get_endTime {
Subroutine get_endTime: not called CC=2 SCAR=17.9
Pod documented
131 0 my ($self, $eventId) = @_;
132 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub isAllDayEvent {
Subroutine isAllDayEvent: not called CC=2 SCAR=17.9
Pod documented
139 0 my ($self, $eventId) = @_;
140 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
141 0 return $self->{'event'}->{$eventId}->{'allDayEvent'};
142 }
143  
144 #gets the title for the event
145 0 ▶sub get_title {
Subroutine get_title: not called CC=2 SCAR=17.9
Pod documented
146 0 my ($self, $eventId) = @_;
147 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub get_notes {
Subroutine get_notes: not called CC=4 SCAR=30.0
Pod documented
154 0 my ($self, $eventId) = @_;
155 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
156 0 my $temp = $self->{'event'}->{$eventId}->{'notes'};
157 0 ▶ if (not ref $temp){
Branch: 1 branch
BranchTrueFalseTotal
unless (ref $temp) 0 0 0
158 0 return $temp;
159 }
160  
161 0 ▶ return "" if not defined $temp->{'content'};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $temp->{"content"} 0 0 0
162  
163 0 my $temp2 = $temp->{'content'};
164  
165 0 return join("\n", @{$temp2});
166 }
167  
168  
169 0 ▶sub get_privacy {
Subroutine get_privacy: not called CC=2 SCAR=17.9
Pod documented
170 0 my ($self, $eventId) = @_;
171 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
172 0 return $self->{'event'}->{$eventId}->{'privacy'};
173 }
174  
175 #gets the start date - yyyy-mm-dd
176 0 ▶sub get_startDate {
Subroutine get_startDate: not called CC=2 SCAR=17.9
Pod documented
177 0 my ($self, $eventId) = @_;
178 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 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 0 ▶sub get_startTime {
Subroutine get_startTime: not called CC=2 SCAR=17.9
Pod documented
185 0 my ($self, $eventId) = @_;
186 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
187 0 my $temp = $self->{'event'}->{$eventId}->{'start'};
188 0 return (split(/ /, $temp))[1];
189 }
190  
191 0 ▶sub get_externalUID {
Subroutine get_externalUID: not called CC=3 SCAR=24.8
Pod documented
192 0 my ($self, $eventId) = @_;
193 0 ▶ $eventId = $self->{'eventIds'}->[$self->{'eventIndex'}] if 0 == $#_;
Branch: 1 branch
BranchTrueFalseTotal
if 0 == $#_ 0 0 0
194 0 my $temp = $self->{'event'}->{$eventId}->{'externalUID'};
195 0 ▶ return "" if ref($temp);#it's a hash if empty
Branch: 1 branch
BranchTrueFalseTotal
if ref $temp 0 0 0
196 0 $temp =~ s/\s+/ /;
197 0 return split(/ /, $temp);
198 }
199  
200 1 1;
201 __END__
« API.pm ↑ Summary API/Todo.pm »