Created
January 24, 2013 09:15
-
-
Save mostlyfine/4618994 to your computer and use it in GitHub Desktop.
im.kayac.comにメッセージを送信するサンプル 同じディレクトリに以下の形式でconfig.plを用意する。
+{ username => 'USERNAME', password => 'PASSWORD',
};
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| #!/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