Skip to content
This repository has been archived by the owner on Apr 22, 2021. It is now read-only.

Commit

Permalink
Add --created-at for tweet
Browse files Browse the repository at this point in the history
  • Loading branch information
mdom committed Feb 25, 2016
1 parent ea2096f commit 59cf675
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 2 deletions.
14 changes: 12 additions & 2 deletions lib/App/txtnix/Cmd/tweet.pm
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,24 @@ use String::ShellQuote qw(shell_quote);

extends 'App::txtnix';

has text => ( is => 'rw' );
has text => ( is => 'rw' );
has created_at => ( is => 'rw' );

sub run {
my ($self) = @_;
my $text = $self->text;
$text = b($text)->decode;
$text =~ s/\@(\w+)/$self->expand_mention($1)/ge;
my $tweet = App::txtnix::Tweet->new( text => $text );

if ( $self->created_at ) {
$self->to_epoch( $self->created_at );
}
else {
$self->created_at(time);
}

my $tweet =
App::txtnix::Tweet->new( text => $text, timestamp => $self->created_at );
my $file = path( $self->twtfile );
$file->touch unless $file->exists;

Expand Down
6 changes: 6 additions & 0 deletions t/run.t
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@ use Mojolicious::Lite;
use Mojo::UserAgent::Server;
use OptArgs 'class_optargs';

$ENV{TZ} = 'UTC';

my $config = Path::Tiny->tempfile;
my $twtfile = Path::Tiny->tempfile;

Expand Down Expand Up @@ -36,6 +38,10 @@ EOO
run( 'tweet', 'Hello World' );
like( $twtfile->slurp_utf8, qr/[\d:TZ-]+\tHello World/ );

$twtfile->spew('');
run( 'tweet', '--created-at', '2016-02-03T00:00:00Z', 'Hello World' );
is( $twtfile->slurp_utf8, "2016-02-03T00:00:00+0000\tHello World\n" );

stdout_is(
sub { run( 'follow', 'bob', '/bob.txt' ) },
qq{You're already following bob.\n}
Expand Down

0 comments on commit 59cf675

Please sign in to comment.