2009/01/07

Recent entries from same category

  1. PerlでWindowsと親和性の高いreadlineが欲しい → あった「Caroline」
  2. Perl をゆるふわと語ろう
  3. cpanfile とは何か、なぜそれを使いたいのか
  4. plackup の --path 引数
  5. Github Notification API が出たので通知を Growl するの書いた。

im.kayac.comに送信するperlスクリプト。
コードだけ。
#!/usr/bin/perl
use strict;
use warnings;

use Encode;
use LWP::UserAgent;
use HTTP::Request::Common qw(POST);
use Config::Pit;
use Digest::SHA1 qw(sha1_hex);
use JSON;

if ($^O eq 'MSWin32') {
    eval {
        require Win32::API;
        Win32::API->Import('kernel32', 'UINT GetACP()');
        Encode::from_to($ARGV[0], 'cp'.GetACP(), 'utf-8');
    };
}

my $config = pit_get("im.kayac.com", require => {
        "username" => "your username on im.kayac.com",
        "password" => "your password(or secretkey) on im.kayac.com",
        "authtype" => "auth type on im.kayac.com: none/password/secretkey",
    });

my %data = ( message => shift );
die "should be specify message" unless $data{message};
$data{password} = $config->{password} if $config->{authtype} eq "password";
$data{sig} = sha1_hex($data{message} . $config->{password}) if $config->{authtype} eq "secretkey";

my $ua = LWP::UserAgent->new;
my $res = from_json($ua->post(
    "http://im.kayac.com/api/post/$config->{username}", \%data,
    "Content-Type" => "application/x-www-form-urlencoded"
)->decoded_content);

print $res->{result}.$res->{error};
Posted at by | Edit