OSDN Git Service

update remove error check
authorISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Mon, 22 Oct 2012 02:53:24 +0000 (11:53 +0900)
committerISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
Mon, 22 Oct 2012 02:53:24 +0000 (11:53 +0900)
mubot4fb.pl

index 869ed4e..9148f93 100755 (executable)
@@ -11,6 +11,8 @@ use Facebook::Graph;
 use LWP::UserAgent;
 use HTTP::Request::Common;
 
+use Data::Dumper;
+
 sub new {
        my $proto = shift;
        my $class = ref $proto || $proto;
@@ -65,10 +67,16 @@ sub remove {
 
        my $uri = $me->{fbo}->query->find($post_id)->uri_as_string;
        my $req = HTTP::Request::Common::DELETE($uri);
-       $req->header('Content-Length', 0);
+       warn Dumper($req);
        my $resp;
-       eval{$resp = LWP::UserAgent->new->request($req)};
-       return !$@;
+       $resp = LWP::UserAgent->new->request($req);
+       warn Dumper($resp);
+       if ($resp->is_success && $resp->code == 200 && $resp->content eq 'true') {
+               return 1;
+       } else {
+               warn 'DELETE ERROR: http code: ' . $resp->code() . ' , http content: ' . $resp->content;
+               return 0;
+       }
 }
 
 1;
@@ -78,9 +86,6 @@ use strict;
 use utf8;
 
 use base 'Bot::BasicBot';
-use Facebook::Graph;
-use LWP::UserAgent;
-use HTTP::Request::Common;
 use DBI qw/:sql_types/;
 use POSIX 'strftime';