SYNOPSIS

use DNS::Hetzner;

my $api_key = '1234abc';
my $dns     = DNS::Hetzner->new(
    token => $api_key,
);

$dns->records->create(
);

ATTRIBUTES

  • endpoint

METHODS

%s ~, $methods_pod;

my $code = sprintf q~package DNS::Hetzner::API::%s;

# ABSTRACT: %s

# --- # This class is auto-generated by bin/get_hetzner_info.pl # ---

use v5.20;

use Moo; use Types::Standard qw(:all);

use Mojo::Base -strict, -signatures;

extends 'DNS::Hetzner';

with 'DNS::Hetzner::Utils'; with 'MooX::Singleton';

use JSON::Validator; use Carp;

has endpoint => ( is => 'ro', isa => Str, default => sub { '%s' } ); %s

1;

__END__

%s ~, $class, $class, $endpoint, $subs, $pod;

return $code;
}

sub _get_params ( $class, $method_def, $components ) { my %params; my @required; my %components;

PARAM:
for my $param ( $method_def->{parameters}->@* ) {
    next PARAM if $param->{in} eq 'query';

    my $name = $param->{name};
    $params{$name} = $param->{schema};

    if ( $param->{required} ) {
        push @required, $name;
    }
}

if ( ($method_def->{requestBody} // {} )->%* ) {
    my $sub_def = $method_def->{requestBody};
    my $type    = $sub_def->{content};
    my $name    = "";

    if ( $type->{"text/plain"} ) {
        $params{""} = { type => "string" };
    }

    if ( $type->{"application/json"} ) {
        my $component_check = $class =~ s{s\z}{}r;
        my %subcomponents = map {
            ( $_ => $components->{schemas}->{$_} );
        } grep {
            $_ =~ m{$component_check};
        } keys $components->{schemas}->%*;

        %components = ( components => \%subcomponents );
        $params{""} = $type->{"application/json"};
    }

    if ( $sub_def->{description} ) {
        $params{$name}->{description} = $sub_def->{description};
    }

    if ( $sub_def->{required} ) {
        push @required, $name;
    }
}

my %data = (
    type       => "object",
    properties => \%params,
    required   => \@required,
    %components,
);

return \%data;
}

sub _get_sub ( $method, $parts, $uri, $params ) { my $method_name = $method;

$method_name = 'create' if $method eq 'post';
$method_name = 'update' if $method eq 'put';

if ( $method eq 'get' && $uri !~ m/:/ ) {
    $method_name = 'list';
}

if ( $parts->@* && $parts->[-1] !~ m/\{/ ) {
    $method_name .= '_' . $parts->[-1];
}

my $spec = Dumper($params);
$spec    =~ s{\$VAR1 = }{};
$spec    =~ s{^}{    }xmsg;

my $sub = sprintf q~
sub %s ($self, $params = {}) {
my $spec   = %s
my $validator = JSON::Validator->new->schema($spec);

my @errors = $validator->validate(
    $params,
);

if ( @errors ) {
    croak 'invalid parameters';
}

my %%request_params = map{
    exists $params->{$_} ?
        ($_ => $params->{$_}) :
        ();
} keys %%{$spec->{properties}};

$self->request(
    '%s',
    { type => '%s' },
    \%%request_params,
);
}
~, $method_name, $spec, $uri, $method;

return ($sub, $method_name);
}

sub _get_pod ( $method, $description, $object, $params) { my $pod = sprintf q~

%s

%s

$dns->%s->%s(%s);
~,
    $method, $description, $object, $method, $params;

return $pod;
}

__END__

NAME

get_hcloud_info.pl - get API definitions from docs.hetzner.cloud

VERSION

version 0.01

AUTHOR

Renee Baecker <reneeb@cpan.org>

COPYRIGHT AND LICENSE

This software is Copyright (c) 2020 by Renee Baecker.

This is free software, licensed under:

The Artistic License 2.0 (GPL Compatible)