Subject: | Constructor parameters fix, add support for HTTP DELETE |
Documentation proposes following use
my $ws = WebService::Futu->new( user => 'username',
pass => 'password' );
but with current CPAN code hash reference is needed
my $ws = WebService::Futu->new({ user => 'username',
pass => 'password' });
Attached patch:
- fixes the constructor to expect parameters in documented (first) way
- adds HTTP DELETE method support
Subject: | futu.patch |
diff -ur WebService.old/Futu.pm WebService/Futu.pm
--- WebService.old/Futu.pm 2010-11-19 15:07:57.000000000 +0100
+++ WebService/Futu.pm 2011-04-04 01:59:39.499344294 +0200
@@ -77,16 +77,16 @@
sub new {
my $class = shift;
- my $hash = shift;
+ my %hash = @_;
- unless ( (defined($hash->{'user'}) or defined($hash->{'id'})) && defined($hash->{'pass'}) ) {
+ unless ( (defined($hash{'user'}) or defined($hash{'id'})) && defined($hash{'pass'}) ) {
die "Must define user and pass to initialise object";
}
my $self;
- $self->{_user} = $hash->{'user'} if exists $hash->{'user'};
- $self->{_id} = $hash->{'id'} if exists $hash->{'id'};
- $self->{_pass} = $hash->{'pass'};
- $self->{_url} = exists $hash->{'url'} ? $hash->{'url'} : 'https://www.futu.cz';
+ $self->{_user} = $hash{'user'} if exists $hash{'user'};
+ $self->{_id} = $hash{'id'} if exists $hash{'id'};
+ $self->{_pass} = $hash{'pass'};
+ $self->{_url} = exists $hash{'url'} ? $hash{'url'} : 'https://www.futu.cz';
return bless($self, $class);
}
@@ -154,6 +154,21 @@
return $self->_perform_auth('PUT', @other);
}
+=item perform_delete($content)
+
+Perform delete on the server.
+Automatically request authentication token.
+$content is used for sending content.
+
+ my $personal = $self->perform_delete('/api/transaction/123', $content);
+
+=cut
+
+sub perform_delete {
+ my ($self, @other) = @_;
+ return $self->_perform_auth('DELETE', @other);
+}
+
sub _perform_auth {
my ($self, $method, $query, $content) = @_;
@@ -226,7 +241,7 @@
}
my $body = $ua->request($req);
- print STDERR Dumper($body);
+ #print STDERR Dumper($body);
return $body;
}