line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Freshservice; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
858
|
use v5.010; |
|
1
|
|
|
|
|
4
|
|
4
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
28
|
|
5
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
38
|
|
6
|
1
|
|
|
1
|
|
491
|
use WebService::Freshservice::API; |
|
1
|
|
|
|
|
21
|
|
|
1
|
|
|
|
|
40
|
|
7
|
1
|
|
|
1
|
|
10
|
use Carp qw( croak ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
62
|
|
8
|
1
|
|
|
1
|
|
7
|
use Method::Signatures 20140224; |
|
1
|
|
|
|
|
20
|
|
|
1
|
|
|
|
|
8
|
|
9
|
1
|
|
|
1
|
|
409
|
use Moo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
7
|
|
10
|
1
|
|
|
1
|
|
367
|
use namespace::clean; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
# ABSTRACT: Abstraction layer to the Freshservice API |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our $VERSION = '0.004'; # VERSION: Generated by DZP::OurPkg:Version |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has 'apikey' => ( is => 'ro', required => 1 ); |
19
|
|
|
|
|
|
|
has 'apiurl' => ( is => 'ro', default => sub { "https://imdexlimited.freshservice.com" } ); |
20
|
|
|
|
|
|
|
has '_api' => ( is => 'rw', lazy => 1, builder => 1 ); |
21
|
|
|
|
|
|
|
|
22
|
1
|
0
|
|
1
|
|
1369
|
method _build__api { |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
return WebService::Freshservice::API->new( |
24
|
|
|
|
|
|
|
apikey => $self->apikey, |
25
|
|
|
|
|
|
|
apiurl => $self->apiurl, |
26
|
|
|
|
|
|
|
); |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# Agent/User searching is pretty much identical. |
30
|
|
|
|
|
|
|
# TODO: Pagination is possible using 'page=#' |
31
|
1
|
|
|
1
|
|
17691
|
method _search( |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
32
|
0
|
|
|
|
|
|
:$email?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
:$mobile?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
:$phone?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
35
|
0
|
0
|
|
|
|
|
:$state = 'all', |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
36
|
0
|
0
|
|
|
|
|
:$page?, |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
) { |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Who ya gunna call? (find the calling method) |
40
|
0
|
|
|
|
|
|
my $caller = substr((caller 1)[3],26); |
41
|
0
|
0
|
|
|
|
|
my $package = $caller eq "requesters" ? "User" : "Agent"; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
# Build query |
44
|
0
|
|
|
|
|
|
my $query = "?"; |
45
|
0
|
0
|
|
|
|
|
if ($email) { |
46
|
0
|
|
|
|
|
|
$query .= "query=email is $email"; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
0
|
|
|
|
|
if ($mobile) { |
49
|
0
|
0
|
|
|
|
|
$query .= "&" unless $query eq "?"; |
50
|
0
|
|
|
|
|
|
$query .= "query=mobile is $mobile"; |
51
|
|
|
|
|
|
|
} |
52
|
0
|
0
|
|
|
|
|
if ($phone) { |
53
|
0
|
0
|
|
|
|
|
$query .= "&" unless $query eq "?"; |
54
|
0
|
|
|
|
|
|
$query .= "query=phone is $phone"; |
55
|
|
|
|
|
|
|
} |
56
|
0
|
0
|
|
|
|
|
my $endpoint = $caller eq 'requesters' ? "itil/requesters.json" : "agents.json"; |
57
|
0
|
0
|
|
|
|
|
$endpoint .= $query unless $query eq "?"; |
58
|
0
|
0
|
|
|
|
|
$endpoint .= $query eq "?" ? "?state=$state" : "&state=$state"; |
59
|
0
|
0
|
|
|
|
|
$endpoint .= "&page=$page" if $page; |
60
|
0
|
|
|
|
|
|
my $users = $self->_api->get_api($endpoint); |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# Build objects |
63
|
0
|
|
|
|
|
|
my @objects; |
64
|
0
|
0
|
|
|
|
|
if ( 0+@{$users} > 0 ) { |
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
foreach my $user ( @{$users} ) { |
|
0
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
push( |
67
|
|
|
|
|
|
|
@objects, |
68
|
|
|
|
|
|
|
"WebService::Freshservice::$package"->new( |
69
|
|
|
|
|
|
|
api => $self->_api, |
70
|
|
|
|
|
|
|
id => $user->{lc($package)}{id}, |
71
|
0
|
|
|
|
|
|
_raw => $user, |
72
|
|
|
|
|
|
|
), |
73
|
|
|
|
|
|
|
); |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
|
77
|
0
|
|
|
|
|
|
return \@objects; |
78
|
|
|
|
|
|
|
} |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# Like the seach method, populating an agent is identical. |
81
|
1
|
0
|
|
1
|
|
6470
|
method _user( :$id?, :$email? ) { |
|
0
|
0
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# Who ya gunna call? (find the calling method) |
83
|
0
|
|
|
|
|
|
my $caller = substr((caller 1)[3],26); |
84
|
0
|
0
|
|
|
|
|
my $package = $caller eq "requester" ? "User" : "Agent"; |
85
|
0
|
|
|
|
|
|
my $search = $caller."s"; # Our search methods are plurals of singular methods. |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my $user; |
88
|
0
|
0
|
|
|
|
|
if ($email) { |
89
|
0
|
|
|
|
|
|
my @users = @{$self->$search( email => $email )}; |
|
0
|
|
|
|
|
|
|
90
|
0
|
0
|
|
|
|
|
croak "No $caller found with $email" unless 0+@users > 0; |
91
|
0
|
|
|
|
|
|
$user = $users[0]; |
92
|
|
|
|
|
|
|
} else { |
93
|
0
|
0
|
|
|
|
|
croak "'id' or 'email' required." unless $id; |
94
|
0
|
|
|
|
|
|
$user = "WebService::Freshservice::$package"->new( api => $self->_api, id => $id ); |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return $user; |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
1
|
|
|
1
|
|
932
|
use WebService::Freshservice::User; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
37
|
|
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
|
102
|
1
|
|
|
1
|
|
3049
|
method requester(...) { |
|
0
|
|
|
0
|
|
|
|
103
|
0
|
|
|
|
|
|
return $self->_user(@_); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
1
|
|
|
1
|
|
2567
|
method requesters(...) { |
|
0
|
|
|
0
|
|
|
|
108
|
0
|
|
|
|
|
|
return $self->_search(@_); |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
1
|
|
|
1
|
|
26075
|
method create_requester( |
|
0
|
|
|
0
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
113
|
0
|
|
|
|
|
|
:$name, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
:$email?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
115
|
0
|
|
|
|
|
|
:$address?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
:$description?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
117
|
0
|
|
|
|
|
|
:$job_title?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
|
:$phone?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
119
|
0
|
|
|
|
|
|
:$mobile?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
:$language?, |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
121
|
0
|
0
|
|
|
|
|
:$timezone?, |
|
0
|
0
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
) { |
123
|
0
|
|
|
|
|
|
my $mandatory; |
124
|
0
|
0
|
|
|
|
|
$mandatory = $email if $email; |
125
|
0
|
0
|
|
|
|
|
$mandatory = $phone if $phone; |
126
|
0
|
0
|
|
|
|
|
$mandatory = $mobile if $mobile; |
127
|
0
|
0
|
|
|
|
|
croak("One of email, phone or mobile must be definded to create a user") unless $mandatory; |
128
|
0
|
0
|
|
|
|
|
croak("Name must be definded to create a user") unless $name; |
129
|
|
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
my $content; |
131
|
0
|
|
|
|
|
|
$content->{user}{name} = $name; |
132
|
0
|
0
|
|
|
|
|
$content->{user}{email} = $email if $email; |
133
|
0
|
0
|
|
|
|
|
$content->{user}{address} = $address if $address; |
134
|
0
|
0
|
|
|
|
|
$content->{user}{description} = $description if $description; |
135
|
0
|
0
|
|
|
|
|
$content->{user}{job_title} = $job_title if $job_title; |
136
|
0
|
0
|
|
|
|
|
$content->{user}{phone} = $phone if $phone; |
137
|
0
|
0
|
|
|
|
|
$content->{user}{mobile} = $mobile if $mobile; |
138
|
0
|
0
|
|
|
|
|
$content->{user}{language} = $language if $language; |
139
|
0
|
0
|
|
|
|
|
$content->{user}{timezone} = $timezone if $timezone; |
140
|
|
|
|
|
|
|
|
141
|
0
|
|
|
|
|
|
my $data = $self->_api->post_api("itil/requesters.json",$content); |
142
|
0
|
|
|
|
|
|
return WebService::Freshservice::User->new( api => $self->_api, _raw => $data, id => $data->{user}{id} ); |
143
|
|
|
|
|
|
|
} |
144
|
|
|
|
|
|
|
|
145
|
1
|
|
|
1
|
|
1116
|
use WebService::Freshservice::Agent; |
|
1
|
|
|
|
|
5
|
|
|
1
|
|
|
|
|
36
|
|
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
|
148
|
1
|
|
|
1
|
|
3352
|
method agent(...) { |
|
0
|
|
|
0
|
|
|
|
149
|
0
|
|
|
|
|
|
return $self->_user(@_); |
150
|
|
|
|
|
|
|
} |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
1
|
|
2701
|
method agents(...) { |
|
0
|
|
|
0
|
|
|
|
154
|
0
|
|
|
|
|
|
return $self->_search(@_); |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
1; |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
__END__ |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=pod |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=encoding UTF-8 |
164
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
=head1 NAME |
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
WebService::Freshservice - Abstraction layer to the Freshservice API |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=head1 VERSION |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
version 0.004 |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head1 SYNOPSIS |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
use WebService::Freshservice; |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
my $freshservice = WebService::Freshservice->new( apikey => '1234567890abcdef' ); |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=head1 DESCRIPTION |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
WebService::Freshservice is an abstraction layer to the Freshservice API. |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
=head1 METHODS |
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head2 requester |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
$freshservice->requester( id => '123456789' ); |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
Returns a WebService::Freshservice::User on success, croaks on failure. |
190
|
|
|
|
|
|
|
Optionally if you can use the attribute 'email' and it will search |
191
|
|
|
|
|
|
|
returning the first result, croaking if not found. |
192
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
=head2 requesters |
194
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
$freshservice->requesters( email => 'test@example.com'); |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
Perform a search on the provided attribute and optional state. If |
198
|
|
|
|
|
|
|
no query is set it will return the first 50 results. |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Use one the following attributes, 'email', 'mobile' or 'phone'. |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
Optionally state can be set to one of 'verified', 'unverified', |
203
|
|
|
|
|
|
|
'all' or 'deleted'. Defaults to 'all'. |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Returns an array of 'WebService::Freshservice::User' objects or |
206
|
|
|
|
|
|
|
empty array if no results are found. |
207
|
|
|
|
|
|
|
|
208
|
|
|
|
|
|
|
=head2 create_requester |
209
|
|
|
|
|
|
|
|
210
|
|
|
|
|
|
|
$freshservice->create_requester( name => 'Test', email => 'Test@email.com' ); |
211
|
|
|
|
|
|
|
|
212
|
|
|
|
|
|
|
Returns a WebService::Freshservice::User object on success, croaks on |
213
|
|
|
|
|
|
|
failure. |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
'name' is a mandatory attribute and requires at least one of 'email', |
216
|
|
|
|
|
|
|
'phone' or 'mobile'. |
217
|
|
|
|
|
|
|
|
218
|
|
|
|
|
|
|
Also accepts the following optional attributes: address, description, |
219
|
|
|
|
|
|
|
external_id, job_title, language, timezone. |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=head2 agent |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
$freshservice->agent( id => '123456789' ); |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
Returns a WebService::Freshservice::Agent on success, croaks on failure. |
226
|
|
|
|
|
|
|
Optionally if you can use the attribute 'email' and it will search |
227
|
|
|
|
|
|
|
returning the first result, croaking if not found. |
228
|
|
|
|
|
|
|
|
229
|
|
|
|
|
|
|
=head2 agent |
230
|
|
|
|
|
|
|
|
231
|
|
|
|
|
|
|
$freshservice->agent( email => 'test@example.com'); |
232
|
|
|
|
|
|
|
|
233
|
|
|
|
|
|
|
Perform a search on the provided attribute and optional state. If |
234
|
|
|
|
|
|
|
no query is set it will return the first 50 results. |
235
|
|
|
|
|
|
|
|
236
|
|
|
|
|
|
|
Use one the following attributes, 'email', 'mobile' or 'phone'. |
237
|
|
|
|
|
|
|
|
238
|
|
|
|
|
|
|
Optionally state can be set to one of 'verified', 'unverified', |
239
|
|
|
|
|
|
|
'all' or 'deleted'. Defaults to 'all'. |
240
|
|
|
|
|
|
|
|
241
|
|
|
|
|
|
|
Returns an array of 'WebService::Freshservice::Agent' objects or |
242
|
|
|
|
|
|
|
empty array if no results are found. |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 AUTHOR |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Leon Wright <techman@cpan.org> |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
This software is copyright (c) 2016 by Leon Wright. |
251
|
|
|
|
|
|
|
|
252
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
253
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
=cut |