File Coverage

blib/lib/WWW/VastAI/API/Endpoints.pm
Criterion Covered Total %
statement 37 37 100.0
branch 8 16 50.0
condition 1 7 14.2
subroutine 10 10 100.0
pod 5 5 100.0
total 61 75 81.3


line stmt bran cond sub pod time code
1             package WWW::VastAI::API::Endpoints;
2             our $VERSION = '0.001';
3             # ABSTRACT: Serverless endpoint management for Vast.ai
4              
5 10     10   86 use Moo;
  10         28  
  10         79  
6 10     10   4614 use Carp qw(croak);
  10         24  
  10         995  
7 10     10   5926 use WWW::VastAI::Endpoint;
  10         61  
  10         400  
8 10     10   70 use namespace::clean;
  10         15  
  10         61  
9              
10             has client => (
11             is => 'ro',
12             required => 1,
13             weak_ref => 1,
14             );
15              
16             sub _wrap {
17 2     2   33 my ($self, $data) = @_;
18 2         65 return WWW::VastAI::Endpoint->new(
19             client => $self->client,
20             data => $data,
21             );
22             }
23              
24             sub list {
25 1     1 1 1736 my ($self) = @_;
26 1         12 my $result = $self->client->request_op('listEndpoints');
27 1 50 0     9 my $endpoints = ref $result eq 'HASH' ? ($result->{endpoints} || $result->{results} || []) : ($result || []);
      0        
28 1         3 return [ map { $self->_wrap($_) } @{$endpoints} ];
  1         4  
  1         3  
29             }
30              
31             sub create {
32 1     1 1 18 my ($self, %params) = @_;
33 1 50       6 croak "endpoint_name required" unless $params{endpoint_name};
34 1 50       4 croak "min_load required" unless exists $params{min_load};
35 1 50       7 croak "target_util required" unless exists $params{target_util};
36              
37 1         8 my $result = $self->client->request_op('createEndpoint', body => \%params);
38 1 50 33     12 my $endpoint = ref $result eq 'HASH' ? ($result->{endpoint} || $result) : $result;
39 1         5 return $self->_wrap($endpoint);
40             }
41              
42             sub delete {
43 1     1 1 4 my ($self, $id) = @_;
44 1 50       5 croak "endpoint id required" unless defined $id;
45 1         9 return $self->client->request_op('deleteEndpoint', path => { id => $id });
46             }
47              
48             sub logs {
49 1     1 1 5 my ($self, $endpoint_name, %params) = @_;
50 1 50       5 croak "endpoint_name required" unless $endpoint_name;
51 1         5 my %body = ( endpoint_name => $endpoint_name, %params );
52 1         7 return $self->client->request_op('getEndpointLogs', body => \%body);
53             }
54              
55             sub workers {
56 1     1 1 4 my ($self, $endpoint_id) = @_;
57 1 50       5 croak "endpoint id required" unless defined $endpoint_id;
58 1         10 return $self->client->request_op('getEndpointWorkers', body => { endpoint_id => $endpoint_id });
59             }
60              
61             1;
62              
63             __END__