Skip to content

Commit

Permalink
Update for OAuth and the new Twitter API
Browse files Browse the repository at this point in the history
  • Loading branch information
avar committed Dec 19, 2012
1 parent 66e1f3f commit 3188b94
Showing 1 changed file with 37 additions and 10 deletions.
47 changes: 37 additions & 10 deletions lib/Bot/Twatterhose.pm
Expand Up @@ -6,7 +6,7 @@ use Any::Moose 'X::Getopt';
use Any::Moose 'X::Types::'.any_moose() => [qw/Int Str Bool HashRef/];
use JSON;
use Hailo;
use Net::Twitter::Lite;
use Net::Twitter;
use Scalar::Util qw(blessed);
use namespace::clean -except => 'meta';

Expand Down Expand Up @@ -36,6 +36,34 @@ has password => (
documentation => "Your Twitter password",
);

has consumer_key => (
traits => [ qw/ Getopt / ],
isa => Str,
is => 'ro',
documentation => "Your Twitter user OAuth consumer key",
);

has consumer_secret => (
traits => [ qw/ Getopt / ],
isa => Str,
is => 'ro',
documentation => "Your Twitter user OAuth consumer secret",
);

has access_token => (
traits => [ qw/ Getopt / ],
isa => Str,
is => 'ro',
documentation => "Your Twitter user OAuth access token",
);

has access_token_secret => (
traits => [ qw/ Getopt / ],
isa => Str,
is => 'ro',
documentation => "Your Twitter user OAuth secret access token",
);

has brain => (
traits => [ qw/ Getopt / ],
isa => Str,
Expand All @@ -55,7 +83,7 @@ has limit => (

has _twatter => (
traits => [ qw/ NoGetopt / ],
isa => 'Net::Twitter::Lite',
isa => 'Net::Twitter',
is => 'ro',
documentation => "Net::Twatter::Lite instance",
lazy_build => 1,
Expand All @@ -64,13 +92,12 @@ has _twatter => (
sub _build__twatter {
my ($self) = @_;

my $twatter = Net::Twitter::Lite->new(
username => $self->username,
password => $self->password,
source => 'twatterhose',
traits => ['API::REST'],
clientname => 'Twatterhose twatterbot',
clienturl => 'http://github.com/avar/bot-twatterhose',
my $twatter = Net::Twitter->new(
traits => [qw/OAuth API::REST/],
consumer_key => $self->consumer_key,
consumer_secret => $self->consumer_secret,
access_token => $self->access_token,
access_token_secret => $self->access_token_secret,
);

return $twatter;
Expand Down Expand Up @@ -134,7 +161,7 @@ sub twatterhose {
my ($self, $callback) = @_;

my ($username, $password) = map { $self->$_ } qw(username password);
my $cmd = "curl -s http://stream.twitter.com/1/statuses/sample.json -u${username}:${password}";
my $cmd = "curl -s https://stream.twitter.com/1.1/statuses/sample.json -u${username}:'${password}'";
open my $twitter, "$cmd |";

my $data = {};
Expand Down

0 comments on commit 3188b94

Please sign in to comment.