AnyEvent-Lingr

 view release on metacpan or  search on metacpan

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


has ['user', 'password'] => (
    is       => 'ro',
    required => 1,
);

has 'api_key' => (
    is => 'ro',
);

has 'endpoint' => (
    is      => 'ro',
    default => 'http://lingr.com/api/',
);

has 'session' => (
    is => 'rw',
);

has ['on_error', 'on_room_info', 'on_event'] => (
    is  => 'rw',

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

has '_polling_guard' => (
    is      => 'rw',
    clearer => '_clear_polling_guard',
);

no Mouse;

sub request {
    my ($self, $http_method, $method, $params, $cb) = @_;

    my $uri = URI->new($self->endpoint . $method);
    $uri->query_form($params);

    my $cb_wrap = sub {
        my ($body, $hdr) = @_;

        my $json = try { decode_json $body };
        $cb->($json, $hdr);
    };

    if ($http_method eq 'GET') {

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

}

sub _polling {
    my ($self) = @_;

    if ($self->_polling_guard) {
        debugf 'polling session is still active, ignoring this request';
        return;
    }

    my $uri = URI->new( $self->endpoint . 'event/observe' );
    $uri->port(8080);
    $uri->query_form({ session => $self->session, counter => $self->counter });

    my $guard = http_get $uri, timeout => 60, sub {
        my ($body, $hdr) = @_;
        return unless $self;

        my $res = try { decode_json $body };

        if ($res and $res->{status} eq 'ok') {



( run in 0.462 second using v1.01-cache-2.11-cpan-b61123c0432 )