| eBay-API-Simple documentation | Contained in the eBay-API-Simple distribution. |
eBay::API::Simple::RSS - Support for grabbing an RSS feed via API call
my $call = eBay::API::Simple::RSS->new();
$call->execute(
'http://sfbay.craigslist.org/search/sss',
{
query => 'shirt',
format => 'rss',
}
);
if ( $call->has_error() ) {
die "Call Failed:" . $call->errors_as_string();
}
# getters for the response DOM or Hash
my $dom = $call->response_dom();
my $hash = $call->response_hash();
# collect all item nodes
my @items = $dom->getElementsByTagName('item');
foreach my $n ( @items ) {
print $n->findvalue('title/text()') . "\n";
}
my $call = ebay::API::Simple::RSS->new();
$call->execute(
'http://sfbay.craigslist.org/search/sss',
{ query => 'shirt', format => 'rss', }
);
This method will construct the API request the supplied URL.
Feed URL to fetch
The supplied args will be encoded and appended to the URL
Accessor for the LWP::UserAgent request agent
Accessor for the HTTP::Request request object
Accessor for the complete request body from the HTTP::Request object
Accessor for the HTTP response body content
Accessor for the HTTP::Request response object
Accessor for the LibXML response DOM
Accessor for the hashified response content
Helper for LibXML that retrieves node content
Accessor to the hashref of errors
Returns true if the call contains errors
Returns a string of API errors if there are any.
This method supplies the XML body for the web service request
This methods supplies the headers for the RSS API call
This method creates the request object and returns to the parent class
Tim Keefer <tim@timkeefer.com>
Tim Keefer 2009
| eBay-API-Simple documentation | Contained in the eBay-API-Simple distribution. |
package eBay::API::Simple::RSS; use strict; use warnings; use base 'eBay::API::SimpleBase'; use HTTP::Request; use HTTP::Headers; use XML::Simple; use URI::Escape; use utf8; our $DEBUG = 0;
sub new { my $class = shift; my $self = $class->SUPER::new(@_); $self->api_config->{request_method} ||= 'GET'; return $self; }
sub execute { my $self = shift; $self->{url} = shift; if ( ! defined $self->{url} ) { die "missing url"; } # collect the optional args $self->{args} = shift; $self->{response_content} = $self->_execute_http_request(); if ( $DEBUG ) { print STDERR $self->request_object->as_string(); print STDERR $self->response_object->as_string(); } }
sub _get_request_body { my $self = shift; my @p; if ( $self->api_config->{request_method} ne 'GET' ) { for my $k ( keys %{ $self->{args} } ) { if ( ref( $self->{args}{$k} ) eq 'ARRAY' ) { for my $ap ( @{ $self->{args}{$k} } ) { push( @p, ( $k . '=' . uri_escape_utf8( $ap ) ) ); } } else { push( @p, ( $k . '=' . uri_escape_utf8( $self->{args}{$k} ) ) ); } } } return join( '&', @p ) or ""; }
sub _get_request_headers { my $self = shift; my $obj = HTTP::Headers->new(); return $obj; }
sub _get_request_object { my $self = shift; my $req_url = undef; # put the args in the url for a GET request only if ( $self->api_config->{request_method} eq 'GET' && defined $self->{args} ) { $req_url = $self->_build_url( $self->{url}, $self->{args} ); } else { $req_url = $self->{url}; } my $request_obj = HTTP::Request->new( ( $self->api_config->{request_method} || 'GET' ), $req_url, $self->_get_request_headers, $self->_get_request_body, ); return $request_obj; } 1;