Show
Ignore:
Timestamp:
04/03/08 15:56:41 (8 months ago)
Author:
yusukebe
Message:

lang/perl/WebService-Simple: get のオプションで base URL を変更可能に. thanks mattn_jp http://mattn.kaoriya.net/software/lang/perl/20080402145529.htm

Files:
1 modified

Legend:

Unmodified
Added
Removed
  • lang/perl/WebService-Simple/trunk/lib/WebService/Simple.pm

    r8680 r8741  
    2323 
    2424sub get { 
    25     my ($self, $request_param) = @_; 
    26     my $url = $self->_make_url($request_param); 
     25    my ($self, $request_param, $opt) = @_; 
     26    my $url = $self->_make_url($request_param, $opt->{path}); 
    2727    my $response = $self->_fetch_url($url); 
    2828    return $response; 
     
    4545    return $response; 
    4646} 
     47 
    4748sub _make_url{ 
    48     my ($self, $request_param) = @_; 
     49    my ($self, $request_param, $path) = @_; 
    4950    my $base_url = $self->{base_url}; 
     51    if($path){ 
     52        $path =~ s!^/!! if $base_url =~ /\/$/; 
     53        $base_url = $base_url . $path; 
     54    } 
    5055    my $url = $base_url =~ /\?$/ ? $base_url : $base_url . "?"; 
    5156    my @params; 
     
    7479=head1 NAME 
    7580 
    76 WebService::Simple - Simple interface to any Web Service APIs 
     81WebService::Simple - Simple interface to Web Service APIs 
    7782 
    7883=head1 VERSION 
     
    95100=head1 DESCRIPTION 
    96101 
    97 WebService::Simple provides you a simple interface to any Web Servcie APIs 
     102WebService::Simple provides you a simple interface to Web Servcie APIs 
    98103 
    99104=head1 METHODS 
     
    117122 
    118123Get the WebService::Simple::Response object. 
     124 
     125If you want to add a path to base URL, use option parameters. 
     126 
     127    my $lingr = WebService::Simple->new( 
     128        base_url => 'http://www.lingr.com/', 
     129        param    => { api_key => "your_api_key", format => 'xml' } 
     130    ); 
     131    my $response = $lingr->get( {}, { path => '/api/session/create' } ); 
    119132 
    120133=back 
     
    141154Yusuke Wada  C<< <yusuke@kamawada.com> >> 
    142155 
    143  
    144156=head1 LICENCE AND COPYRIGHT 
    145157