しゃある通信

#10-01 [iPhone,perl]Boxcar User APIを使ってiPhoneに任意のメッセージを送信するスクリプト

  1. Boxcar を起動して Sign Up もしくは Sign in。ここで使った Email AddressPassword はあとで使います。
  2. Boxcar の「Add a Service」から「Growl」を選んで Advanced Settings を Alert: Full Message に。 ほかはお好みで。
  3. ~/.netrc に
    machine boxcar.io
            login    さっきのEmail Address
            password さっきのPassword
    
    と書く。chmod 600 ~/.netrc もしておく。
  4. 次のスクリプトに適当な名前(boxcar-growlとか)をつけて (Crypt::SSLeay モジュールが必要です)
    #!/usr/bin/perl
    
    use strict;
    use Net::Netrc;
    use LWP::UserAgent;
    use HTTP::Request::Common qw(POST);
    
    my $BOXCAR_DOMAIN = 'boxcar.io';
    my $boxcar = Net::Netrc->lookup($BOXCAR_DOMAIN);
    
    my %formdata = (
        'notification[from_screen_name]' => $ARGV[0],
        'notification[message]' => $ARGV[1],
        'notification[from_remote_service_id]' => time,
        );
    my $postURI = "https://$BOXCAR_DOMAIN/notifications";
    my $req = POST($postURI, [%formdata]);
    $req->authorization_basic($boxcar->login, $boxcar->password);
    
    my $ua = LWP::UserAgent->new(timeout => 10);
    my $res = $ua->request($req);
    if (! $res->is_success) {
        print $res->message . "\n";
    }
    
    実行してみる
    $ boxcar-growl `hostname -s` "This is test."
    
送信できるメッセージは140文字までだそうです。



マクロミルへ登録

© 2010 Kazuya 'Sharl' Masuda
(C)Willoo Entertainment Inc. (C)Konami Digital Entertainment 株式会社ウィローエンターテイメント及び株式会社コナミデジタルエンタテインメントの著作権を侵害する行為は禁止されています。 0.003966 cached