File Coverage

blib/lib/Net/Duo/Admin/Token.pm
Criterion Covered Total %
statement 23 24 95.8
branch 1 2 50.0
condition n/a
subroutine 9 9 100.0
pod 3 3 100.0
total 36 38 94.7


line stmt bran cond sub pod time code
1             # Representation of a single Duo token for the Admin API.
2             #
3             # This class wraps the Duo representation of a single Duo token, as returned
4             # by (for example) the Admin /tokens REST endpoint.
5              
6             package Net::Duo::Admin::Token 1.01;
7              
8 6     6   138 use 5.014;
  6         21  
9 6     6   33 use strict;
  6         11  
  6         132  
10 6     6   29 use warnings;
  6         12  
  6         188  
11              
12 6     6   31 use parent qw(Net::Duo::Object);
  6         10  
  6         47  
13              
14 6     6   390 use Net::Duo::Admin::User;
  6         10  
  6         1422  
15              
16             # Data specification for converting JSON into our object representation. See
17             # the Net::Duo::Object documentation for syntax information.
18             ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
19             sub _fields {
20             return {
21 13     13   72 serial => 'simple',
22             token_id => 'simple',
23             type => 'simple',
24             users => 'Net::Duo::Admin::User',
25             };
26             }
27             ## use critic
28              
29             # Install our accessors.
30             Net::Duo::Admin::Token->install_accessors;
31              
32             # Override the new method to support creating a token from an ID instead
33             # of decoded JSON data.
34             #
35             # $class - Class of object to create
36             # $duo - Net::Duo object to use to create the object
37             # $id_or_data - Token ID or reference to data
38             #
39             # Returns: Newly-created object
40             # Throws: Net::Duo::Exception on any problem creating the object
41             sub new {
42 3     3 1 8 my ($class, $duo, $id_or_data) = @_;
43 3 50       8 if (!ref($id_or_data)) {
44 0         0 $id_or_data = $duo->call_json('GET', "/admin/v1/tokens/$id_or_data");
45             }
46 3         12 return $class->SUPER::new($duo, $id_or_data);
47             }
48              
49             # Override the create method to add the appropriate URI.
50             #
51             # $class - Class of object to create
52             # $duo - Net::Duo object to use to create the object
53             # $data_ref - Data for new object as a reference to a hash
54             #
55             # Returns: Newly-created object
56             # Throws: Net::Duo::Exception on any problem creating the object
57             sub create {
58 1     1 1 69 my ($class, $duo, $data_ref) = @_;
59 1         10 return $class->SUPER::create($duo, '/admin/v1/tokens', $data_ref);
60             }
61              
62             # Delete the token from Duo. After this call, the object should be treated as
63             # read-only since it can no longer be usefully updated.
64             #
65             # $self - The Net::Duo::Admin::Token object to delete
66             #
67             # Returns: undef
68             # Throws: Net::Duo::Exception on any problem deleting the object
69             ## no critic (Subroutines::ProhibitBuiltinHomonyms)
70             sub delete {
71 1     1 1 2 my ($self) = @_;
72 1         6 $self->{_duo}->call_json('DELETE', "/admin/v1/tokens/$self->{token_id}");
73 1         3 return;
74             }
75             ## use critic
76              
77             1;
78             __END__