Show
Ignore:
Timestamp:
06/20/08 12:38:50 (5 months ago)
Author:
tokuhirom
Message:

added channels api

Location:
lang/perl/App-Nakanobu/trunk
Files:
3 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/App-Nakanobu/trunk/lib/App/Nakanobu/Plugin/Component/IRCClient.pm

    r14220 r14284  
    8282    ); 
    8383 
     84    # hook some channels. 
    8485    for my $command (qw(notice privmsg)) { 
    8586        $context->register_hook( 
     
    9293        ); 
    9394    } 
     95 
     96    $context->register_hook( 
     97        'channels' => $self => sub { 
     98            my ($self, ) = @_; 
     99            $self->channels; 
     100        }, 
     101    ); 
    94102}; 
    95103 
  • lang/perl/App-Nakanobu/trunk/lib/App/Nakanobu/Plugin/Component/JSONRPC/HTTP.pm

    r14207 r14284  
    2525 
    2626my $method_map = { 
    27     map { 
     27    map({ 
    2828        $_ => sub { 
    2929            my $command = $_; 
     
    3434            } 
    3535        }->() 
    36     } qw(notice privmsg) 
     36    } qw(notice privmsg)), 
     37    channels => sub { 
     38        [ 
     39            map { @{ $_ } } # flatten 
     40            @{ App::Nakanobu->context->run_hook( 'channels' ) } 
     41        ] 
     42    }, 
    3743}; 
    3844 
  • lang/perl/App-Nakanobu/trunk/tools/jsonrpc-client.pl

    r14250 r14284  
    44use JSON::RPC::Client; 
    55 
    6 my $uri = 'http://localhost:5555/'; 
    7 my $method = 'privmsg'; 
    8 my $params = {channel => '#てすと', text => "abcあいうえお123\n456" }; 
    96 
    10 my $client = JSON::RPC::Client->new; 
    11 my $res = $client->call($uri, { method => $method, params => $params } ); 
    12 if ($res) { 
    13     if ($res->is_error) { 
    14         warn $res->error_message; 
     7call( 'http://localhost:5555/', 'privmsg', 
     8    { channel => '#てすと', text => "abcあいうえお123\n456" }, 
     9); 
     10 
     11call( 'http://localhost:5555/', 'channels', {}); 
     12 
     13sub call { 
     14    my ($uri, $method, $params) = @_; 
     15 
     16    my $client = JSON::RPC::Client->new; 
     17    my $res = $client->call($uri, { method => $method, params => $params } ); 
     18    if ($res) { 
     19        if ($res->is_error) { 
     20            warn $res->error_message; 
     21        } else { 
     22            use Data::Dumper; warn Dumper($res->result); 
     23            print $res->result, "\n"; 
     24        } 
    1525    } else { 
    16         use Data::Dumper; warn Dumper($res->result); 
    17         print $res->result, "\n"; 
     26        print $client->status_line; 
    1827    } 
    19 } else { 
    20     print $client->status_line; 
    2128} 
    22