LoginSignup
0
0

More than 5 years have passed since last update.

Etherpad-lite PerlのAPIモジュール

Last updated at Posted at 2018-05-06

Etherpad-lite PerlのAPIモジュール

これは何?

Etherpad-liteのHTTP APIをPerlのモジュールを使って操作する方法の紹介です。

HTTP API

上記公式サイトの説明が非常にわかりやすいのでここを見ていただければ十分だと思います。

プログラム言語からのHTTP API操作のモジュール

HTTP API client libraries
https://github.com/ether/etherpad-lite/wiki/HTTP-API-client-libraries
を参照してください。
Pythonについては以下も参考になります。
https://qiita.com/gkmaro634/items/8152b8ba9572dc5b5aa5

PerlモジュールのAPI

上記のHTTP APIをPerlモジュールで操作します。

cpanm Etherpad

でインストールできます。

  • Mojoliciousとかが必要なようですのでPerlバージョン等は注意です。

使い方

https://github.com/ether/etherpad-lite/wiki/HTTP-API
のExample 1相当を実行してみます。

use strict;
use warnings;

use Etherpad;

my $url ='http://192.168.33.10:9001';
my $apikey ='secret';

my $ec = Etherpad->new(
   url      => $url,
   apikey   => $apikey
);

my $authorID = $ec->create_author_if_not_exists_for( '100', 'John');
print "$authorID:authorID\n";

my $groupID = $ec->create_group_if_not_exists_for('999');
print "$groupID:groupID\n";

my $padID = $ec->create_group_pad( $groupID, 'padName' ,'test1');
print "$padID:padID\n";

my $sessionID =$ec->create_session($groupID, $authorID, 1893423600);
print "$sessionID:sessionID\n";

得られたsessionIDの値をクッキーで
sessionIDというキーで書き込めば対象のドキュメントを編集できるようになります。

非常に簡単です。
ただPerlのAPIについてはMojoliciousが必要です。
やっていることの単純さの割にMojoliciousを必要とする理由は考えてみてもいいかもしれません。

  • おそらく主にMojo::Baseを使いたいためのようです。

場合によってはHTTP APIを直接操作するなり自分でモジュールを作るなりでもいいかもしれません。

0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0