-
Notifications
You must be signed in to change notification settings - Fork 13
/
Note.pm
101 lines (84 loc) · 2.02 KB
/
Note.pm
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
#!/usr/bin/perl
# Note.pm
# -------
#
# Implements note operations on the OSM API
#
# Part of the "osmtools" suite of programs
# Originally written by Frederik Ramm <[email protected]>; public domain
package Note;
use strict;
use warnings;
use OsmApi;
use URI::Escape;
# -----------------------------------------------------------------------------
# Hides the given note.
# Parameters: Note ID
# Returns: 1, or undef in case of error (will write error to stderr)
# (this API call requires moderator privilege)
sub hide
{
my ($id) = @_;
my $resp = OsmApi::delete("notes/$id", undef, 1);
if (!$resp->is_success)
{
print STDERR "cannot hide note: ".$resp->status_line."\n";
return undef;
}
return 1;
}
# -----------------------------------------------------------------------------
# Reopens the given note.
# Parameters: Note ID, comment text
# Returns: 1, or undef in case of error (will write error to stderr)
sub reopen
{
my ($id, $text) = @_;
return post("reopen", $id, $text);
}
sub close
{
my ($id, $text) = @_;
return post("close", $id, $text);
}
sub comment
{
my ($id, $text) = @_;
return post("comment", $id, $text);
}
sub post
{
my ($endpoint, $id, $text) = @_;
my $body;
$body = "text=".uri_escape($text) if defined($text);
my $resp = OsmApi::post("notes/$id/$endpoint", $body, 1);
if (!$resp->is_success)
{
print STDERR "cannot $endpoint note: ".$resp->status_line."\n";
return undef;
}
return 1;
}
sub get
{
my ($id) = @_;
my $resp = OsmApi::get("notes/$id", undef, 1);
if (!$resp->is_success)
{
print STDERR "cannot load note: ".$resp->status_line."\n";
return undef;
}
return $resp->content;
}
sub create
{
my ($lat, $lon, $text) = @_;
my $resp = OsmApi::post("notes", "lat=$lat&lon=$lon&text=".uri_escape($text));
if (!$resp->is_success)
{
print STDERR "cannot create note: ".$resp->status_line."\n";
return undef;
}
return $resp->content;
}
1;