Skip to content

Instantly share code, notes, and snippets.

@mostlyfine
Created January 24, 2013 09:15
Show Gist options
  • Select an option

  • Save mostlyfine/4618994 to your computer and use it in GitHub Desktop.

Select an option

Save mostlyfine/4618994 to your computer and use it in GitHub Desktop.
im.kayac.comにメッセージを送信するサンプル 同じディレクトリに以下の形式でconfig.plを用意する。 +{ username => 'USERNAME', password => 'PASSWORD', };
#!/usr/bin/env perl
use strict;
use warnings;
use utf8;
use Encode;
use LWP::UserAgent;
use JSON;
use Digest::SHA1 qw(sha1_hex);
use HTTP::Request::Common qw(POST);
my $config = do './config.pl';
my $data = +{message => $ARGV[0]};
die "should be specify message" unless $data->{message};
if($config->{auth} eq 'secretkey') {
$data->{sig} = sha1_hex($data->{message} . $config->{password});
} else {
$data->{password} = $config->{password};
}
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};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment