-
Notifications
You must be signed in to change notification settings - Fork 13
/
osm_api.pl
72 lines (62 loc) · 1.75 KB
/
osm_api.pl
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
#!/usr/bin/perl
use strict;
use FindBin;
use lib "$FindBin::Bin/lib";
use OsmApi;
if (($ARGV[0] eq "curl") && (scalar(@ARGV) >= 2))
{
shift @ARGV;
my $token = OsmApi::read_existing_oauth2_token(1);
my $path = pop @ARGV;
my $url = $OsmApi::prefs->{apiurl} . $path;
exec "curl", "--oauth2-bearer", $token, @ARGV, $url;
}
if (($ARGV[0] eq "delete") && (scalar(@ARGV) == 2))
{
my $path = $ARGV[1];
OsmApi::delete($path, undef, 1);
exit;
}
if (($ARGV[0] eq "get") && (scalar(@ARGV) == 2))
{
my $path = $ARGV[1];
OsmApi::get($path, undef, 1);
exit;
}
if (($ARGV[0] eq "post") && (scalar(@ARGV) == 2))
{
my $path = $ARGV[1];
my $body = "";
while(<STDIN>) { $body .= $_; }
OsmApi::post($path, $body, 1);
exit;
}
if (($ARGV[0] eq "put") && (scalar(@ARGV) == 2))
{
my $path = $ARGV[1];
my $body = "";
while(<STDIN>) { $body .= $_; }
OsmApi::put($path, $body, 1);
exit;
}
print <<EOF;
Usage:
$0 curl <curl options> <path> run cURL with proper --oauth2-bearer and url
$0 delete <path> DELETE request
$0 get <path> GET request
$0 post <path> < input_file POST request
$0 put <path> < input_file PUT request
<path> is relative to (server)/api/0.6/
Examples:
get trace #23:
$0 get gpx/23
post a "test comment" comment for changeset #123 using cURL:
$0 curl -d "text=test comment" changeset/123/comment
upload a private trace file "filename.gpx" with description "some trace" using cURL:
$0 curl -F "description=some trace" -F file=\@filename.gpx gpx/create
Enable debug output in .osmtoolsrc to see the results, for example:
debug=1
debug_response_headers=1
debug_response_body=1
Or use cURL with its options, for example -v.
EOF