AnyEvent-SparkBot

 view release on metacpan or  search on metacpan

lib/AnyEvent/HTTP/Spark.pm  view on Meta::CPAN

Example:

  my $code=sub {
    my ($self,$id,$result,$request,$response)=@_;
    $self->handle_paginate($id,$result,$request,$response,$cb);
  };
  return $self->que_get($code,$url,$args);

Pagination information can be found in the following result fields.

  cursorPosition: last|next|prev|first
  pageLink: (undef when cursorPosition eq 'last') Url to the next page

=cut

sub handle_paginate {
  my ($self,$id,$result,$request,$response,$cb)=@_;
   if($result) {
     my $headers={$response->headers->flatten};
     my $data=$result->get_data;
     $data->{cursorPosition}='last';
     $data->{pageLink}='';
     if(exists $headers->{Link}) {
       my $link=$headers->{Link};
       if($link=~ /^<([^>]+)>;\s+rel="(\w+)"\s*$/s) {
         $data->{pageLink}=$1;
         $data->{cursorPosition}=$2;
       }
     } 
  }

  $cb->(@_);
}

=item * my $result=$self->build_post_json($url,$data);

Returns a Data::Result object; When true it contains an HTTP::Request Object For $url, the body will consist of $data converted to json.  When false it contains why it failed.



( run in 0.232 second using v1.01-cache-2.11-cpan-4d50c553e7e )