The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
#!/usr/bin/perl
# ABSTRACT: Upload images to rajce.net.
# PODNAME: rajce-put

use strict;
use warnings;

use Getopt::Std;
use Net::Netrc;
use WebService::Rajce;
use Pod::Usage;

$|++;

my %opt;
getopts('VhvDkt:d:', \%opt); 

if($opt{h}){
	pod2usage(-verbose => 2, -output => '-');
	exit;
}

my $version = $WebService::Rajce::VERSION;

if($opt{V}){
	print "$version\n";
	exit;
}

if(!@ARGV or !$opt{t}){
	pod2usage(-verbose => 1, -output => '-');
	exit;
}

my $desc = '';
if($opt{d}){
	$desc = $opt{d};
}

my $rajce = new WebService::Rajce('keep_exif'=>$opt{k},'debug'=>$opt{D});

my $user = Net::Netrc->lookup($rajce->{API})
	or die "Cant find $rajce->{API} in \$HOME/.netrc";

info("Login to rajce.net ...",%opt);
my $login = $rajce->login($user->login,$user->password)
	or die "Bad username or password.";
info(" OK\n",%opt);

info("Create new album ...",%opt);
my $album = $rajce->create_album($opt{t},$desc)
	or die "Failed to create new album";
info(" OK\n",%opt);

foreach my $file(@ARGV){
	info("Uploading $file ...",%opt);
	$rajce->add_photo($file,$album)
		or die "Failed add file $file";
	info(" OK\n",%opt);
}

sub info{
	my ($message,%opt) = @_;
	if($opt{v}){
		print "$message";
	}
}

__END__

=pod

=encoding UTF-8

=head1 NAME

rajce-put - Upload images to rajce.net.

=head1 VERSION

version 1.152420

=head1 SYNOPSIS

rajce-put [-V ] [-h] [-v] [-D] [-k] -t 'Title' [ -d 'Description' ] file.jpg file2.jpg ...

=head1 DESCRIPTION

This program will upload images to rajce.net. Before you start uploading
add entry to $HOME/.netrc

Something like this:

machine http://www.rajce.idnes.cz/liveAPI/index.php login mail@example.com password nbu123

Set the correct access rights:

$ chmod 700 $HOME/.netrc

Behind proxy server try set:

export http_proxy=http://your.proxyserver:port

=head1 OPTIONS AND ARGUMENTS

	 -h - Help
	 -v - Verbose mode
	 -D - Debugging messages
	 -k - Keep exif data
	 -t - Specify title of album
	 -d - Description of album
	 -V - Show version and exit

=head1 SEE ALSO

For creating account visit: www.rajce.net/ucet

https://metacpan.org/module/WebService::Rajce

=head1 AUTHOR

Petr Kletecka <pek@cpan.org>

=head1 COPYRIGHT AND LICENSE

This software is copyright (c) 2015 by Petr Kletecka.

This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.

=cut