source: subversion/applications/editors/potlatch/potlatchtweet.cgi @ 18703

Last change on this file since 18703 was 18703, checked in by avar, 10 years ago

Return Net::Twitter errors to Potlatch so it can show meaningful error messages

File size: 1.7 KB
Line 
1#!/usr/bin/perl
2use strict;
3use Net::Twitter;
4use CGI;
5use URI;
6
7my $query = CGI->new;
8my $res = URI->new;
9
10my $success = 0;
11my $errcode = 0;
12my $errmsg = '';
13my $errerr = '';
14my $submitted = 0;
15
16if ($query->param('tweet') and
17    $query->param('lat') and
18    $query->param('long') and
19    $query->param('twitter_id') and
20    $query->param('twitter_pwd') and
21    $query->param('clientver')) {
22    $submitted = 1;
23
24    my $app = 'Potlatch';
25    my $ver = $query->param('clientver');
26    my $ua = "$app/$ver";
27
28    my $twat = Net::Twitter->new(
29        traits => ['API::REST'],
30        username => $query->param('twitter_id'),
31        password => $query->param('twitter_pwd'),
32        useragent  => $ua,
33        clientname => $app,
34        clientver  => $ver,
35        clienturl  => 'http://openstreetap.org/edit',
36
37        # identi.ca or twitter?
38        ($query->param('identica')
39         ? (identica => 1)
40         : ()),
41
42        # identica takes this as-is, twitter says "from web" because
43        # it isn't registering source paramaters anymore, we'd have to
44        # use OAuth to play nice with it.
45        source => $app,
46    );
47
48    eval {
49        $twat->update({
50            status => $query->param('tweet'),
51            lat => $query->param('lat'),
52            long => $query->param('long')
53        });
54    };
55    if (my $err = $@) {
56        $errcode = $err->code;
57        $errmsg  = $err->message;
58        $errerr  = $err->error;
59    } else {
60        $success = 1;
61    }
62}
63
64$res->query_form(
65    success => $success,
66    errcode => $errcode,
67    errmsg  => $errmsg,
68    errerr  => $errerr,
69    submit  => $submitted,
70);
71
72my $q = $res->as_string;
73$q =~ s/^\?//;
74
75        print <<EOF;
76Content-Type: application/x-www-form-urlencoded
77
78&$q&
79EOF
80
Note: See TracBrowser for help on using the repository browser.