Commit 9f2f97b86fc7548c232a907b2ce82720553fff30

Authored by Caesar Ahlenhed
1 parent 3c6cf22b

Fixes for new API

Showing 1 changed file with 9 additions and 10 deletions   Show diff stats
boxcarirssi.pl
... ... @@ -50,30 +50,29 @@ $VERSION = "0.2";
50 50 description => "Sends notifcations when away",
51 51 license => "GPLv2",
52 52 url => "http://sniker.codebase.nu",
53   - changed => "Sat Jun 23 18:06:26 CESTT 2014",
  53 + changed => "Sat Jun 23 18:06:26 CEST 2014",
54 54 );
55 55  
56 56 # Configuration settings and default values.
57   -Irssi::settings_add_str("boxcarirssi", "boxcarirssi_email", "");
58   -Irssi::settings_add_str("boxcarirssi", "boxcarirssi_password", "");
  57 +Irssi::settings_add_str("boxcarirssi", "boxcarirssi_token", "");
59 58 Irssi::settings_add_bool("boxcarirssi", "boxcarirssi_general_hilight", 0);
60 59 Irssi::settings_add_str("boxcarirssi", "boxcarirssi_ignore_nettag", "");
61 60  
62 61 sub send_noti {
63   - my ($text) = @_;
  62 + my ($eventtype, $text) = @_;
64 63  
65 64 my %options = ();
66 65  
67 66 $options{'application'} ||= "Irssi";
68 67 $options{'notification'} = $text;
  68 + $options{'eventtype'} = $eventtype;
69 69  
70 70 my ($userAgent, $req, $response);
71 71 $userAgent = LWP::UserAgent->new;
72 72 $userAgent->agent("BoxcarIrssi/0.2");
73 73  
74   - $req = HTTP::Request->new(POST => "https://boxcar.io/notifications");
75   - $req->content("notification[from_screen_name]=" . $options{'application'} . "&notification[message]=" . $options{'notification'});
76   - $req->authorization_basic(Irssi::settings_get_str("boxcarirssi_email") => Irssi::settings_get_str("boxcarirssi_password"));
  74 + $req = HTTP::Request->new(POST => "https://new.boxcar.io/api/notifications");
  75 + $req->content("user_credentials=". Irssi::settings_get_str("boxcarirssi_token") . "&notification[source_name]=" . $options{'application'} . "&notification[long_message]=" . $options{'notification'} . "&notification[title]=" . $options{'eventtype'});
77 76  
78 77 $response = $userAgent->request($req);
79 78  
... ... @@ -88,7 +87,7 @@ sub pubmsg {
88 87 my ($server, $data, $nick, $nick_addr, $target) = @_;
89 88 if(!Irssi::settings_get_bool("boxcarirssi_general_hilight")){
90 89 if($server->{usermode_away} == 1 && $data =~ /$server->{nick}/i && index(Irssi::settings_get_str("boxcarirssi_ignore_nettag"), $server->{tag}) == -1){
91   - send_noti("Hilighted " . $server->{tag} . "/" . $target ." - " . $nick . ': ' . $data);
  90 + send_noti("Hilighted " . $server->{tag} . "/" . $target, $nick . ': ' . $data);
92 91 }
93 92 }
94 93 }
... ... @@ -96,7 +95,7 @@ sub pubmsg {
96 95 sub privmsg {
97 96 my ($server, $data, $nick) = @_;
98 97 if($server->{usermode_away} == 1 && index(Irssi::settings_get_str("boxcarirssi_ignore_nettag"), $server->{tag}) == -1){
99   - send_noti("PM @ " . $server->{tag} . " - " . $nick . ': ' . $data);
  98 + send_noti("PM @ " . $server->{tag}, $nick . ': ' . $data);
100 99 }
101 100 }
102 101  
... ... @@ -107,7 +106,7 @@ sub genhilight {
107 106 if($dest->{level} & MSGLEVEL_HILIGHT) {
108 107 if($server->{usermode_away} == 1 && index(Irssi::settings_get_str("boxcarirssi_ignore_nettag"), $server->{tag}) == -1){
109 108 if(Irssi::settings_get_bool("boxcarirssi_general_hilight")){
110   - send_noti("General Hilight " . $server->{tag} . "/" . $dest->{target} ." - " . $stripped);
  109 + send_noti("General Hilight " . $server->{tag} . "/" . $dest->{target}, $stripped);
111 110 }
112 111 }
113 112 }
... ...