|
Revision 10275, 1.0 kB
(checked in by yusukebe, 5 years ago)
|
|
example を修正、そろそろCPANにあげる
|
| Line | |
|---|
| 1 | use strict; |
|---|
| 2 | use warnings; |
|---|
| 3 | use WebService::Simple; |
|---|
| 4 | |
|---|
| 5 | my $api_key = $ARGV[0] || "your_api_key"; |
|---|
| 6 | my $room_id = "hO4SmQWTdJ4"; # http://www.lingr.com/room/hO4SmQWTdJ4 |
|---|
| 7 | my $nickname = "lingr.pl"; |
|---|
| 8 | my $message = "Hello, World."; |
|---|
| 9 | |
|---|
| 10 | my $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 |
|---|
| 16 | my $response; |
|---|
| 17 | $response = $lingr->get( 'api/session/create', {} ); |
|---|
| 18 | my $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 | ); |
|---|
| 29 | my $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 | ); |
|---|
| 40 | my $status = $response->parse_response->{status}; |
|---|
| 41 | |
|---|
| 42 | # destroy session |
|---|
| 43 | $lingr->get( 'api/session/destroy', { session => $session, } ); |
|---|