Changeset 7430aa4 for lib/BarnOwl/Module/Twitter
- Timestamp:
- Jul 21, 2009, 9:46:50 PM (15 years ago)
- Branches:
- master, release-1.10, release-1.7, release-1.8, release-1.9
- Children:
- d748296
- Parents:
- 159aaad
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
lib/BarnOwl/Module/Twitter/Handle.pm
r159aaad r7430aa4 19 19 use BarnOwl; 20 20 use BarnOwl::Message::Twitter; 21 21 22 sub fail { 22 23 my $self = shift; 23 24 my $msg = shift; 24 25 undef $self->{twitter}; 25 BarnOwl::admin_message('Twitter Error', $msg);26 die(" TwitterError: $msg\n");26 my $nickname = $self->{cfg}->{account_nickname} || ""; 27 die("[Twitter $nickname] Error: $msg\n"); 27 28 } 28 29 … … 37 38 my $cfg = shift; 38 39 39 my %obj = (40 my $self = { 40 41 'user' => undef, 41 42 'cfg' => $cfg, … … 45 46 'last_id' => undef, 46 47 'last_direct' => undef, 47 ); 48 }; 49 50 bless($self, $class); 48 51 49 52 my %twitter_args = @_; 50 53 51 $ obj{twitter} = Net::Twitter->new(%twitter_args);52 53 if(!defined($ obj{twitter}->verify_credentials())) {54 fail("Invalid twittercredentials");55 } 56 57 unless(defined($ obj{last_id})) {54 $self->{twitter} = Net::Twitter->new(%twitter_args); 55 56 if(!defined($self->{twitter}->verify_credentials())) { 57 $self->fail("Invalid credentials"); 58 } 59 60 unless(defined($self->{last_id})) { 58 61 eval { 59 $ obj{last_id} = $obj{twitter}->friends_timeline({count => 1})->[0]{id};62 $self->{last_id} = $self->{twitter}->friends_timeline({count => 1})->[0]{id}; 60 63 }; 61 $ obj{last_id} = 0 unless defined($obj{last_id});62 } 63 64 unless(defined($ obj{last_direct})) {64 $self->{last_id} = 0 unless defined($self->{last_id}); 65 } 66 67 unless(defined($self->{last_direct})) { 65 68 eval { 66 $ obj{last_direct} = $obj{twitter}->direct_messages()->[0]{id};69 $self->{last_direct} = $self->{twitter}->direct_messages()->[0]{id}; 67 70 }; 68 $ obj{last_direct} = 0 unless defined($obj{last_direct});71 $self->{last_direct} = 0 unless defined($self->{last_direct}); 69 72 } 70 73 71 74 eval { 72 $obj{twitter}->{ua}->timeout(1); 73 }; 74 75 return bless {%obj}, $class; 76 75 $self->{twitter}->{ua}->timeout(1); 76 }; 77 78 return $self; 77 79 } 78 80
Note: See TracChangeset
for help on using the changeset viewer.