AXL-Client-Simple

 view release on metacpan or  search on metacpan

lib/AXL/Client/Simple/Phone.pm  view on Meta::CPAN

package AXL::Client::Simple::Phone;
use Moose;

use AXL::Client::Simple::LineResultSet;
use Carp;

our $VERSION = '0.01';
$VERSION = eval $VERSION; # numify for warning-free dev releases

has client => (
    is => 'ro',
    isa => 'AXL::Client::Simple',
    required => 1,
    weak_ref => 1,
);

has stash => (
    is => 'ro',
    isa => 'HashRef',
    required => 1,
);

has currentProfileName => (
    is => 'ro',
    isa => 'Str',
    required => 0,
    lazy_build => 1,
);

sub _build_currentProfileName { return (shift)->stash->{currentProfileName} }

has loginUserId => (
    is => 'ro',
    isa => 'Str',
    required => 0,
    lazy_build => 1,
);

sub _build_loginUserId { return (shift)->stash->{loginUserId} }

sub has_active_em {
    my $self = shift;
    return ($self->currentProfileName && $self->loginUserId);
}

has currentProfile => (
    is => 'ro',
    isa => 'AXL::Client::Simple::Phone',
    lazy_build => 1,
);

sub _build_currentProfile {
    my $self = shift;
    return $self if not $self->has_active_em;

    my $profile = $self->client->getDeviceProfile->(
        profileName => $self->currentProfileName);

    if (exists $profile->{'Fault'}) {
        my $f = $profile->{'Fault'}->{'faultstring'};
        croak "Fault status returned from server in _build_currentProfile: $f\n";
    }

    return AXL::Client::Simple::Phone->new({
        client => $self->client,
        stash  => $profile->{'parameters'}->{'return'}->{'profile'},
    });
}

has lines => (
    is => 'ro',
    isa => 'AXL::Client::Simple::LineResultSet',
    lazy_build => 1,
);

sub _build_lines {
    my $self = shift;

    my @lines = map { { stash => $_ } }
                map { defined $_ ? $_ : () }
                map { $_->{'parameters'}->{'return'}->{'directoryNumber'} }
                map { $self->client->getLine->(uuid => $_) }
                map { $_->{'dirn'}->{'uuid'} }
                    @{ $self->stash->{'lines'}->{'line'} || [] };

    return AXL::Client::Simple::LineResultSet->new({items => \@lines});
}

__PACKAGE__->meta->make_immutable;
no Moose;
1;

__END__

=head1 NAME

AXL::Client::Simple::Phone - Properties and Lines on a CUCM Handset

=head1 VERSION

This document refers to version 0.01 of AXL::Client::Simple::Phone

=head1 SYNOPSIS

First set up your CUCM AXL client as per L<AXL::Client::Simple>:

 use AXL::Client::Simple;
 
 my $cucm = AXL::Client::Simple->new({
     server      => 'call-manager-server.example.com',
     username    => 'oliver',
     password    => 's3krit', # or set in $ENV{AXL_PASS}
 });

Then perform simple queries on the Unified Communications server:

 my $device = $cucm->get_phone('SEP001122334455');
 
 my $lines = $device->lines;
 printf "this device has %s lines.\n", $lines->count;
 
 while ($lines->has_next) {
     my $l = $lines->next;
     print $l->alertingName, "\n";
     print $l->extn, "\n";
 }
 
 if ($device->has_active_em) {
     # extension mobility is active, so the lines are different
 
     my $profile = $device->currentProfile;
 
     my $profile_lines = $profile->lines;
     printf "this profile has %s lines.\n", $profile_lines->count;
 
     while ($profile_lines->has_next) {



( run in 0.608 second using v1.01-cache-2.11-cpan-39bf76dae61 )