From c9ac55a2a507fbf738e169d7b37a13aeba89fa2c Mon Sep 17 00:00:00 2001 From: Brock Wilcox Date: Thu, 2 Oct 2014 17:39:52 -0400 Subject: use hipchat v2 api via WebService::HipChat --- scripts/hipchat_complete.pl | 20 +++++++------------- 1 file changed, 7 insertions(+), 13 deletions(-) (limited to 'scripts/hipchat_complete.pl') diff --git a/scripts/hipchat_complete.pl b/scripts/hipchat_complete.pl index 094b9a6..54a3c52 100644 --- a/scripts/hipchat_complete.pl +++ b/scripts/hipchat_complete.pl @@ -1,4 +1,5 @@ # hipchat_complete.pl - (c) 2013 John Morrissey +# (c) 2014 Brock Wilcox # # Redistribution and use in source and binary forms, with or without # modification, are permitted provided that the following conditions are @@ -46,11 +47,11 @@ # To use # ====== # -# 1. Install the HTTP::Message, JSON, and LWP Perl modules. +# 1. Install the WebService::HipChat module from CPAN. # # 2. /script load hipchat_completion.pl # -# 3. Get a Hipchat auth token (hipchat.com -> Account settings -> API +# 3. Get a Hipchat auth v2 token (hipchat.com -> Account settings -> API # access). In irssi: # # /set hipchat_auth_token some-hex-value @@ -63,12 +64,10 @@ use strict; -use HTTP::Request; use Irssi; -use JSON; -use LWP::UserAgent; +use WebService::HipChat; -my $VERSION = '1.0'; +my $VERSION = '2.0'; my %IRSSI = ( authors => 'John Morrissey', contact => 'jwm@horde.net', @@ -81,18 +80,13 @@ my %NICK_TO_MENTION; my $LAST_MAP_UPDATED = 0; sub get_hipchat_people { - my $ua = LWP::UserAgent->new; - $ua->timeout(5); - my $auth_token = Irssi::settings_get_str('hipchat_auth_token'); if (!$auth_token) { return; } - my $r = HTTP::Request->new('GET', - "https://api.hipchat.com/v1/users/list?auth_token=$auth_token"); - my $response = $ua->request($r); + my $hc = WebService::HipChat->new(auth_token => $auth_token); - my $hipchat_users = from_json($response->decoded_content)->{users}; + my $hipchat_users = $hc->get_users->{items}; foreach my $user (@{$hipchat_users}) { my $name = $user->{name}; $name =~ s/[^A-Za-z]//g; -- cgit v1.2.3