line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# Representation of a single Duo phone for the Admin API. |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# This class wraps the Duo representation of a single Duo phone, as returned |
4
|
|
|
|
|
|
|
# by (for example) the Admin /phones REST endpoint. |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# SPDX-License-Identifier: MIT |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
package Net::Duo::Admin::Phone 1.02; |
9
|
|
|
|
|
|
|
|
10
|
6
|
|
|
6
|
|
2459
|
use 5.014; |
|
6
|
|
|
|
|
20
|
|
11
|
6
|
|
|
6
|
|
45
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
138
|
|
12
|
6
|
|
|
6
|
|
27
|
use warnings; |
|
6
|
|
|
|
|
70
|
|
|
6
|
|
|
|
|
212
|
|
13
|
|
|
|
|
|
|
|
14
|
6
|
|
|
6
|
|
34
|
use parent qw(Net::Duo::Object); |
|
6
|
|
|
|
|
19
|
|
|
6
|
|
|
|
|
29
|
|
15
|
|
|
|
|
|
|
|
16
|
6
|
|
|
6
|
|
2697
|
use Net::Duo::Admin::User; |
|
6
|
|
|
|
|
21
|
|
|
6
|
|
|
|
|
3004
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
# Data specification for converting JSON into our object representation. See |
19
|
|
|
|
|
|
|
# the Net::Duo::Object documentation for syntax information. |
20
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) |
21
|
|
|
|
|
|
|
sub _fields { |
22
|
|
|
|
|
|
|
return { |
23
|
18
|
|
|
18
|
|
235
|
activated => 'simple', |
24
|
|
|
|
|
|
|
capabilities => 'array', |
25
|
|
|
|
|
|
|
extension => ['simple', 'set'], |
26
|
|
|
|
|
|
|
name => ['simple', 'set'], |
27
|
|
|
|
|
|
|
number => ['simple', 'set'], |
28
|
|
|
|
|
|
|
phone_id => 'simple', |
29
|
|
|
|
|
|
|
platform => ['simple', 'set'], |
30
|
|
|
|
|
|
|
postdelay => ['simple', 'set'], |
31
|
|
|
|
|
|
|
predelay => ['simple', 'set'], |
32
|
|
|
|
|
|
|
sms_passcodes_sent => 'simple', |
33
|
|
|
|
|
|
|
type => ['simple', 'set'], |
34
|
|
|
|
|
|
|
users => 'Net::Duo::Admin::User', |
35
|
|
|
|
|
|
|
}; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
## use critic |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
# Install our accessors. |
40
|
|
|
|
|
|
|
Net::Duo::Admin::Phone->install_accessors; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Override the new method to support creating a phone from an ID instead |
43
|
|
|
|
|
|
|
# of decoded JSON data. |
44
|
|
|
|
|
|
|
# |
45
|
|
|
|
|
|
|
# $class - Class of object to create |
46
|
|
|
|
|
|
|
# $duo - Net::Duo object to use to create the object |
47
|
|
|
|
|
|
|
# $id_or_data - Phone ID or reference to data |
48
|
|
|
|
|
|
|
# |
49
|
|
|
|
|
|
|
# Returns: Newly-created object |
50
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem creating the object |
51
|
|
|
|
|
|
|
sub new { |
52
|
4
|
|
|
4
|
1
|
333
|
my ($class, $duo, $id_or_data) = @_; |
53
|
4
|
100
|
|
|
|
15
|
if (!ref($id_or_data)) { |
54
|
1
|
|
|
|
|
5
|
$id_or_data = $duo->call_json('GET', "/admin/v1/phones/$id_or_data"); |
55
|
|
|
|
|
|
|
} |
56
|
4
|
|
|
|
|
26
|
return $class->SUPER::new($duo, $id_or_data); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# Override the create method to add the appropriate URI. |
60
|
|
|
|
|
|
|
# |
61
|
|
|
|
|
|
|
# $class - Class of object to create |
62
|
|
|
|
|
|
|
# $duo - Net::Duo object to use to create the object |
63
|
|
|
|
|
|
|
# $data_ref - Data for new object as a reference to a hash |
64
|
|
|
|
|
|
|
# |
65
|
|
|
|
|
|
|
# Returns: Newly-created object |
66
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem creating the object |
67
|
|
|
|
|
|
|
sub create { |
68
|
1
|
|
|
1
|
1
|
384
|
my ($class, $duo, $data_ref) = @_; |
69
|
1
|
|
|
|
|
11
|
return $class->SUPER::create($duo, '/admin/v1/phones', $data_ref); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# Request an activation URL and barcode for a phone. |
73
|
|
|
|
|
|
|
# |
74
|
|
|
|
|
|
|
# $self - The Net::Duo::Admin::Phone object to request activation URLs for |
75
|
|
|
|
|
|
|
# $args_ref - Arguments for the request (optional) |
76
|
|
|
|
|
|
|
# install - Set to a true value to request an install URL as well |
77
|
|
|
|
|
|
|
# valid_secs - Time the URL will be valid in seconds |
78
|
|
|
|
|
|
|
# |
79
|
|
|
|
|
|
|
# Returns: A reference to a hash with the following possible keys |
80
|
|
|
|
|
|
|
# activation_url - Activation URL for this phone |
81
|
|
|
|
|
|
|
# activation_barcode - Activation URL for QR code for this phone |
82
|
|
|
|
|
|
|
# installation_url - Install URL if one was requested |
83
|
|
|
|
|
|
|
# valid_secs - How long URLs will be valid |
84
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem getting activation URLs |
85
|
|
|
|
|
|
|
sub activation_url { |
86
|
2
|
|
|
2
|
1
|
651
|
my ($self, $args_ref) = @_; |
87
|
2
|
|
|
|
|
5
|
my %args = %{$args_ref}; |
|
2
|
|
|
|
|
8
|
|
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
# Canonicalize the install argument. |
90
|
2
|
100
|
66
|
|
|
16
|
if (defined($args_ref) && defined($args_ref->{install})) { |
91
|
1
|
50
|
|
|
|
6
|
$args{install} = $args{install} ? 1 : 0; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
# Make the JSON call and return the results. |
95
|
2
|
|
|
|
|
8
|
my $uri = "/admin/v1/phones/$self->{phone_id}/activation_url"; |
96
|
2
|
|
|
|
|
10
|
return $self->{_duo}->call_json('POST', $uri, \%args); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# Commit any changed data and refresh the object from Duo. |
100
|
|
|
|
|
|
|
# |
101
|
|
|
|
|
|
|
# $self - The Net::Duo::Admin::Phone object to commit changes for |
102
|
|
|
|
|
|
|
# |
103
|
|
|
|
|
|
|
# Returns: undef |
104
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem updating the object |
105
|
|
|
|
|
|
|
sub commit { |
106
|
2
|
|
|
2
|
1
|
556
|
my ($self) = @_; |
107
|
2
|
|
|
|
|
17
|
return $self->SUPER::commit("/admin/v1/phones/$self->{phone_id}"); |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
# Delete the phone from Duo. After this call, the object should be treated as |
111
|
|
|
|
|
|
|
# read-only since it can no longer be usefully updated. |
112
|
|
|
|
|
|
|
# |
113
|
|
|
|
|
|
|
# $self - The Net::Duo::Admin::Phone object to delete |
114
|
|
|
|
|
|
|
# |
115
|
|
|
|
|
|
|
# Returns: undef |
116
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem deleting the object |
117
|
|
|
|
|
|
|
## no critic (Subroutines::ProhibitBuiltinHomonyms) |
118
|
|
|
|
|
|
|
sub delete { |
119
|
1
|
|
|
1
|
1
|
309
|
my ($self) = @_; |
120
|
1
|
|
|
|
|
10
|
$self->{_duo}->call_json('DELETE', "/admin/v1/phones/$self->{phone_id}"); |
121
|
1
|
|
|
|
|
2
|
return; |
122
|
|
|
|
|
|
|
} |
123
|
|
|
|
|
|
|
## use critic |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
# Send a new batch of SMS passcodes to a phone. |
126
|
|
|
|
|
|
|
# |
127
|
|
|
|
|
|
|
# $self - The Net::Duo::Admin::Phone object to which to send SMS passcodes |
128
|
|
|
|
|
|
|
# |
129
|
|
|
|
|
|
|
# Returns: undef |
130
|
|
|
|
|
|
|
# Throws: Net::Duo::Exception on any problem sending passcodes |
131
|
|
|
|
|
|
|
sub send_sms_passcodes { |
132
|
1
|
|
|
1
|
1
|
358
|
my ($self) = @_; |
133
|
1
|
|
|
|
|
5
|
my $uri = "/admin/v1/phones/$self->{phone_id}/send_sms_passcodes"; |
134
|
1
|
|
|
|
|
6
|
$self->{_duo}->call_json('POST', $uri); |
135
|
1
|
|
|
|
|
3
|
return; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
__END__ |