Net-Flowdock-Stream

 view release on metacpan or  search on metacpan

lib/Net/Flowdock/Stream.pm  view on Meta::CPAN


sub _read_next_chunk {
    my $self = shift;

    my $nbytes = $self->_socket->read_entity_body(my $buf, 4096);
    if (!defined $nbytes) {
        return if $!{EINTR} || $!{EAGAIN};
        die "Error reading from server";
    }
    die "Disconnected" if $nbytes == 0;
    return if $nbytes == -1;

    $self->_append_readbuf($buf);
}

sub _process_readbuf {
    my $self = shift;

    if ((my $buf = $self->_readbuf) =~ s/^([^\x0d]*)\x0d//) {
        my $chunk = $1;
        $self->_readbuf($buf);
        warn "New event:\n$chunk" if $self->debug;
        return decode_json($chunk);
    }

    return;
}

__PACKAGE__->meta->make_immutable;
no Moose;


1;

__END__
=pod

=head1 NAME

Net::Flowdock::Stream - Streaming API for Flowdock

=head1 VERSION

version 0.01

=head1 SYNOPSIS

  my $stream = Net::Flowdock::Stream->new(
      token => '...',
      flows => ['myorg/testing'],
  );

  while (1) {
      if (my $event = $stream->get_next_event) {
          process_event($event);
      }
  }

=head1 DESCRIPTION

This module implements the streaming api for
L<Flowdock|https://www.flowdock.com/>. It provides a non-blocking method which
you can call to get the next available event in the stream. You can then
integrate this method into your existing event-driven app.

=head1 ATTRIBUTES

=head2 token

Your account's API token, for authentication. Required unless C<email> and
C<password> are provided.

=head2 email

Your account's email address, for authentication. Required unless C<token> is
provided.

=head2 password

Your account's password, for authentication. Required unless C<token> is
provided.

=head2 flows

An arrayref of flows that should be listened to for events. Note that the flow
names must include the organization, so C<myorg/testing>, not just C<testing>.

=head1 METHODS

=head2 get_next_event

Returns the next event that has been received in the stream. This call is
nonblocking, and will return undef if no events are currently available.

=head1 BUGS

No known bugs.

Please report any bugs through RT: email
C<bug-net-flowdock-stream at rt.cpan.org>, or browse to
L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Flowdock-Stream>.

=head1 SEE ALSO

L<https://www.flowdock.com/>

=head1 SUPPORT

You can find this documentation for this module with the perldoc command.

    perldoc Net::Flowdock::Stream

You can also look for information at:

=over 4

=item * AnnoCPAN: Annotated CPAN documentation

L<http://annocpan.org/dist/Net-Flowdock-Stream>

=item * CPAN Ratings



( run in 0.553 second using v1.01-cache-2.11-cpan-39bf76dae61 )