Fork me on GitHub

2009/01/07

Recent entries from same category

  1. Web::Scraperでvim.orgのkarmaを調べる。 Hatena
  2. perldocのbash-completionが激しく便利でうれしょん出た。 Hatena
  3. Perl音痴な私がPerlを使っている理由 Hatena
  4. TatsumakiとDUI Streamを使って画像ストリーミングサーバ作ってみた。 Hatena
  5. のび太の物は俺の物。俺の物は俺の物。 Hatena

はてな
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};

blog comments powered by Disqus
WriteBacks

TrackBack ping me at
Post a comment

writeback message: Ready to post a comment.