Ignore:
Timestamp:
Nov 26, 2010, 4:59:22 AM (14 years ago)
Author:
David Benjamin <davidben@mit.edu>
Branches:
master, release-1.10, release-1.7, release-1.8, release-1.9
Children:
2ff0693
Parents:
b31f1c9
git-author:
Nelson Elhage <nelhage@MIT.EDU> (11/07/10 08:30:32)
git-committer:
David Benjamin <davidben@mit.edu> (11/26/10 04:59:22)
Message:
Download Twitter consumer keys from barnowl.mit.edu

[davidben@mit.edu: Fetch keys lazily in case Twitter is not configured.]
Reviewed-by: Anders Kaseorg <andersk@mit.edu>
File:
1 edited

Legend:

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

    rc6adf17 r7aa1fa5  
    3131use POSIX qw(asctime);
    3232
    33 use constant BARNOWL_CONSUMER_KEY    => "9Py27vCQl6uB5V7ijmp31A";
    34 use constant BARNOWL_CONSUMER_SECRET => "GLhheSim8P5cVuk9FTM99KTEgWLW0LGl7gf54QWfg";
     33use LWP::UserAgent;
     34use URI;
     35use JSON;
     36
     37use constant CONSUMER_KEY_URI => 'http://barnowl.mit.edu/twitter-keys';
     38our $oauth_keys;
     39
     40sub fetch_keys {
     41    my $ua = LWP::UserAgent->new;
     42    $ua->timeout(5);
     43    my $response = $ua->get(CONSUMER_KEY_URI);
     44    if ($response->is_success) {
     45        $oauth_keys = eval { from_json($response->decoded_content) };
     46    } else {
     47        warn "[Twitter] Unable to download OAuth keys: $response->status_line\n";
     48    }
     49}
    3550
    3651sub fail {
     
    5772        $cfg->{show_mentions} = $val;
    5873    }
     74
     75
     76    if (!defined($oauth_keys)) {
     77        fetch_keys();
     78    }
     79    my $keys = $oauth_keys->{URI->new($cfg->{service})->canonical} || {};
    5980
    6081    $cfg = {
     
    6586        publish_tweets   => 0,
    6687        show_mentions    => 1,
    67         oauth_key        => BARNOWL_CONSUMER_KEY,
    68         oauth_secret     => BARNOWL_CONSUMER_SECRET,
     88        oauth_key        => $keys->{oauth_key},
     89        oauth_secret     => $keys->{oauth_secret},
    6990        %$cfg,
    7091       };
Note: See TracChangeset for help on using the changeset viewer.