use Mubot4FB::DB;
use Mubot4FB::FB;
+use Mubot4FB::Queue;
use Data::Dumper;
my ($me) = @_;
$me->{fb} = Mubot4FB::FB->new($me->{cfg});
$me->{db} = Mubot4FB::DB->new($me->{cfg});
+ $me->{queue} = Mubot4FB::Queue->new($me->{cfg}, $me->{db}->{dbh});
$me->misc_init;
return 1;
}
if ($post_ok) {
my (undef, $post_id) = split(/_/, $resp->{id});
- $me->{db}->add({submitter => $args->{who},
- fb_post_id => $post_id,
- uri => $uri,
- prefix => $prefix,
- comment => $comment});
+ my $db_args = {submitter => $args->{who},
+ fb_post_id => $post_id,
+ uri => $uri,
+ prefix => $prefix,
+ comment => $comment,
+ _command => 'add'};
+ $me->{db}->add($db_args);
+ if (defined $me->{cfg}->{queues}) {
+ foreach my $funcname (@{$me->{cfg}->{queues}}) {
+ $me->{queue}->insert($funcname, $db_args);
+ }
+ }
$resp_msg = $args->{who} . ': うい '.$me->{fb}->post_uri($post_id).' で登録';
} else {
$resp_msg = 'can not post to facebook';
# fb 側のエントリを削除しないといけない
if ($me->{fb}->remove($post_id)) {
$me->{db}->commit;
+ if (defined $me->{cfg}->{queues}) {
+ foreach my $funcname (@{$me->{cfg}->{queues}}) {
+ $me->{queue}->insert($funcname, {_command => 'remove', post_id => $post_id});
+ }
+ }
$resp_msg = $args->{who} . ': 削除しました ' . $me->{fb}->post_uri($post_id);
} else {
$me->{db}->rollback;
--- /dev/null
+#!/usr/bin/perl
+#
+# Copyright (c) 2012 ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
+# This program is covered by the GNU General Public License 2
+#
+package Mubot4FB::Common;
+
+use strict;
+use utf8;
+
+use Data::Dumper;
+
+sub new {
+ my ($proto, $cfg) = @_;
+ my $class = ref $proto || $proto;
+ my $self = {cfg => $cfg};
+ bless $self, $class;
+
+ $self->init();
+ return $self;
+}
+
+sub init {
+ return 1;
+}
+
+sub post_uri {
+ my ($me, $post_id) = @_;
+
+ return $me->{cfg}->{fb_page_url} . '/posts/' . $post_id;
+}
+
+1;
use HTTP::Request::Common;
use URI::Split qw(uri_split uri_join);
-use Data::Dumper;
-
-sub new {
- my $proto = shift;
- my $class = ref $proto || $proto;
- my $self = {cfg => shift};
- bless $self, $class;
+use base 'Mubot4FB::Common';
- $self->init();
- return $self;
-}
+use Data::Dumper;
sub init {
my ($me) = @_;
return $me->{fbo} = Facebook::Graph->new(access_token => $page_access_token);
}
-
sub uri_fixer {
my ($me, $uri) = @_;
->as_hashref();
}
-sub post_uri {
- my ($me, $post_id) = @_;
-
- return $me->{cfg}->{fb_page_url} . '/posts/' . $post_id;
-}
-
sub remove {
my ($me, $post_id) = @_;
--- /dev/null
+#!/usr/bin/perl
+#
+# Copyright (c) 2012 ISHIKAWA Mutsumi <ishikawa@hanzubon.jp>
+# This program is covered by the GNU General Public License 2
+#
+package Mubot4FB::Queue;
+use strict;
+use utf8;
+
+use TheSchwartz::Simple;
+
+use Data::Dumper;
+
+sub new {
+ my ($proto, $cfg, $dbh) = @_;
+ my $class = ref $proto || $proto;
+ my $self = {cfg => $cfg, dbh => $dbh};
+ bless $self, $class;
+
+ $self->init();
+ return $self;
+}
+
+sub init {
+ my ($me) = @_;
+
+ return $me->{queue} = TheSchwartz::Simple->new([ $me->{dbh} ]);
+}
+
+sub insert {
+ my ($me, $funcname, $arg) = @_;
+
+ $me->{queue}->insert($funcname, $arg);
+}
+
+1;