Changeset 1eafdfa


Ignore:
Timestamp:
May 22, 2010, 6:59:05 PM (10 years ago)
Author:
Nelson Elhage <nelhage@ksplice.com>
Branches:
master, release-1.7, release-1.8, release-1.9
Children:
63d9de9
Parents:
05cfc78
Message:
Implement support for authorization via xAuth
File:
1 edited

Legend:

Unmodified
Added
Removed
  • lib/BarnOwl/Module/Twitter/Handle.pm

    r538a5f7 r1eafdfa  
    3030use BarnOwl::Message::Twitter;
    3131use POSIX qw(asctime);
     32
     33use constant BARNOWL_CONSUMER_KEY    => "9Py27vCQl6uB5V7ijmp31A";
     34use constant BARNOWL_CONSUMER_SECRET => "GLhheSim8P5cVuk9FTM99KTEgWLW0LGl7gf54QWfg";
    3235
    3336sub fail {
     
    7881    my %twitter_args = @_;
    7982
    80     $self->{twitter}  = Net::Twitter::Lite->new(%twitter_args);
     83    my ($username, $password, $xauth);
     84
     85    if (*Net::Twitter::Lite::xauth{CODE}) {
     86        $xauth = 1;
     87        $username = delete $twitter_args{username};
     88        $password = delete $twitter_args{password};
     89        $twitter_args{consumer_key}    = BARNOWL_CONSUMER_KEY;
     90        $twitter_args{consumer_secret} = BARNOWL_CONSUMER_SECRET;
     91    } else {
     92        BarnOwl::error("Please upgrade your version of Net::Twitter::Lite to support xAuth.");
     93    }
     94
     95    $self->{twitter}  = Net::Twitter::Lite->new(%twitter_args,);
     96
     97    if ($xauth){
     98        eval {
     99            $self->{twitter}->xauth($username, $password);
     100        };
     101        if($@) {
     102            $self->fail("Invalid credentials: $@");
     103        }
     104    }
    81105
    82106    my $timeline = eval { $self->{twitter}->home_timeline({count => 1}) };
    83107    warn "$@\n" if $@;
    84108
    85     if(!defined($timeline)) {
     109    if(!defined($timeline) && !$xauth) {
    86110        $self->fail("Invalid credentials");
    87111    }
Note: See TracChangeset for help on using the changeset viewer.