root/lang/perl/WebService-Simple/trunk/example/lingr.pl @ 10275

Revision 10275, 1.0 kB (checked in by yusukebe, 6 years ago)

example を修正、そろそろCPANにあげる

Line 
1use strict;
2use warnings;
3use WebService::Simple;
4
5my $api_key = $ARGV[0] || "your_api_key";
6my $room_id = "hO4SmQWTdJ4";    # http://www.lingr.com/room/hO4SmQWTdJ4
7my $nickname = "lingr.pl";
8my $message  = "Hello, World.";
9
10my $lingr = WebService::Simple->new(
11    base_url => 'http://www.lingr.com/',
12    param    => { api_key => $api_key, format => 'xml' }
13);
14
15# create session, get session
16my $response;
17$response = $lingr->get( 'api/session/create', {} );
18my $session = $response->parse_response->{session};
19
20# enter the room, get ticket
21$response = $lingr->get(
22    'api/room/enter',
23    {
24        session  => $session,
25        id       => $room_id,
26        nickname => $nickname,
27    },
28);
29my $ticket = $response->parse_response->{ticket};
30
31# say 'Hello, World'
32$response = $lingr->get(
33    'api/room/say',
34    {
35        session => $session,
36        ticket  => $ticket,
37        message => $message,
38    },
39);
40my $status = $response->parse_response->{status};
41
42# destroy session
43$lingr->get( 'api/session/destroy', { session => $session, } );
Note: See TracBrowser for help on using the browser.