line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Dynect::REST::Session; |
2
|
|
|
|
|
|
|
# $Id: Session.pm 149 2010-09-26 01:33:15Z james $ |
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
5
|
1
|
|
|
1
|
|
4
|
use overload '""' => \&_as_string; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
6
|
1
|
|
|
1
|
|
49
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
971
|
|
7
|
|
|
|
|
|
|
our $VERSION = do { my @r = (q$Revision: 149 $ =~ /\d+/g); sprintf "%d."."%03d" x $#r, @r }; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Net::Dynect::REST::Session - A session object for the Dynect REST API |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 SYNOPSIS |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
use Net::Dynect::REST; |
16
|
|
|
|
|
|
|
my $dynect = Net::Dynect::REST->new(user_name => $user, customer_name => $customer, password => $password); |
17
|
|
|
|
|
|
|
print $dynect->session . "\n"; |
18
|
|
|
|
|
|
|
print $dynect->session->api_version . "\n"; |
19
|
|
|
|
|
|
|
$dynect->session->delete; |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=head1 METHODS |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head2 Creating |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=over 4 |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=item Net::Dynect::REST::Session->new(); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Creates a new (empty) session object. You may supply the following arguments to populate this: |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over 4 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item response => $response |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=item token => $token |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item user_name => $user |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=item api_version => $version |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item uri => $uri |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=back |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=back |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=cut |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub new { |
50
|
0
|
|
|
0
|
1
|
|
my $proto = shift; |
51
|
0
|
|
0
|
|
|
|
my $class = ref($proto) || $proto; |
52
|
0
|
|
|
|
|
|
my $self = {}; |
53
|
0
|
|
|
|
|
|
bless $self, $class; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my %args = @_; |
56
|
0
|
0
|
0
|
|
|
|
if ( defined $args{response} |
57
|
|
|
|
|
|
|
&& ref( $args{response} ) eq "Net::Dynect::REST::Response" ) |
58
|
|
|
|
|
|
|
{ |
59
|
0
|
|
|
|
|
|
$self->token( $args{response}->data->token ); |
60
|
0
|
|
|
|
|
|
$self->api_version( $args{response}->data->version ); |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
0
|
0
|
|
|
|
|
$self->token( $args{token} ) if defined $args{token}; |
64
|
0
|
0
|
|
|
|
|
$self->api_version( $args{api_version} ) if defined $args{api_version}; |
65
|
0
|
0
|
|
|
|
|
$self->user_name( $args{user_name} ) if defined $args{user_name}; |
66
|
0
|
0
|
|
|
|
|
$self->uri( $args{uri} ) if defined $args{uri}; |
67
|
|
|
|
|
|
|
|
68
|
0
|
|
|
|
|
|
return $self; |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
=head2 Attributes |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=over 4 |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item user_name |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
This gets (or sets) the user_name that was associated with the session established - as a convenience in case you have multiple sessions open and want to track them. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=cut |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub user_name { |
82
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
83
|
0
|
0
|
|
|
|
|
if (@_) { |
84
|
0
|
|
|
|
|
|
my $new = shift; |
85
|
0
|
0
|
|
|
|
|
if ( $new !~ /^\S+$/ ) { |
86
|
0
|
|
|
|
|
|
carp "user_name should not have spaces"; |
87
|
0
|
|
|
|
|
|
return; |
88
|
|
|
|
|
|
|
} |
89
|
0
|
|
|
|
|
|
$self->{user_name} = $new; |
90
|
|
|
|
|
|
|
} |
91
|
0
|
|
|
|
|
|
return $self->{user_name}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub uri { |
95
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
96
|
0
|
0
|
|
|
|
|
if (@_) { |
97
|
0
|
|
|
|
|
|
$self->{uri} = shift; |
98
|
|
|
|
|
|
|
} |
99
|
0
|
|
|
|
|
|
return $self->{uri}; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=item token |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This is the value of the B header that must be sent with each authenticated request. |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=cut |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
sub token { |
109
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
110
|
0
|
0
|
|
|
|
|
if (@_) { |
111
|
0
|
|
|
|
|
|
my $new = shift; |
112
|
0
|
|
|
|
|
|
$self->{token} = $new; |
113
|
0
|
|
|
|
|
|
$self->_token_create_time( time() ); |
114
|
|
|
|
|
|
|
} |
115
|
0
|
|
|
|
|
|
$self->_last_token_read_time( time() ); |
116
|
0
|
|
|
|
|
|
return $self->{token}; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=item api_version |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
This is the version of the API that satisfied the call to establish the session. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub api_version { |
126
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
127
|
0
|
0
|
|
|
|
|
if (@_) { |
128
|
0
|
|
|
|
|
|
$self->{api_version} = shift; |
129
|
|
|
|
|
|
|
} |
130
|
0
|
|
|
|
|
|
return $self->{api_version}; |
131
|
|
|
|
|
|
|
} |
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
sub _as_string { |
134
|
0
|
|
|
0
|
|
|
my $self = shift; |
135
|
0
|
0
|
|
|
|
|
return unless defined $self->token; |
136
|
|
|
|
|
|
|
return |
137
|
0
|
|
0
|
|
|
|
sprintf "Auth-Token %s (api version %s) for user %s at uri %s at %s GMT", |
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
138
|
|
|
|
|
|
|
$self->token, $self->api_version || "unknown", |
139
|
|
|
|
|
|
|
$self->user_name || "unknown", $self->uri || "unknown", |
140
|
|
|
|
|
|
|
scalar( gmtime( $self->_token_create_time ) ) || "unknown"; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _token_create_time { |
144
|
0
|
|
|
0
|
|
|
my $self = shift; |
145
|
0
|
0
|
|
|
|
|
if (@_) { |
146
|
0
|
|
|
|
|
|
my $new = shift; |
147
|
0
|
0
|
|
|
|
|
if ( $new !~ /^\d+$/ ) { |
148
|
0
|
|
|
|
|
|
carp "Time should only be digits"; |
149
|
0
|
|
|
|
|
|
return; |
150
|
|
|
|
|
|
|
} |
151
|
0
|
|
|
|
|
|
$self->{token_create_time} = $new; |
152
|
|
|
|
|
|
|
} |
153
|
0
|
|
|
|
|
|
return $self->{token_create_time}; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub _last_token_read_time { |
157
|
0
|
|
|
0
|
|
|
my $self = shift; |
158
|
0
|
0
|
|
|
|
|
if (@_) { |
159
|
0
|
|
|
|
|
|
my $new = shift; |
160
|
0
|
0
|
|
|
|
|
if ( $new !~ /^\d+$/ ) { |
161
|
0
|
|
|
|
|
|
carp "Time should only be digits"; |
162
|
0
|
|
|
|
|
|
return; |
163
|
|
|
|
|
|
|
} |
164
|
0
|
|
|
|
|
|
$self->{token_read_time} = $new; |
165
|
|
|
|
|
|
|
} |
166
|
0
|
|
|
|
|
|
return $self->{token_read_time}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
=back |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
=head2 Destruction |
172
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=over 4 |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
=item delete |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
This will remove the session object |
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
=cut |
180
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub delete { |
182
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
183
|
0
|
|
|
|
|
|
$self = undef; |
184
|
|
|
|
|
|
|
} |
185
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=back |
187
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
=head1 SEE ALSO |
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
L, L. |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
=head1 AUTHOR |
193
|
|
|
|
|
|
|
|
194
|
|
|
|
|
|
|
James bromberger, james@rcpt.to |
195
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
197
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright (C) 2010 by James Bromberger |
199
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
201
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.10.1 or, |
202
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
203
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |