AnyEvent-SparkBot

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

  -- Changed min version of Carp to 1.38
1.011 
  -- Removed old vendor doc links
  -- Added missing meetings api and pod
1.012
  -- Added uploadFile interface
1.013
  -- Fixed the readme file
1.014
  -- Added retry for 404 ( these are super common )
	-- fixed missing method retryTimeout, now has a default value of 1 second
1.015
  -- Changed the default api url from: https://api.ciscospark.com/v1/ To:  https://webexapis.com/v1/

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

	#default=>'https://api.ciscospark.com/v1/',
	default=>'https://webexapis.com/v1/',
);

has retryCount=>(
  isa=>Int,
  is=>'ro',
  default=>1,
);

has retryTimeout=>(
  isa=>Int,
	is=>'ro',
	default=>1,
);

has retryAfter=>(
  isa=>Int,
  is=>'ro',
  default=>10,
);

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

  return $self->queue_result($cb,$result) unless $result;
  my $request=$result->get_data;

  my $wrap;
  my $count=$self->retryCount;
  if($self->is_blocking) {
    $wrap=sub {
      my ($self,$id,$result,undef,$response)=@_;

      return $cb->(@_) if $result or !($response->code==429 and $count-- >0);
      my $timeout=looks_like_number($response->header('Retry-After')) ? $response->header('Retry-After') : $self->retryTimeout;
      $self->log_warn("Request: $id recived a 429 response, will retry in $timeout seconds");
      

      if($count>0)  {
        my $next_id=$self->queue_request($request,sub { 
          my ($self,undef,$result,undef,$response)=@_;
	  $wrap->($self,$id,$result,$request,$response);
	});
        $self->add_ids_for_blocking($next_id);
        return $self->agent->run_next;

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

      };
      
      my $next_id=$self->queue_request($request,$code);
      $self->add_ids_for_blocking($next_id);
      $self->agent->run_next;
    };
  } else {
    $wrap=sub {
      my ($self,$id,$result,undef,$response)=@_;
      return $cb->(@_) if $result || !(($response->code==429 || $response->code==404) &&  $count-- >0);
      my $timeout=looks_like_number($response->header('Retry-After')) ? $response->header('Retry-After') : $self->retryTimeout;
      $self->log_warn("Request: $id recived a 429 response, will retry in $timeout seconds");

      if($count>0)  {
	my $ae;
	$ae=AnyEvent->timer(after=>$timeout,cb=>sub {
          my $next_id=$self->queue_request($request,sub { 
            my ($self,undef,$result,undef,$response)=@_;
	    $wrap->($self,$id,$result,$request,$response);
	  });
          $self->add_ids_for_blocking($next_id);

lib/AnyEvent/SparkBot.pm  view on Meta::CPAN


=head1 Moo Role(s)

This module uses the following Moo role(s)

  HTTP::MultiGet::Role
  AnyEvent::SparkBot::SharedRole

=cut

has retryTimeout=>(
  is=>'ro',
  isa=>Int,
  default=>10,
  lazy=>1,
);

has retryCount=>(
  is=>'ro',
  isa=>Int,
  default=>1,

lib/AnyEvent/SparkBot.pm  view on Meta::CPAN


  reconnect: default is true
  logger: null(default) or an instance of log4perl::logger
  lastConn: location to the last connection file
    # it may be a very good idea to set this value
    # default: /tmp/sparkBotLastConnect.json
  defaultUrl: https://wdm-a.wbx2.com/wdm/api/v1/devices
    # this is where we authenticate and pull the websocket url from
  deviceDesc: JSON hash, representing the client description
  agent: an instance of AnyEvent::HTTP::MultiGet
  retryTimeout: default 10, sets how long to wait afer getting a 429 error
  retryCount: default 1, sets how many retries when we get a 429 error

Timout and retry values:

  pingEvery: 60 # used to check how often we run a ping
    # pings only happen if no inbound request has come in for 
    # the interval
  pingWait: 10 
    # how long to wait for a ping response
  reconnect_sleep: 10



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