#!perl
use strict;
use warnings;
use WWW::Facebook::API::Simple;

my $cb = 'http://www.unobe.com/perl-wfa/test.cgi';
my $client = WWW::Facebook::API::Simple->new(
    callback => $cb,
    desktop => 0,
    throw_errors => 1,
    parse_response => 1, # uses XML::Simple if set to 1
);

# Session initialization
# prompts for login credentials from STDIN
my $token = $client->login->login();
$client->auth->get_session( auth_token => $token );

# Dump XML data returned
use Data::Dumper;
my @friends = @{ $client->friends->get };
print Dumper $client->friends->are_friends(
    uids1 => [@friends[0,1,2,3]],
    uids2 => [@friends[4,5,6,7]],
);

my $unread_pokes = $client->notifications->get->{pokes}->[0]->{unread}->[0];
print "You have $unread_pokes unread poke(s).\n";

my @users
    = @{ $client->users->get_info( uids => \@friends, fields => ['quotes'] ) };
print "Number of friends:".@users."\n";

# Get number of quotes by derefrencing, and then removing the null items (hash
# refs)
my @quotes = grep !ref, map { @{$_->{'quotes'}} } @users;
print "Number of quotes: ".@quotes."\n";
print "Random quote: ".$quotes[int rand @quotes]."\n";

$client->auth->logout;
