App-RoboBot

 view release on metacpan or  search on metacpan

lib/App/RoboBot/Plugin/API/Github.pm  view on Meta::CPAN

            $self->bot->config->plugins->{'github'}{'token'}
        );
    }

    my $response = $self->ua->request($req);

    return unless $response->is_success;

    my $json;
    eval {
        $json = decode_json($response->decoded_content);
    };

    return if $@;
    return $json;
}

sub _run_watcher {
    my ($self, $bot) = @_;

    # Ensure that we only get repositories that are currently associated with

lib/App/RoboBot/Plugin/API/Kegerator.pm  view on Meta::CPAN

    }

    my $req = HTTP::Request->new( GET => $uri->as_string );

    my $response = $self->ua->request($req);

    return unless $response->is_success;

    my $json;
    eval {
        $json = decode_json($response->decoded_content);
    };

    return if $@;
    return $json;
}

sub _run_watcher {
    my ($self, $bot) = @_;

    # TODO: Call base API path, get JSON

lib/App/RoboBot/Plugin/API/PagerDuty.pm  view on Meta::CPAN

    my $req = HTTP::Request->new( GET => $uri->as_string );
    $req->header( 'Content-type'  => 'application/json' );
    $req->header( 'Authorization' => sprintf('Token token=%s', $group->{'api_key'}) );

    my $response = $self->ua->request($req);

    return unless $response->is_success;

    my $json;
    eval {
        $json = decode_json($response->decoded_content);
    };
    return if $@;
    return $json;
}

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

    return DateTime->now->iso8601 . 'Z';
}

lib/App/RoboBot/Plugin/API/Translate.pm  view on Meta::CPAN

    my $response = $self->ua->post('https://datamarket.accesscontrol.windows.net/v2/OAuth2-13',
        { grant_type    => 'client_credentials',
          client_id     => $client,
          client_secret => $secret,
          scope         => 'http://api.microsofttranslator.com' });

    return 0 unless $response->is_success;

    my $json;
    eval {
        $json = decode_json($response->decoded_content);
    };
    return 0 if $@;
    return 0 unless ref($json) eq 'HASH' && exists $json->{'access_token'} && $json->{'access_token'} =~ m{HMACSHA256};

    $self->token($json->{'access_token'});
    $self->last_authed(time() +0);

    return 1;
}

lib/App/RoboBot/Plugin/API/Translate.pm  view on Meta::CPAN

    $req->header('Authorization' => sprintf('Bearer %s', $self->token));

    my $res = $self->ua->request($req);

    return unless $res->is_success;

    my $translation;

    eval {
        $translation = XML::LibXML->load_xml(
            string => $res->decoded_content
        )->getElementsByTagName("string") . "";
    };

    return if $@ || !defined $translation || length($translation) < 1;

    # TODO: This should eventually have some sort of garbage collection to keep
    #       the translation cache from growing out of control on long running
    #       bot processes.
    $self->cache->{$from}{$to}{$key} = $translation;
    return $translation;

lib/App/RoboBot/Plugin/Net/HTTP.pm  view on Meta::CPAN

    if ($self->_check_rate_limit($url)) {
        $self->_log_http_request($url);
    } else {
        $message->response->raise('That site has been queried too much recently. Please wait a few minutes before requesting a page from it again.');
        return;
    }

    my $response = $self->ua->get($url);

    if ($response->is_success) {
        return $response->decoded_content;
    }

    $message->response->raise("Could not GET %s: %s", $url, $response->status_line);
    return;
}

sub http_headers {
    my ($self, $message, $command, $rpl, $url) = @_;

    unless (defined $url && length($url) > 0) {

lib/App/RoboBot/Plugin/Net/URLs.pm  view on Meta::CPAN

    });
    $finder->find(\$text);

    return @uris;
}

sub get_title {
    my ($self, $r) = @_;

    my $tree = HTML::TreeBuilder::LibXML->new;
    $tree->parse($r->decoded_content);
    $tree->eof;

    my @values = $tree->findvalue('//head/title');

    if (@values && scalar(@values) > 0) {
        return $values[0];
    }

    return;
}



( run in 0.323 second using v1.01-cache-2.11-cpan-26ccb49234f )