Show
Ignore:
Timestamp:
10/01/11 08:52:12 (20 months ago)
Author:
topia
Message:

* add nma (not tested, but api success)
* add url-format and event-format support for prowl.
* switched to api.prowlapp.com.

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/tiarra/trunk/module/Auto/Notify.pm

    r38984 r39035  
    148148    require URI; 
    149149 
    150     my $url = URI->new("https://prowl.weks.net/publicapi/verify"); 
     150    my $url = URI->new("https://api.prowlapp.com/publicapi/verify"); 
    151151    $url->query_form(apikey => $config->apikey); 
    152152    my $runloop = $this->_runloop; 
     
    156156           Callback => sub { 
    157157               my $stat = shift; 
    158                $runloop->notify_warn(__PACKAGE__." verify failed: $stat") 
     158               $runloop->notify_warn(__PACKAGE__." prowl: verify failed: $stat") 
    159159                   unless ref($stat); 
    160160               ## FIXME: check response (should check 'error') 
     
    166166    my ($this, $config, $text, $msg, $sender, $full_ch_name) = @_; 
    167167 
    168     my $url = URI->new("https://prowl.weks.net/publicapi/add"); 
     168    my $url = URI->new("https://api.prowlapp.com/publicapi/add"); 
    169169    $text = Auto::AliasDB->stdreplace( 
    170170        $msg->prefix, 
     
    174174        raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), 
    175175        text => $this->strip_mirc_formatting($text), 
     176       ); 
     177    my $event; 
     178    if (defined $config->event_format) { 
     179        $event = Auto::AliasDB->stdreplace( 
     180            $msg->prefix, 
     181            $config->event_format, 
     182            $msg, $sender, 
     183            channel => $full_ch_name, 
     184            raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), 
     185            text => $text, 
     186           ); 
     187    } else { 
     188        $event = $config->event || 'keyword'; 
     189    } 
     190    my $uri = Auto::AliasDB->stdreplace( 
     191        $msg->prefix, 
     192        $config->url_format || '', ## config and param are "URL" 
     193        $msg, $sender, 
     194        channel => $full_ch_name, 
     195        raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), 
     196        text => $text, 
    176197       ); 
    177198    my @data = (apikey => $config->apikey, 
    178199                priority => $config->priority || 0, 
    179200                application => $config->application || 'tiarra', 
    180                 event => $config->event || 'keyword', 
     201                event => $event, 
     202                ($uri ne "" ? (url => $uri) : ()), 
    181203                description => $text); 
    182204    $url->query_form(@data); 
     
    369391 
    370392 
     393sub config_nma { 
     394    my ($this, $config) = @_; 
     395 
     396    # I don't have a good feeling to NMA, but Prowl didn't support 
     397    #  Android, on 2011-09-30. 
     398    # see also http://www.cocoaforge.com/viewtopic.php?f=45&t=20765#p129361 
     399    # and check send_prowl and send_nma. 
     400 
     401    require Crypt::SSLeay; # https support 
     402    require URI; 
     403 
     404    foreach my $apikey (split(/,/, $config->apikey)) { 
     405        my $url = URI->new("https://www.notifymyandroid.com/publicapi/verify"); 
     406        $url->query_form(apikey => $apikey, 
     407                         (defined $config->developerkey ? 
     408                              (developerkey => $config->developerkey) : ())); 
     409        my $runloop = $this->_runloop; 
     410        Tools::HTTPClient->new( 
     411            Request => GET($url->as_string()), 
     412           )->start( 
     413               Callback => sub { 
     414                   my $stat = shift; 
     415                   $runloop->notify_warn(__PACKAGE__." NMA: verify failed: $stat") 
     416                       unless ref($stat); 
     417                   ## FIXME: check response (should check 'error') 
     418               }, 
     419              ); 
     420    } 
     421} 
     422 
     423sub send_nma { 
     424    my ($this, $config, $text, $msg, $sender, $full_ch_name) = @_; 
     425 
     426    my $url = URI->new("https://www.notifymyandroid.com/publicapi/notify"); 
     427    $text = Auto::AliasDB->stdreplace( 
     428        $msg->prefix, 
     429        $config->format || $this->config->format || '[tiarra][#(channel):#(nick.now)] #(text)', 
     430        $msg, $sender, 
     431        channel => $full_ch_name, 
     432        raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), 
     433        text => $this->strip_mirc_formatting($text), 
     434       ); 
     435    my $event = Auto::AliasDB->stdreplace( 
     436        $msg->prefix, 
     437        $config->event_format || 'keyword', 
     438        $msg, $sender, 
     439        channel => $full_ch_name, 
     440        raw_channel => Auto::Utils::get_raw_ch_name($msg, 0), 
     441        text => $text, 
     442       ); 
     443    my @data = (apikey => $config->apikey, 
     444                priority => $config->priority || 0, 
     445                application => $config->application || 'tiarra', 
     446                event => $event, 
     447                description => $text, 
     448                (defined $config->developerkey ? 
     449                     (developerkey => $config->developerkey) : ())); 
     450    $url->query_form(@data); 
     451 
     452    my $runloop = $this->_runloop; 
     453    Tools::HTTPClient->new( 
     454        Request => GET($url->as_string()), 
     455       )->start( 
     456           Callback => sub { 
     457               my $stat = shift; 
     458               if (!ref($stat)) { 
     459                   $runloop->notify_warn(__PACKAGE__." NMA: post failed: $stat"); 
     460               } elsif ($stat->{Content} !~ /<success /) { 
     461                   (my $content = $stat->{Content}) =~ s/\s+/ /; 
     462                   $runloop->notify_warn(__PACKAGE__." NMA: post failed: $content"); 
     463               } 
     464           }, 
     465          ); 
     466} 
     467 
     468 
    3714691; 
    372470 
     
    393491 
    394492# 使用するブロックを指定します 
    395 -blocks: im prowl boxcar-growl boxcar-provider notifo 
     493-blocks: im prowl boxcar-growl boxcar-provider notifo nma 
    396494 
    397495im { 
     
    422520# 通知先ごとにフォーマットを指定できます。 
    423521# この例では先頭に時刻を追加しています。 
    424 -format: #(date:%H:%M:%S) [#(channel):#(nick.now)] #(text) 
     522-format: #(date:%H:%M:%S) #(text) 
    425523 
    426524# Prowl で表示された apikey を入力します。 
     
    428526-apikey: XXXXXX 
    429527 
     528# イベントのフォーマットを指定できます。 
     529# 省略すると event の設定が利用されます。 
     530event-format: #(channel):#(nick.now) 
     531 
     532# URLのフォーマットを指定できます。 
     533# 省略すると通知にURLを含めません。 
     534# 現状の機構ではURLをエスケープする手段がないので、固定値以外はお勧めしません。 
     535# また、 URL を指定するとアプリ側でのredirect設定は無視されるようです。 
     536url-format: 
     537 
     538# イベントを指定します。(固定値) 
     539# event-format が指定された場合はそちらが優先されます。 
     540event: keyword 
     541 
     542 
    430543# http://forums.cocoaforge.com/viewtopic.php?f=45&t=20339 
    431544priority: 0 
    432545application: tiarra 
    433 event: keyword 
    434546 
    435547} 
     
    530642} 
    531643 
     644nma { 
     645 
     646# 通知先のタイプを指定します。 
     647# Notify My Android には nma を指定してください。 
     648type: nma 
     649 
     650# 通知先ごとにフォーマットを指定できます。 
     651# この例では先頭に時刻を追加しています。 
     652format: #(date:%H:%M:%S) #(text) 
     653 
     654# NMA で表示された apikey を入力します。 
     655# https://www.notifymyandroid.com/account.php 
     656# カンマで区切ると複数のAPIキーを指定することができます。 
     657-apikey: XXXXXX 
     658 
     659# イベントのフォーマットを指定できます。 
     660# デフォルト値: keyword 
     661event-format: #(channel):#(nick.now) 
     662 
     663# https://www.notifymyandroid.com/api.php 
     664priority: 0 
     665application: tiarra 
     666-developerkey: 
     667 
     668} 
     669 
    532670 
    533671=cut