App-SpreadRevolutionaryDate

 view release on metacpan or  search on metacpan

lib/App/SpreadRevolutionaryDate/Target/Twitter.pm  view on Meta::CPAN

#
# This file is part of App-SpreadRevolutionaryDate
#
# This software is Copyright (c) 2019-2026 by Gérald Sédrati.
#
# This is free software, licensed under:
#
#   The GNU General Public License, Version 3, June 2007
#
use 5.014;
use utf8;
package App::SpreadRevolutionaryDate::Target::Twitter;
$App::SpreadRevolutionaryDate::Target::Twitter::VERSION = '0.54';
# ABSTRACT: Target class for L<App::SpreadRevolutionaryDate> to handle spreading on Twitter.

use Moose;
with 'App::SpreadRevolutionaryDate::Target'
  => {worker => 'Twitter::API__WITH__Twitter::API::Trait::ApiMethods'};

use Twitter::API;

use Locale::TextDomain 'App-SpreadRevolutionaryDate';
use namespace::autoclean;

has 'consumer_key' => (
  is  => 'ro',
  isa => 'Str',
  required => 1,
);

has 'consumer_secret' => (
  is  => 'ro',
  isa => 'Str',
  required => 1,
);

has 'access_token' => (
  is  => 'ro',
  isa => 'Str',
  required => 1,
);

has 'access_token_secret' => (
  is  => 'ro',
  isa => 'Str',
  required => 1,
);


around BUILDARGS => sub {
  my ($orig, $class) = @_;

  my $args = $class->$orig(@_);
  my $api_1 = $args->{api} && $args->{api} eq 1 || 0;

  $args->{obj} = Twitter::API->new_with_traits(
                  traits              => 'ApiMethods',
                  $api_1 ?
                    () :
                    (api_version => '2', api_ext => ''),
                  consumer_key        => $args->{consumer_key},
                  consumer_secret     => $args->{consumer_secret},
                  access_token        => $args->{access_token},
                  access_token_secret => $args->{access_token_secret},
                  agent               => 'RevolutionaryDate');
  return $args;
};


sub spread {
  my ($self, $msg, $test) = @_;
  $test //= 0;

  # Multiline message
  $msg =~ s/\\n/\n/g;

  if ($test) {
    $msg = __("Spread on Twitter: ") . $msg;

    use open qw(:std :encoding(UTF-8));
    use IO::Handle;
    my $io = IO::Handle->new;
    $io->fdopen(fileno(STDOUT), "w");



( run in 1.524 second using v1.01-cache-2.11-cpan-0bb4e1dffa6 )