-
Notifications
You must be signed in to change notification settings - Fork 13
/
Block.pm
44 lines (36 loc) · 1.05 KB
/
Block.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
#!/usr/bin/perl
# Block.pm
# ------------
#
# Implements block operations on the OSM API
#
# Part of the "osmtools" suite of programs
# Originally written by Frederik Ramm <[email protected]>; public domain
package Block;
use strict;
use warnings;
use OsmApi;
use URI::Escape;
# -----------------------------------------------------------------------------
# Creates new block.
# Parameters: User name, reason for block, duration in hours, and 1/0 for "needs to log in"
# Returns: block id, or undef
sub create
{
my ($user, $reason, $duration, $needsview) = @_;
my $resp = OsmApi::post_web("user_blocks",
"display_name=".uri_escape_utf8($user).
"&user_block[reason]=".uri_escape_utf8($reason).
"&user_block_period=".uri_escape($duration).
"&user_block[needs_view]=".sprintf("%d", $needsview));
if ($resp->content() =~ m!<div class="message">([^<]+)</div>!)
{
print "$1\n";
}
if ($resp->content() =~ m!<li><a href="/user_blocks/(\d+)/edit">!)
{
return $1;
}
return undef;
}
1;