Net::Duo::Admin::Phone

(Representation of a Duo phone)

SYNOPSIS

    my $decoded_json = get_json();
    my $phone = Net::Duo::Admin::Phone->new($decoded_json);
    say $phone->number;

REQUIREMENTS

Perl 5.14 or later and the modules HTTP::Request and HTTP::Response (part of HTTP::Message), JSON, LWP (also known as libwww-perl), Perl6::Slurp, Sub::Install, and URI::Escape (part of URI), all of which are available from CPAN.

DESCRIPTION

A Net::Duo::Admin::Phone object is a Perl representation of a Duo phone as returned by the Duo Admin API, usually via the phones() method or nested in a user returned by the users() method. It contains various information about a phone.

CLASS METHODS

create(DUO, DATA)

Creates a new phone in Duo and returns the resulting phone as a new Net::Duo::Admin::Phone object. DUO is the Net::Duo object that should be used to perform the creation. DATA is a reference to a hash with the following keys:

extension

The extension. Optional.

name

The name of the phone. Optional.

number

The phone number. Optional.

platform

The platform of phone for Duo Mobile, or unknown for a generic phone type. For the list of valid values, see the Duo Admin API documentation. Optional.

postdelay

The time (in seconds) to wait after the extension is dialed and before the speaking the prompt. Optional.

predelay

The time (in seconds) to wait after the number picks up and before dialing the extension. Optional.

type

The type of the phone. See the "type()" method below for the possible values. Optional.

new(DUO, DATA)

Creates a new Net::Duo::Admin::Phone object from a full data set. DUO is the Net::Duo object that should be used for any further actions on this object. DATA should be the data structure returned by the Duo REST API for a single user, after JSON decoding.

new(DUO, ID)

Creates a new Net::Duo::Admin::Phone by ID. DUO is the Net::Duo object that is used to retrieve the phone from Duo and will be used for any subsequent operations. The ID should be the Duo identifier of the phone. This constructor is distinguished from the previous constructor by checking whether ID is a reference.

INSTANCE ACTION METHODS

activation_url([ARGS])

Request activation URLs (and optionally an install URL) for this phone. ARGS is an optional reference to a hash whose keys should be chosen from the following:

install

If set to a true value, request an installation URL for this phone as well as the activation URLs. This is a URL that, when opened, will prompt the user to install Duo Mobile. The default is to not request an installation URL.

valid_secs

The number of seconds these activation URLs should be valid for. The default is 86,400 (one day).

The return value of this method will be a reference to a hash containing the following keys:

activation_url

Opening this URL with the Duo Mobile app will complete activation.

activation_barcode

URL of an image that can be scanned with Duo Mobile to complete activation. Activating with this image or with the activation URL will produce the same result.

installation_url

Opening this URL on the phone will prompt the user to install Duo Mobile. This will only be present if the install argument is set to a true value.

valid_secs

The number of seconds that the activation code is valid for. Normally this will be the same as the valid_secs argument in the request if it was present, unless Duo rejected the requested validity interval.

commit()

Commit all changes made via the set_*() methods to Duo. Until this method is called, any changes made via set_*() are only internal to the object and not reflected in Duo.

After commit(), the internal representation of the object will be refreshed to match the new data returned by the Duo API for that object. Therefore, other fields of the object may change after commit() if some other user has changed other, unrelated fields in the object.

It's best to think of this method as a synchronize operation: changed data is written back, overwriting what's in Duo, and unchanged data may be overwritten by whatever is currently in Duo, if it is different.

delete()

Delete this phone from Duo. After successful completion of this call, the Net::Duo::Admin::Phone object should be considered read-only, since no further changes to the object can be meaningfully sent to Duo.

json()

Convert the data stored in the object to JSON and return the results. The resulting JSON should match the JSON that one would get back from the Duo web service when retrieving the same object (plus any changes made locally to the object via set_*() methods). This is primarily intended for debugging dumps or for passing Duo objects to other systems via further JSON APIs.

send_sms_passcodes()

Generate a new batch of SMS passcodes and send them to the phone in a single SMS message. The number of passcodes sent is a global setting on the Duo account.

INSTANCE DATA METHODS

Some fields have set_*() methods. Those methods replace the value of the field in its entirety with the new value passed in. This change is only made locally in the object until commit() is called.

activated()

Whether the phone has been activated for Duo Mobile.

capabilities()

A list of phone capabilities, chosen from the following values:

push

The device is activated for Duo Push.

phone

The device can receive phone calls.

sms

The device can receive batches of SMS passcodes.

extension()
set_extension(EXTENSION)

The extension for this phone, if any.

name()
set_name(NAME)

The name of this phone.

number()
set_number(NUMBER)

The number for this phone, without any extension.

phone_id()

The unique ID of this phone as generated by Duo on phone creation.

platform()
set_platform(PLATFORM)

The platform of phone for Duo Mobile, or unknown for a generic phone type. For the list of valid values, see the Duo Admin API documentation.

postdelay()
set_postdelay(POSTDELAY)

The time (in seconds) to wait after the extension is dialed and before the speaking the prompt.

predelay()
set_predelay(PREDELAY)

The time (in seconds) to wait after the number picks up and before dialing the extension.

sms_passcodes_sent()

Whether SMS passcodes have been sent to this phone.

type()
set_type(TYPE)

The type of phone, chosen from unknown, mobile, or landline.

users()

The users associated with this phone as a list of Net::Duo::Admin::User objects.

AUTHOR

Russ Allbery <rra@cpan.org>

COPYRIGHT AND LICENSE

Copyright 2014 The Board of Trustees of the Leland Stanford Junior University

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

SEE ALSO

Net::Duo::Admin

Duo Admin API for phones

This module is part of the Net::Duo distribution. The current version of Net::Duo is available from CPAN, or directly from its web site at <http://www.eyrie.org/~eagle/software/net-duo/>.

Last modified and spun 2015-08-16