aboutsummaryrefslogtreecommitdiffstats
path: root/tools/piwigo_remote.pl
diff options
context:
space:
mode:
authorplegall <plg@piwigo.org>2009-11-22 22:09:41 +0000
committerplegall <plg@piwigo.org>2009-11-22 22:09:41 +0000
commit6768482bcf5ba73a1fd429a1584134c2b213044d (patch)
treeec2e97b7c785c50312c63d18a792c75fb0cf8c49 /tools/piwigo_remote.pl
parent2bba9bc48a96378668bb460b11c5bcdd48a33669 (diff)
feature 1051: new API method pwg.images.checkFiles. This method will be useful
before asking for an update on photo files. Enhancement in code factorization. git-svn-id: http://piwigo.org/svn/branches/2.0@4344 68402e56-0260-453c-a942-63ccdbb3a9ee
Diffstat (limited to 'tools/piwigo_remote.pl')
-rw-r--r--tools/piwigo_remote.pl64
1 files changed, 63 insertions, 1 deletions
diff --git a/tools/piwigo_remote.pl b/tools/piwigo_remote.pl
index ceb2af4b9..91b072aeb 100644
--- a/tools/piwigo_remote.pl
+++ b/tools/piwigo_remote.pl
@@ -17,6 +17,7 @@ use warnings;
use JSON;
use LWP::UserAgent;
+# LWP::Debug::level('+');
use Getopt::Long;
use Encode qw/is_utf8 decode/;
use POSIX qw(ceil floor);
@@ -40,6 +41,7 @@ GetOptions(
);
our $ua = LWP::UserAgent->new;
+$ua->agent('Mozilla/piwigo_remote.pl 1.25');
$ua->cookie_jar({});
my %conf;
@@ -56,6 +58,11 @@ foreach my $conf_key (keys %conf_default) {
$conf{$conf_key} = defined $opt{$conf_key} ? $opt{$conf_key} : $conf_default{$conf_key}
}
+$ua->default_headers->authorization_basic(
+ $conf{username},
+ $conf{password}
+);
+
my $result = undef;
my $query = undef;
@@ -78,7 +85,6 @@ $result = $ua->post(
if ($opt{action} eq 'pwg.images.add') {
use MIME::Base64 qw(encode_base64);
use Digest::MD5::File qw/file_md5_hex/;
- use File::Slurp;
$form = {};
$form->{method} = 'pwg.images.add';
@@ -132,6 +138,7 @@ if ($opt{action} eq 'pwg.images.add') {
print "upload successful\n";
}
else {
+ print Dumper($response);
warn 'A problem has occured during upload', "\n";
warn $response->decoded_content, "\n";
die $response->status_line;
@@ -170,6 +177,7 @@ if ($opt{action} eq 'pwg.tags.getAdminList') {
);
$result = $ua->get($query);
+ print Dumper($result);
my $tags = from_json($result->content)->{result}{tags};
foreach my $tag (@{$tags}) {
@@ -234,6 +242,37 @@ if ($opt{action} eq 'pwg.images.exist') {
# print Dumper($response);
}
+if ($opt{action} eq 'pwg.images.checkFiles') {
+ use Digest::MD5::File qw/file_md5_hex/;
+
+ $form = {};
+ $form->{method} = $opt{action};
+
+ foreach my $type (qw/thumbnail file high/) {
+ if (defined $opt{$type}) {
+ $form->{$type.'_sum'} = file_md5_hex($opt{$type});
+ }
+ }
+
+ foreach my $key (keys %{ $opt{define} }) {
+ $form->{$key} = $opt{define}{$key};
+ }
+
+ my $response = $ua->post(
+ $conf{base_url}.'/ws.php?format=json',
+ $form
+ );
+
+ print "-" x 50, "\n";
+ printf("response code : %u\n", $response->code);
+ printf("response message : %s\n", $response->message);
+ print "-" x 50, "\n";
+ print "\n";
+
+ use Data::Dumper;
+ print Dumper(from_json($response->content));
+}
+
if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setInfo') {
$form = {
method => $opt{action},
@@ -253,6 +292,27 @@ if ($opt{action} eq 'pwg.images.setInfo' or $opt{action} eq 'pwg.categories.setI
print Dumper($response);
}
+if ($opt{action} eq 'pwg.categories.getList') {
+ $form = {
+ method => $opt{action},
+ };
+
+ foreach my $key (keys %{ $opt{define} }) {
+ $form->{$key} = $opt{define}{$key};
+ }
+
+ my $response = $ua->post(
+ $conf{base_url}.'/ws.php?format=json',
+ $form
+ );
+
+ use Data::Dumper;
+ print Dumper($response->content);
+ print Dumper(from_json($response->content)->{result});
+ print Dumper($response);
+}
+
+
$query = pwg_ws_get_query(
method => 'pwg.session.logout'
);
@@ -273,6 +333,8 @@ sub pwg_ws_get_query {
sub send_chunks {
my %params = @_;
+ use File::Slurp;
+
my $content = read_file($params{filepath});
my $content_length = length($content);
my $nb_chunks = ceil($content_length / $conf{chunk_size});