The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Firefox::Sync::Client - A Client for the Firefox Sync Server

SYNOPSIS

Simple example:

use Firefox::Sync::Client;

my $c = new Firefox::Sync::Client(
    URL      => 'https://your.ffsync-server.org/',
    User     => 'your@mail.address',
    Password => 'SyncPassword',
    SyncKey  => 'x-thisx-isxxx-thexx-secre-txkey',
);

my $tabs = $c->get_tabs;

foreach my $client (@$tabs) {
    print $client->{'payload'}->{'clientName'} . "\n";
    foreach my $tab (@{$client->{'payload'}->{'tabs'}}) {
        print '    ' . $tab->{'title'} . "\n";
        print '        --> ' . $tab->{'urlHistory'}[0] . "\n";
    }
    print "\n";
}

Advanced example, printing HTML code with all bookmarks and links. Results will be cached:

use Firefox::Sync::Client;
use utf8;
binmode STDOUT, ':encoding(UTF-8)';

my $c = new Firefox::Sync::Client(
    URL       => 'https://your.ffsync-server.org/',
    User      => 'your@mail.address',
    Password  => 'SyncPassword',
    SyncKey   => 'x-thisx-isxxx-thexx-secre-txkey',
    CacheFile => '/tmp/ffsync-cache',
);

my $bm = $c->get_bookmarks;

print '<html><head><meta http-equiv="Content-Type" content="text/html; charset=UTF-8" /></head><body>' . "\n";
print_children(1, $bm);
print '</body></html>' . "\n";

sub print_children {
    my ($h, $bm) = @_;

    foreach my $item (@$bm) {
        if ($item->{'payload'}->{'type'} eq 'folder') {
            print '<h' . $h . '>' . $item->{'payload'}->{'title'} . '</h' . $h . '>' . "\n";
            print '<ul>' . "\n";
            print_children($h + 1, $item->{'payload'}->{'children'});
            print '</ul>' . "\n";
        }

        if (defined $item->{'payload'}->{'bmkUri'}) {
            print '<li>';
            print '<a href="' . $item->{'payload'}->{'bmkUri'} . '" target="_blank">' . $item->{'payload'}->{'title'} . '</a>';
            print '</li>' . "\n";
        }
        else {
            print '<hr>' . "\n";
        }
    }
}

DESCRIPTION

This module implements a client to the popular Firefox Sync service.

More information on the server can be found at Mozilla: https://developer.mozilla.org/en-US/docs/Firefox_Sync

For now, this module is only a read-only client. That means, it is possible to get some collections of things from the server by using either the specialized get_* methods or get_raw_collection(). The methods usually return an array reference.

In a future release, caching and some other improvements will be realized.

METHODS

What each method actually returns, can be different. But it will always be a reference to an array containing hashes. Every hash has the following keys:

id       - The ID of the element.
modified - A timestamp of the last modification
payload  - Contains a hash of elements. The keys are different for each collection
new(%config)

Constructor. You can set the following parameters during construction:

ProtocolVersion - defaults to 1.1
URL             - The server address
User            - The username or e-mail address
Password        - The password
SyncKey         - The sync/recovery key
CacheFile       - A file to be used for caching
CacheLifetime   - Lifetime of cached requests in seconds
get_raw_collection($collection)

Returns an array reference containing all elements of the given collection.

The following collections are tested (but other collections may also work):

bookmarks
prefs
clients
forms
history
passwords
tabs
addons

You can not fetch the metadata with this method, please use get_meta() instead. Also, if you plan to do something with the 'bookmarks' collection, better use get_bookmarks(), as it returns a somewhat nicer formatted array reference.

get_addons()

Returns an array of the synced add-on data.

get_bookmarks()

Returns all bookmark collections, folders and bookmarks in a well formatted array. That means, the references are recursively resolved in the tree.

get_clients()

Returns all known data of the connected Sync clients.

get_forms()

Returns an array of synchronized form input data.

get_history()

Returns the synced browser history.

get_meta()

Returns an array containing the sync metadata for the user.

get_passwords()

Returns all synchronized passwords. The passwords are returned unencrypted.

get_prefs()

Returns the synchronized browser preferences.

get_tabs()

Returns an array of tabs opened on each Sync client / Browser.

AUTHOR

Robin Schroeder, <schrorg@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2012 by Robin Schroeder

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.10 or, at your option, any later version of Perl 5 you may have available.