AnyEvent-SparkBot

 view release on metacpan or  search on metacpan

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

      # 4: HTTP::Result Object
    };


=back

=head2 Delete Meetings

=over 4

=item * Blocking my $result=$self->deleteMeetings($roomId)

Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.

=item * Non-Blocking my $id=$self->que_deleteMeetings($cb,$roomId)

Example Callback

  $cb=sub {
    my ($self,$id,$result,$request,$response,$roomId)=@_;
      # 0: $self The current AnyEvent::HTTP::Slack object
      # 1: $id the id of the http request
      # 2: Data::Result Object
      # 3: HTTP::Request Object
      # 4: HTTP::Result Object
    };


=back

=head2 Update Meetings

=over 4

=item * Blocking my $result=$self->updateMeetings($roomId,$hashRef)

Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.

=item * Non-Blocking my $id=$self->que_updateMeetings($cb,$roomId,$hashRef)

Example Callback

  $cb=sub {
    my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_;
      # 0: $self The current AnyEvent::HTTP::Slack object
      # 1: $id the id of the http request
      # 2: Data::Result Object
      # 3: HTTP::Request Object
      # 4: HTTP::Result Object
    };


=back

=head1 Attaching files to messages

Posting files to channel steps outside of the traditional json data format. 

=over 4 

=item * Blocking my $result=$self->uploadFile('/path/to/file',%args);

Returns a L<Data::Result> Object, when true it contains the data, when false it contains why it failed.

=item * Non-Blocking my $result=$self->que_uploadFile($cb,'/path/to/file',%args);

Example Callback

  $cb=sub {
    my ($self,$id,$result,$request,$response,$roomId,$hashRef)=@_;
      # 0: $self The current AnyEvent::HTTP::Slack object
      # 1: $id the id of the http request
      # 2: Data::Result Object
      # 3: HTTP::Request Object
      # 4: HTTP::Result Object
    };

=back

=cut

sub que_uploadFile {
  my ($self,$cb,$file,%args)=@_;

  my $post=[
    %args,
    files=>[$file],
  ];

  my $url=$self->api_url.'messages';
  my $request=POST($url,Content_type=>'form-data',Content=>$post);
  $request->header(Authorization=>"Bearer ".$self->token);
  return $self->queue_request($request,$cb);
}

=head1 Low Level Request functions

This section documents low level request functions.

=over 4

=cut

=item * $self->handle_paginate($id,$result,$request,$response,$cb) 

Internal Method wrapper for parsing pagination headers.

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);



( run in 1.570 second using v1.01-cache-2.11-cpan-b16cb0d3907 )