App-txtnix

 view release on metacpan or  search on metacpan

README.pod  view on Meta::CPAN

  mention =

Setting a value to an empty string will disable coloring for that element.

=head1 Hooks

I<pre_tweet_hook> and I<post_tweet_hook> are very useful if you want to
push your twtxt file to a remote server. The following examples are just
some ideas, basically the sky is the limit.

Transmit the the latest tweet via curl to an http endpoint:

  post_tweet_hook = "tail -1 {twtfile} | curl -s -d @- -d 'name=foo' -d 'password=bar' http://example.com/feeds"

Publish your twtfile on aws s3:

  post_tweet_hook = "aws s3 cp {twtfile} s3://mybucket.org/twtxt.txt --cache-control 'max-age=60,public'"

Update your git hosted twtfile before tweeting and push it afterwards:

  pre_tweet_hook = "cd ~/git/website && git pull --rebase --prune"

bin/txtnix  view on Meta::CPAN

  mention =

Setting a value to an empty string will disable coloring for that element.

=head1 Hooks

I<pre_tweet_hook> and I<post_tweet_hook> are very useful if you want to
push your twtxt file to a remote server. The following examples are just
some ideas, basically the sky is the limit.

Transmit the the latest tweet via curl to an http endpoint:

  post_tweet_hook = "tail -1 {twtfile} | curl -s -d @- -d 'name=foo' -d 'password=bar' http://example.com/feeds"

Publish your twtfile on aws s3:

  post_tweet_hook = "aws s3 cp {twtfile} s3://mybucket.org/twtxt.txt --cache-control 'max-age=60,public'"

Update your git hosted twtfile before tweeting and push it afterwards:

  pre_tweet_hook = "cd ~/git/website && git pull --rebase --prune"

lib/App/txtnix/Registry.pm  view on Meta::CPAN

use Carp;

has [ 'url', 'ua' ];

sub register_user {
    my ( $self, $url, $nickname ) = @_;

    croak('Parameter url or nickname missing')
      if !$url && !$nickname;

    my $endpoint = Mojo::URL->new( $self->url )->path('/api/plain/users')
      ->query( nickname => $nickname, url => $url );

    my $tx = $self->ua->post($endpoint);

    return 1 if $tx->success;

    warn "Can't add user: " . $tx->error->{message} . "\n";
    return 0;
}

sub get_users {
    my ( $self, $user, $cb ) = @_;
    my $query = Mojo::URL->new( $self->url )->path('/api/plain/users')
      ->query( q => $user || '' );
    return $self->query_endpoint( $query, $cb );
}

sub get_tweets {
    my ( $self, $text, $cb ) = @_;
    my $query = Mojo::URL->new( $self->url )->path('/api/plain/tweets')
      ->query( q => $text || '' );
    return $self->query_endpoint( $query, $cb );
}

sub get_tags {
    my ( $self, $tag, $cb ) = @_;
    croak('Parameter tag must be provided for get_tag.')
      if not $tag;
    my $query = Mojo::URL->new( $self->url )->path("/api/plain/tags/$tag");
    return $self->query_endpoint( $query, $cb );
}

sub get_mentions {
    my ( $self, $url, $cb ) = @_;
    croak('Parameter url must be provided for get_mentions.')
      if not $url;
    my $query = Mojo::URL->new( $self->url )->path('/api/plain/mentions')
      ->query( url => $url );
    return $self->query_endpoint( $query, $cb );
}

sub process_result {
    my ( $self, $tx ) = @_;
    my @result;
    if ( my $res = $tx->success ) {
        for my $line ( split /\n/, b( $res->body )->decode ) {
            push @result, [ split /\t/, $line ];
        }
    }
    return @result;
}

sub query_endpoint {
    my ( $self, $endpoint, $cb ) = @_;
    if ($cb) {
        return $self->ua->get(
            $endpoint => sub {
                my ( $ua, $tx ) = @_;
                my @result = $self->process_result($tx);
                $cb->(@result);
            }
        );
    }
    return $self->process_result( $self->ua->get($endpoint) );
}

1;



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