|
NAMEWebService::Simple - Simple Interface To Web Services APIsSYNOPSISuse WebService::Simple; # Simple use case my $flickr = WebService::Simple->new( base_url => "http://api.flickr.com/services/rest/", param => { api_key => "your_api_key", } ); # send GET request to # http://api.flickr.com/service/rest/?api_key=your_api_key&method=flickr.test.echo&name=value $flickr->get( { method => "flickr.test.echo", name => "value" } ); # send GET request to # http://api.flickr.com/service/rest/extra/path?api_key=your_api_key&method=flickr.test.echo&name=value $flickr->get( "extra/path", { method => "flickr.test.echo", name => "value" }); DESCRIPTIONWebService::Simple is a simple class to interact with web services.It's basically an LWP::UserAgent that remembers recurring API URLs and parameters, plus sugar to parse the results. METHODS
SUBCLASSINGFor better encapsulation, you can create subclass of WebService::Simple to customize the behaviorpackage WebService::Simple::Flickr; use base qw(WebService::Simple); __PACKAGE__->config( base_url => "http://api.flickr.com/services/rest/", upload_url => "http://api.flickr.com/services/upload/", ); sub test_echo { my $self = shift; $self->get( { method => "flickr.test.echo", name => "value" } ); } sub upload { my $self = shift; local $self->{base_url} = $self->config->{upload_url}; $self->post( Content_Type => "form-data", Content => { title => "title", description => "...", photo => ... }, ); } PARSERSWeb services return their results in various different formats. Or perhaps you require more sophisticated results parsing than what WebService::Simple provides.WebService::Simple by default uses XML::Simple, but you can easily override that by providing a parser object to the constructor: my $service = WebService::Simple->new( response_parser => AVeryComplexParser->new, ... ); my $response = $service->get( ... ); my $thing = $response->parse_response; For example. If you want to set XML::Simple options, use WebService::Simple::Parser::XML::Simple including this module: use WebService::Simple; use WebService::Simple::Parser::XML::Simple; use XML::Simple; my $xs = XML::Simple->new( KeyAttr => [], ForceArray => ['entry'] ); my $service = WebService::Simple->new( base_url => "http://gdata.youtube.com/feeds/api/videos", param => { v => 2 }, response_parser => WebService::Simple::Parser::XML::Simple->new( xs => $xs ), ); This allows great flexibility in handling different Web Services REPOSITORYhttps://github.com/yusukebe/WebService-SimpleAUTHORYusuke Wada "<yusuke@kamawada.com>"Daisuke Maki "<daisuke@endeworks.jp>" Matsuno Tokuhiro Naoki Tomita (tomi-ru) COPYRIGHT AND LICENSEThis module is free software; you can redistribute it and/or modify it under the same terms as Perl itself. See perlartistic.
Visit the GSP FreeBSD Man Page Interface. |