2009/04/16 21:33:41
Config::Pitとエディタが立ち上がるように変更した。
サービスのURIを知るためにwgetしたらつながらなくてあせったが--auth-no-challengeオプションを入れて解決
#!/opt/local/bin/perl
use XML::Atom::Client;
use XML::Atom::Entry;
use constant NS_DC => 'http://purl.org/dc/elements/1.1/';
use File::Temp;
use File::Slurp;
use Path::Class;
use Config::Pit;
my $vox = "kzfm.vox.com";
my $title = "";
my $content = "";
my $category = "life";
my $config = pit_get($vox, require => {
"username" => "your username on vox",
"password" => "your password on vox",
"postURI" => "your potURI"
});
my $f = File::Temp->new();
close $f;
my $t = file($f->filename)->stat->mtime;
system $ENV{EDITOR}, $f->filename;
if ($t == file($f->filename)->stat->mtime) {
print STDERR "No changes.";
} else {
my @lines = read_file($f->filename);
$title = shift @lines;
$content = join "", @lines
}
die "content not found\n" unless $content;
my $api = XML::Atom::Client->new;
$api->username($config->{username});
$api->password($config->{password});
my $entry = XML::Atom::Entry->new;
$entry->title($title);
$entry->content($content);
my @tags = split /,/, $category;
my $dc = XML::Atom::Namespace->new( dc => NS_DC );
foreach my $tag (@tags) {
$entry->add( $dc, 'subject', $tag);
}
my $EditURI = $api->createEntry($config->{postURI}, $entry);
print $api->errstr if $api->errstr;
2007/09/20 20:51:08
Voxクライアントが便利だが、タグ付けできなくてちょっと不便なので入れられるようにしてみた。それぞれのエントリみると
<category term="test" label="test" />
みたいに組めばよさそうだったので、blog.nomadscafe.jpを参考に。
my $entry = XML::Atom::Entry->new;
$entry->title($title);
my $category = XML::Atom::Category->new(Version=>1);
$category->term('life');
$category->label('life');
$entry->category($category);
$entry->content($content);
これだと、なぜかタグが反映されない。なんでかなーと調べてたらSix Apartの野良プラグインにヒントが
あった。
<dc:subject xmlns:dc="http://purl.org/dc/elements/1.1/">life</dc:subject>
が正しいらしい。なので修正したら動いた。
use constant NS_DC => 'http://purl.org/dc/elements/1.1/';
...
my $entry = XML::Atom::Entry->new;
$entry->title($title);
$entry->content($content);
my @tags = split /,/, $category;
my $dc = XML::Atom::Namespace->new( dc => NS_DC );
foreach my $tag (@tags) {
$entry->add( $dc, 'subject', $tag);
}
オプションでタグを選べるようになった
$ vx -t 英語ネタ -c english,life "fortranner の goto は \
ロードランナーの穴掘り。たまに掘った穴に埋まる"
2007/09/18 21:32:44
vox用のCLIを作った。post用のURIはこんな感じで探した。本当はhttp://www.vox.com/services/atomにGETして返ってきたXMLをパースすんのがいいんだろうけど、これはそのうちやる。今回は直接指定した。
#!/usr/bin/perl
use XML::Atom::Client;
use XML::Atom::Entry;
use Getopt::Long;
# --- configure --- #
my $user = vox_user;
my $password = vox_passwd;
my $title = "'(my memo)";
my $PostURI = posturl;
# --- main --- #
GetOptions ("title=s" => \$title);
my $content = shift @ARGV;
die "content not found\n" unless $content;
my $api = XML::Atom::Client->new;
$api->username($user);
$api->password($password);
my $entry = XML::Atom::Entry->new;
$entry->title($title);
$entry->content($content);
my $EditURI = $api->createEntry($PostURI, $entry);
print $api->errstr if $api->errstr;
これをvxって名前で保存しておく。以下使用例
$ vx "なんか思いついたことを書くとよさげ"
タイトルを変えたいときには
$ vx -t todo "ビリーでダイエット"
とか。
2007/09/18 20:47:19
自分のVox用にCLIが欲しくて、Atompubでつくろっかなと思ったので。
use Atompub::Client;
my $service_uri = 'http://kzfm.vox.com/library/posts/atom.xml';
my $client = Atompub::Client->new;
$client->username('xxx@gmail.com');
$client->password('mokyumokyu');
my $service = $client->getService( $service_uri );
さてこれがエラー。
$ perl atomc.pl
Bad Content-Type: text/xml at /usr/lib/perl5/site_perl/5.8.8/Atompub/Client.pm line 220.
Can't call method "collections" on an undefined value at atomc.pl line 14.
Atompub::MediaTypeあたりを触ればいいんだろうか?エンドポイント間違えてるだけだったりして、、、、
ちょっと興味があるのでソースを読んでみる。あとdraft-ietf-atompub-protocol-17.txtも併せて読む
追記 07.09.18
色々ボケてた。
rsd.xmlに記述されているAtomのAPIにGETしないといけない。
$ wget --http-user=user --http-passwd=XXX \
http://www.vox.com/services/atom
で戻ってきたxmlの中見てservice.postにPOST
ここへのPOSTはXML::Atom::ClientでもAtompub::ClientでもどちらでもOK