Git Product home page Git Product logo

net-fritz-phonebook's Introduction

Travis Build Status AppVeyor Build Status

NAME

Net::Fritz::Phonebook - manage the Fritz!Box phonebook from Perl

SYNOPSIS

my $fb = Net::Fritz::Box->new(
    username => $username,
    password => $password,
    upnp_url => $host,
);
my $device = $fb->discover;
if( my $error = $device->error ) {
    die $error
};

my @phonebooks = Net::Fritz::Phonebook->list(device => $device);

This module uses the API exposed by the Fritz!Box via TR064 to read, create and update contacts in a phone book. This uses the X_AVM-DE_OnTel service, which is specific to the AVM Fritz!Box line of products.

ACCESSORS

id

print $phonebook->id;

The ID of the phone book on the Fritz!Box

name

print $phonebook->name;

The user visible name of the phone book on the Fritz!Box

url

print $phonebook->url;

The URL of the phone book on the Fritz!Box

This URL is used to access the phone book contents.

entries

for my $entry ( @{ $phonebook->entries }) {
    print $entry->name
};

Arrayref of the entries in this phone book. Each entry is a Net::Fritz::PhonebookEntry.

METHODS

$phonebook->create

$phonebook->create();

Creates the phone book on the FritzBox. Entries of this phone book are not saved.

$phonebook->delete

$phonebook->delete();

Deletes the phone book on the FritzBox. All entries of this phone book are also deleted with the phone book.

$phonebook->add_entry

$phonebook->add_entry( $new_contact );

Saves an entry in the phone book on the FritzBox.

$phonebook->get_entry_by_uniqueid

my $entry = $phonebook->get_entry_by_uniqueid( $uniqueid );

Scans all phone book entries and returns the one with the matching unique id

$phonebook->get_entry_by_index

my $entry = $phonebook->get_entry_by_index( 0 );

Retrieves a single entry in the phone book on the FritzBox by its index in the list. This avoids fetching the complete phone book, but you basically have no way of determining the order of entries.

Net::Fritz::Phonebook->by_name( $device, $name )

my $device = $fb->discover;
my $phonebook = Net::Fritz::Phonebook->by_name( device => $device, name => 'Telefonbuch' );

Utility function to find a phonebook by name.

Net::Fritz::Phonebook->list( $service )

my $device = $fb->discover;
my $services = $device->find_service_names(qr/X_AVM-DE_OnTel/);
my @phonebooks = Net::Fritz::Phonebook->list( service => $services->data->[0] );

Net::Fritz::Phonebook->reload

$phonebook->reload();

Refreshes the content of the phonebook from the Fritz!Box. This is useful if you have added or removed entries from the phone book and want to fetch the state on the Fritz!Box again.

SEE ALSO

https://avm.de/fileadmin/user_upload/Global/Service/Schnittstellen/x_contactSCPD.pdf

REPOSITORY

The public repository of this module is https://github.com/Corion/Net-Fritz-Phonebook.

SUPPORT

The public support forum of this module is https://perlmonks.org/.

BUG TRACKER

Please report bugs in this module via the RT CPAN bug queue at https://rt.cpan.org/Public/Dist/Display.html?Name=Net-Fritz-Phonebook or via mail to [email protected].

AUTHOR

Max Maischein [email protected]

COPYRIGHT (c)

Copyright 2017-2023 by Max Maischein [email protected].

LICENSE

This module is released under the same terms as Perl itself.

net-fritz-phonebook's People

Contributors

voegelas avatar corion avatar

Watchers

 avatar James Cloos avatar  avatar

Forkers

haarg

net-fritz-phonebook's Issues

AddPhonebookEntry action doesn't seem to exist

Before I realized that I can add new contacts with Net::Fritz::Phonebook->add_entry, I tried to use Net::Fritz::PhonebookEntry->save, which failed.

The latter method uses the action AddPhonebookEntry, which neither exists in AVM's x_contactSCPD.pdf document nor is supported by my Fritz!Box. I can save contacts if I replace AddPhonebookEntry with SetPhonebookEntry plus XML payload.

There's also a Net::Fritz::PhonebookEntry->create method, which uses AddPhonebookEntry. As far as I can see, that method cannot work. AddPhonebookEntry does not exist and SetPhonebookEntry requires at least a name.

Scripts don’t get installed?

There’s no EXE_FILES section in your Makefile.PL so the user has to dig the scripts out of the tarball separately… is that intentional? (And if so… can I request making a separate App:: out of them maybe?)

Add XML declaration for SetPhonebookEntry

To get non-ASCII characters inserted correctly, I needed to add an explicit XML declaration to the XML passed to the SetPhonebookEntry service. This can be obtained by adding XMLDecl => 1 to the XMLout call.

sub add_entry( $self, $entry ) {
    my $s = $entry->build_structure;

    my $xml = XMLout({ contact => [$s]}, XMLDecl => 1);
    #use Data::Dumper;
    #$Data::Dumper::Useqq = 1;
#    $xml =~ s; (quickdial|prio|vanity)="";;g;
#    $xml =~ s;<category>0</category>;<category/>;g;
    #print Dumper \$xml;

    my $res = $self->service->call('SetPhonebookEntry',
        NewPhonebookID => $self->id,
        NewPhonebookEntryID => '', # new entry
        NewPhonebookEntryData => $xml,
    );
};

Alternatively, insert the header explicitly:

    $xml = '<?xml version="1.0" encoding="utf-8"?>'."\n".$xml;

(This is what I prefer, since it includes the encoding.)
You may wish to add the two lines stripping quickdial, prio and vanity attributes from phone numbers and eliminating the setting of category 0.

Deleting an entry deletes the wrong entry

The following snippet:

my $entry = $phonebooks[0]->get_entry_by_uniqueid(1201);
printf( "%4d: %4d %s %s %s\n",
    $entry->uniqueid,
    $entry->phonebookIndex,
    $entry->category,
    $entry->name,
    join(",", map { $_->content } @{$entry->numbers}),
  );
$entry->delete;

This prints the data for entry with uniqueId 1201. In my particular case, this entry has phonebookIndex 26. After the delete is executed, entry with uniqueId 1201 still exists in the phonebook, but an unrelated entry (uniqueId 1101, phonebookIndex 31) is deleted instead.

The reason seems to be that, when retrieving all entries, or using get_entry_by_uniqueid, internal entries (e.g. **601) are included in the list (and occupy index numbers) while get_entry_by_index (and delete !) do not take these internal entries into account.

Ironically, when get_entry_by_index is used, the PhonebookEntry retrieved does not have its phonebookIndex set and hence it cannot be deleted unless you set the index manually.

And yes, entry index numbers are updated after each delete.

Prevent dummy quickdial/vanity codes

The XML to add a phone number uses the following number entity:

<number prio="" vanity="" quickdial="">123456</number>

The empty vanity and quickdial attributes lead to dummy quickdial/vanity codes in the primary phone book. To avoid this, remove them from the XML, e.g.

sub add_entry( $self, $entry ) {
    my $s = $entry->build_structure;

    my $xml = XMLout({ contact => [$s] }, XMLDecl => 1 );
    #use Data::Dumper;
    #$Data::Dumper::Useqq = 1;
    $xml =~ s; (quickdial|prio|vanity)="";;g;
    $xml =~ s;<category>0</category>;<category/>;g;
#    use DDumper; DDumper \$xml;
    #print Dumper \$xml;

    my $res = $self->service->call('SetPhonebookEntry',
        NewPhonebookID => $self->id,
        NewPhonebookEntryID => '', # new entry
        NewPhonebookEntryData => $xml,
    );
};

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.