-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathduckdns.ts
More file actions
30 lines (27 loc) · 1.04 KB
/
duckdns.ts
File metadata and controls
30 lines (27 loc) · 1.04 KB
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
duckdns isa ontology ~ https://www.duckdns.org/ns/duckdns/
duckdns:update isa ts:function
isa ts:side-effect
return """
my $token = $_[0]->[0];
my $subdomain = $_[1]->[0];
# warn "token $token subdomain $subdomain";
$TM2::log->logdie( "access token not defined" ) unless defined $token;
# warn "ctx ".TM2::TempleScript::PE::ctx_dump ($ctx);
my $loop = TM2::TempleScript::PE::lookup_var( $ctx, '$loop' );
# warn "ctx $ctx loop $loop";
use Net::Async::HTTP;
my $http = Net::Async::HTTP->new();
$loop->add( $http );
my $resp = $http->GET( "https://www.duckdns.org/update?domains=$subdomain&token=$token&verbose=true" )->get;
# use Data::Dumper;
# warn Dumper $resp;
if ($resp->is_success) { # this does not mean anything
if ($resp->content =~ /^OK/) {
return [ TM2::Literal->new( $resp->content ) ];
} else { # KO, or else
$TM2::log->logdie( "duckdns:update: ".$resp->content );
}
} else {
$TM2::log->logdie( "duckdns:update: ".$resp->message );
}
""" ^^ lang:perl !