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

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

add more m to openstreetap

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