[2810] in BarnOwl Developers
Re: [RFC] Download Twitter consumer keys from barnowl.mit.edu
daemon@ATHENA.MIT.EDU (David A Benjamin)
Fri Nov 26 04:26:10 2010
Date: Fri, 26 Nov 2010 04:26:06 -0500 (EST)
From: David A Benjamin <davidben@MIT.EDU>
To: Nelson Elhage <nelhage@mit.edu>
cc: barnowl-dev@mit.edu
In-Reply-To: <1289136632-12151-1-git-send-email-nelhage@mit.edu>
LGTM. I'll go ahead and commit it since you're on vacation right now. (And
if I'm sufficiently pantsful maybe I'll get an RC out this weekend.
Finally.)
David
On Sun, 7 Nov 2010, Nelson Elhage wrote:
> ---
> .../Twitter/lib/BarnOwl/Module/Twitter/Handle.pm | 26 ++++++++++++++++---
> 1 files changed, 22 insertions(+), 4 deletions(-)
>
> diff --git a/perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm b/perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm
> index 353f857..fc2ee95 100644
> --- a/perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm
> +++ b/perl/modules/Twitter/lib/BarnOwl/Module/Twitter/Handle.pm
> @@ -30,8 +30,23 @@ use BarnOwl;
> use BarnOwl::Message::Twitter;
> use POSIX qw(asctime);
>
> -use constant BARNOWL_CONSUMER_KEY => "9Py27vCQl6uB5V7ijmp31A";
> -use constant BARNOWL_CONSUMER_SECRET => "GLhheSim8P5cVuk9FTM99KTEgWLW0LGl7gf54QWfg";
> +use LWP::UserAgent;
> +use URI;
> +use JSON;
> +
> +use constant CONSUMER_KEY_URI => 'http://barnowl.mit.edu/twitter-keys';
> +our $oauth_keys;
> +
> +{
> + my $ua = LWP::UserAgent->new;
> + $ua->timeout(5);
> + my $response = $ua->get(CONSUMER_KEY_URI);
> + if ($response->is_success) {
> + $oauth_keys = eval { from_json($response->decoded_content) };
> + } else {
> + warn "[Twitter] Unable to download OAuth keys: $response->status_line\n";
> + }
> +}
>
> sub fail {
> my $self = shift;
> @@ -57,6 +72,9 @@ sub new {
> $cfg->{show_mentions} = $val;
> }
>
> +
> + my $keys = $oauth_keys->{URI->new($cfg->{service})->canonical} || {};
> +
> $cfg = {
> account_nickname => '',
> default => 0,
> @@ -64,8 +82,8 @@ sub new {
> poll_for_dms => 1,
> publish_tweets => 0,
> show_mentions => 1,
> - oauth_key => BARNOWL_CONSUMER_KEY,
> - oauth_secret => BARNOWL_CONSUMER_SECRET,
> + oauth_key => $keys->{oauth_key},
> + oauth_secret => $keys->{oauth_secret},
> %$cfg,
> };
>
> --
> 1.7.1.31.g6297e
>
>