- Remove xmlrtorrent.pm, refactor to $talker methods
[xmlrtorrent.git] / xmlrtorrent / RTorrentTalkerBase.pm
diff --git a/xmlrtorrent/RTorrentTalkerBase.pm b/xmlrtorrent/RTorrentTalkerBase.pm
new file mode 100644 (file)
index 0000000..3f451da
--- /dev/null
@@ -0,0 +1,81 @@
+# Talker for RTorrent
+#
+# (c) 2008 by Ralf Ertzinger <ralf@camperquake.de>
+# licensed under GNU GPL v2
+
+package xmlrtorrent::RTorrentTalkerBase;
+use xmlrtorrent::TalkerBase;
+@ISA = qw(xmlrtorrent::TalkerBase);
+
+use Data::Dumper;
+use strict;
+
+sub new {
+    my $class = shift;
+    my $self = $class->SUPER::new();
+
+    bless($self, $class);
+
+    $self->_prepare_parameters();
+
+    return $self;
+}
+
+sub load_start {
+    my $self = shift;
+    my $url = shift;
+    my $res;
+
+    $res = $self->send_request('load_start', $url);
+    unless(ref($res)) {
+        $self->{'__ERROR'} = $res;
+        return undef;
+    }
+
+    if ($res->is_fault()) {
+        $self->{'__ERROR'} = $res->value()->{'faultString'};
+        return undef;
+    }
+
+    return 1;
+}
+
+sub download_list {
+    my $self = shift;
+    my $talker = shift;
+    my $res;
+
+    $res = $talker->send_request('d.multicall', '',
+            'd.get_name=',
+            'd.get_size_bytes=',
+            'd.get_bytes_done=',
+            'd.get_up_rate=',
+            'd.get_down_rate=',
+            'd.is_active=');
+    unless(ref($res)) {
+        $self->{'__ERROR'} = $res;
+        return undef
+    }
+
+    if ($res->is_fault()) {
+        $self->{'__ERROR'} = $res->value()->{'faultString'};
+        return undef;
+    }
+
+    my @ret = ();
+    foreach (@{$res->value()}) {
+        push @ret,
+        {
+            'NAME'       => $_->[0]->value(),
+            'SIZE_BYTES' => $_->[1]->value(),
+            'BYTES_DONE' => $_->[2]->value(),
+            'UP_RATE'    => $_->[3]->value(),
+            'DOWN_RATE'  => $_->[4]->value(),
+            'ACTIVE'     => $_->[5]->value(),
+        };
+    }
+
+    return \@ret;
+}
+
+1;