line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WebService::Eulerian::Analytics; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# $Id: Analytics.pm,v 1.4 2008-09-21 23:30:08 cvscore Exp $ |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
our $VERSION = 0.8; |
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1735
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
49
|
|
8
|
1
|
|
|
1
|
|
15934
|
use SOAP::Lite; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=pod |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
WebService::Eulerian::Analytics - Eulerian Analytics API |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 DESCRIPTION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
This module handles the calls and responses sent to the different services |
19
|
|
|
|
|
|
|
provided by the WebService::Eulerian::Analytics modules. It's the parent class |
20
|
|
|
|
|
|
|
for all other modules and should not be used directly. |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 METHODS |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
=head2 new : constructor called by other modules |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head3 input |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=over 4 |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=item * hash reference with the following options |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
o apikey : API key allowing you to request the API, mandatory (provided by Eulerian Technologies), must be sent with each requests in the SOAP Enveloppe. |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
o host : the host on which you have to send your API requests, mandatory (provided by Eulerian Analytics) |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
o timeout : in seconds the timeout after which a request is aborted, defaults to 60. |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
o debug : set to 1 if you want to check the raw SOAP requets, defaults to 0. |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
o version : indicate the version of the API you are requesting, defaults to the newest version. |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=back |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head3 output |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
=over 4 |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * a Perl object corresponding to the service you instantiated |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
=back |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
=cut |
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub new { |
55
|
|
|
|
|
|
|
my $proto = shift; |
56
|
|
|
|
|
|
|
my $class = ref($proto) || $proto; |
57
|
|
|
|
|
|
|
my %h_p = @_; |
58
|
|
|
|
|
|
|
if ( $h_p{debug} ) { |
59
|
|
|
|
|
|
|
SOAP::Lite->import(+trace => 'debug'); |
60
|
|
|
|
|
|
|
} |
61
|
|
|
|
|
|
|
return bless({ |
62
|
|
|
|
|
|
|
_APIKEY => $h_p{apikey}, |
63
|
|
|
|
|
|
|
_HOST => $h_p{host} || 'api.ea.eulerian.com', |
64
|
|
|
|
|
|
|
_VERSION => $h_p{version} || 'v1', |
65
|
|
|
|
|
|
|
_SERVICE => $h_p{service}, |
66
|
|
|
|
|
|
|
_DEBUG => $h_p{debug} || 0, |
67
|
|
|
|
|
|
|
_TIMEOUT => $h_p{timeout} || 60 * 15, # 15 minutes |
68
|
|
|
|
|
|
|
_FAULT => 0, |
69
|
|
|
|
|
|
|
_FAULTDETAILS=> {}, |
70
|
|
|
|
|
|
|
}, $class); |
71
|
|
|
|
|
|
|
} |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
sub _endpoint { |
74
|
|
|
|
|
|
|
my ($self, $host, $version) = @_; |
75
|
|
|
|
|
|
|
return 'http://'.join('/', $host, 'ea', $version); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub _faultclear { |
79
|
|
|
|
|
|
|
my $self = shift; |
80
|
|
|
|
|
|
|
$self->{_FAULT} = 0; |
81
|
|
|
|
|
|
|
$self->{_FAULTDETAILS} = {}; |
82
|
|
|
|
|
|
|
return 1; |
83
|
|
|
|
|
|
|
} |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _faultadd { |
86
|
|
|
|
|
|
|
my ($self, $r_h) = @_; |
87
|
|
|
|
|
|
|
$self->{_FAULT} = 1; |
88
|
|
|
|
|
|
|
$self->{_FAULTDETAILS} = $r_h; |
89
|
|
|
|
|
|
|
return 1; |
90
|
|
|
|
|
|
|
} |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=pod |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head2 fault : indicates if the last call generated a fault on the server |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head3 input |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=over 4 |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=item * none |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=back |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
=head3 output |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=over 4 |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=item * 1 if a fault was generated, 0 otherwise |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=back |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
sub fault { return shift()->{_FAULT}; } |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=pod |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 faultdetails : returns a hash reference containing the details on the last generated fault |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head3 input |
121
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
=over 4 |
123
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
=item * none |
125
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=back |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=head3 output |
129
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=over 4 |
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
=item * hash reference |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
o code : fault code |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
o string : fault string |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=back |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
=cut |
141
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
sub faultdetails { return shift()->{_FAULTDETAILS}; } |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
=pod |
145
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
=head2 faultcode : returns the faultcode of the last generated fault |
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head3 input |
149
|
|
|
|
|
|
|
|
150
|
|
|
|
|
|
|
=over 4 |
151
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=item * none |
153
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=back |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
=head3 output |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
=over 4 |
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=item * code describing the fault |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
=back |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=cut |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
sub faultcode { return shift()->_faultdetails_k('code'); } |
167
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=pod |
169
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 faultstring : returns the faultstring of the last generated fault |
171
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
=head3 input |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=over 4 |
175
|
|
|
|
|
|
|
|
176
|
|
|
|
|
|
|
=item * none |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=back |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
=head3 output |
181
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
=over 4 |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
=item * text describing the fault |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=cut |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
sub faultstring { return shift()->_faultdetails_k('string'); } |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
sub _faultdetails_k { |
193
|
|
|
|
|
|
|
my ($self, $k) = @_; |
194
|
|
|
|
|
|
|
return $self->{_FAULTDETAILS}->{ $k }; |
195
|
|
|
|
|
|
|
} |
196
|
|
|
|
|
|
|
|
197
|
|
|
|
|
|
|
=pod |
198
|
|
|
|
|
|
|
|
199
|
|
|
|
|
|
|
=head2 call : generic SOAP call method (private) |
200
|
|
|
|
|
|
|
|
201
|
|
|
|
|
|
|
This method should not be called directly, use the main classes. |
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=head3 input |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
=over 4 |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=item * name of the method to be called |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=item * array of parameters sent to the method call |
210
|
|
|
|
|
|
|
|
211
|
|
|
|
|
|
|
=back |
212
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
=head3 output |
214
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
=over 4 |
216
|
|
|
|
|
|
|
|
217
|
|
|
|
|
|
|
=item * if no error : returns the value of the Response part of the SOAP call |
218
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
=item * if error : returns undef and set the fault flag to 1 and faultdetails with fault information |
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=back |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
=head3 sample |
224
|
|
|
|
|
|
|
|
225
|
|
|
|
|
|
|
my $rh_return = $service->call('MyMethodName', 'param1', { hash => 'param2' }, [ 'param3' ]); |
226
|
|
|
|
|
|
|
# |
227
|
|
|
|
|
|
|
# test if the server generated a fault |
228
|
|
|
|
|
|
|
if ( $service->fault ) { |
229
|
|
|
|
|
|
|
# die on fault and display the faultstring |
230
|
|
|
|
|
|
|
die $service->faultstring(); |
231
|
|
|
|
|
|
|
} |
232
|
|
|
|
|
|
|
# |
233
|
|
|
|
|
|
|
# no fault : process the returned structure |
234
|
|
|
|
|
|
|
use Data::Dumper; |
235
|
|
|
|
|
|
|
print Dumper($rh_return); |
236
|
|
|
|
|
|
|
|
237
|
|
|
|
|
|
|
=cut |
238
|
|
|
|
|
|
|
|
239
|
|
|
|
|
|
|
sub call { |
240
|
|
|
|
|
|
|
my ($self, $method, @a_p) = @_; |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
# reset fault methods |
243
|
|
|
|
|
|
|
$self->_faultclear(); |
244
|
|
|
|
|
|
|
|
245
|
|
|
|
|
|
|
# build soap header with auth |
246
|
|
|
|
|
|
|
my @a_header = ( |
247
|
|
|
|
|
|
|
SOAP::Header->name("apikey")->value($self->{_APIKEY} )->type('') |
248
|
|
|
|
|
|
|
); |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
# send SOAP request to API host |
251
|
|
|
|
|
|
|
my $soap = SOAP::Lite->proxy( |
252
|
|
|
|
|
|
|
$self->_endpoint($self->{_HOST}, $self->{_VERSION}).'/'.$self->{_SERVICE}, |
253
|
|
|
|
|
|
|
timeout => $self->{_TIMEOUT} |
254
|
|
|
|
|
|
|
); |
255
|
|
|
|
|
|
|
my $result = $soap->call( |
256
|
|
|
|
|
|
|
SOAP::Data->name($method)->uri($self->{_SERVICE}) => @a_header, @a_p); |
257
|
|
|
|
|
|
|
|
258
|
|
|
|
|
|
|
# check for a fault and return hash detailling fault if any |
259
|
|
|
|
|
|
|
if ( $result->fault ) { |
260
|
|
|
|
|
|
|
$self->_faultadd({ |
261
|
|
|
|
|
|
|
code => $result->faultcode || 0, |
262
|
|
|
|
|
|
|
string => $result->faultstring || '', |
263
|
|
|
|
|
|
|
}); |
264
|
|
|
|
|
|
|
return undef; |
265
|
|
|
|
|
|
|
} |
266
|
|
|
|
|
|
|
# no fault : return the generated structure |
267
|
|
|
|
|
|
|
return $result->valueof('//'.$method.'Response/'.$method.'Return'); |
268
|
|
|
|
|
|
|
} |
269
|
|
|
|
|
|
|
|
270
|
|
|
|
|
|
|
=pod |
271
|
|
|
|
|
|
|
|
272
|
|
|
|
|
|
|
=head1 SEE ALSO |
273
|
|
|
|
|
|
|
|
274
|
|
|
|
|
|
|
L |
275
|
|
|
|
|
|
|
|
276
|
|
|
|
|
|
|
=head1 AUTHOR |
277
|
|
|
|
|
|
|
|
278
|
|
|
|
|
|
|
Mathieu Jondet |
279
|
|
|
|
|
|
|
|
280
|
|
|
|
|
|
|
=head1 COPYRIGHT |
281
|
|
|
|
|
|
|
|
282
|
|
|
|
|
|
|
Copyright (c) 2008 Eulerian Technologies Ltd L |
283
|
|
|
|
|
|
|
|
284
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify |
285
|
|
|
|
|
|
|
it under the terms of the GNU General Public License as published by |
286
|
|
|
|
|
|
|
the Free Software Foundation; either version 2 of the License, or |
287
|
|
|
|
|
|
|
(at your option) any later version. |
288
|
|
|
|
|
|
|
|
289
|
|
|
|
|
|
|
This program is distributed in the hope that it will be useful, |
290
|
|
|
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of |
291
|
|
|
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
292
|
|
|
|
|
|
|
GNU General Public License for more details. |
293
|
|
|
|
|
|
|
|
294
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License |
295
|
|
|
|
|
|
|
along with this program; if not, write to the Free Software |
296
|
|
|
|
|
|
|
Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
297
|
|
|
|
|
|
|
|
298
|
|
|
|
|
|
|
=cut |
299
|
|
|
|
|
|
|
|
300
|
|
|
|
|
|
|
1; |
301
|
|
|
|
|
|
|
__END__ |