IO-Iron

 view release on metacpan or  search on metacpan

lib/IO/Iron/IronWorker/Client.pm  view on Meta::CPAN

    $log->tracef( 'Entering new(%s, %s)', $class, \%params );
    my $self = IO::Iron::ClientBase->new();

    # Add more keys to the self hash.
    my @self_keys = ( legal_keys( %{$self} ), );
    unlock_keys( %{$self} );
    lock_keys_plus( %{$self}, @self_keys );
    my $config = IO::Iron::Common::get_config(%params);
    $log->debugf( 'The config: %s', $config );
    $self->{'project_id'} = defined $config->{'project_id'} ? $config->{'project_id'} : undef;
    assert_nonblank( $self->{'project_id'}, 'self->{project_id} is not defined or is blank' );

    unlock_keys( %{$self} );
    bless $self, $class;
    lock_keys( %{$self}, @self_keys );

    # Set up the connection client
    my $connection = IO::Iron::Connection->new(
        {
            'project_id'  => $config->{'project_id'},
            'token'       => $config->{'token'},
            'host'        => defined $config->{'host'} ? $config->{'host'} : $DEFAULT_HOST,
            'protocol'    => $config->{'protocol'},
            'port'        => $config->{'port'},
            'api_version' => defined $config->{'api_version'} ? $config->{'api_version'} : $DEFAULT_API_VERSION,
            'timeout'     => $config->{'timeout'},
            'connector'   => $params{'connector'},
        }
    );
    $self->{'connection'} = $connection;
    $log->debugf(
        'IronWorker Client created with config: (project_id=%s; token=%s; host=%s; timeout=%s).',
        $config->{'project_id'},
        $config->{'token'}, $config->{'host'}, $config->{'timeout'}
    );
    $log->tracef( 'Exiting new: %s', $self );
    return $self;
}

###############################################
######## FUNCTIONS: CODE PACKAGES #############
###############################################

sub list_code_packages {
    my ($self) = @_;
    $log->tracef('Entering list_code_packages()');

    my $connection = $self->{'connection'};
    my ( $http_status_code, $response_message ) =
      $connection->perform_iron_action( IO::Iron::IronWorker::Api::IRONWORKER_LIST_CODE_PACKAGES(), {} );
    $self->{'last_http_status_code'} = $http_status_code;
    my @codes;
    foreach ( @{$response_message} ) {
        push @codes, $_;
    }
    $log->debugf( 'Returning %d code packages.', scalar @codes );
    $log->tracef( 'Exiting list_code_packages: %s', \@codes );
    return @codes;
}

sub update_code_package {
    my $self   = shift;
    my %params = validate(
        @_,
        {
            'name' => { type => SCALAR, },    # Code package name.
            'file' => {
                type     => SCALAR,
                optional => 1,                            # The zip archive as a string buffer.
                depends  => [ 'file_name', 'runtime' ],
            },
            'file_name'       => { type => SCALAR, optional => 1 },     # Name of the zip file, not
            'runtime'         => { type => SCALAR, optional => 1, },    # The runtime type, e.g. sh, perl, ruby.
            'config'          => { type => SCALAR, optional => 1, },
            'max_concurrency' => { type => SCALAR, optional => 1, },
            'retries'         => { type => SCALAR, optional => 1, },
            'retries_delay'   => { type => SCALAR, optional => 1, },
        }
    );
    $log->tracef( 'Entering update_code_package(%s)', \%params );
    my $connection = $self->{'connection'};
    my ( $http_status_code, $response_message ) = $connection->perform_iron_action(
        IO::Iron::IronWorker::Api::IRONWORKER_UPLOAD_OR_UPDATE_A_CODE_PACKAGE(),
        {
            'body' => \%params,
        }
    );
    $self->{'last_http_status_code'} = $http_status_code;
    my $id = $response_message->{'id'};
    $log->tracef( 'Exiting update_code_package: %s', $id );
    return $id;
}

sub get_info_about_code_package {
    my $self   = shift;
    my %params = validate(
        @_,
        {
            'id' => { type => SCALAR, },    # Code package id.
        }
    );
    $log->tracef( 'Entering get_info_about_code_package(%s)', \%params );
    my $connection = $self->{'connection'};
    my ( $http_status_code, $response_message ) =
      $connection->perform_iron_action( IO::Iron::IronWorker::Api::IRONWORKER_GET_INFO_ABOUT_A_CODE_PACKAGE(),
        { '{Code ID}' => $params{'id'}, } );
    $self->{'last_http_status_code'} = $http_status_code;
    my $info = $response_message;
    $log->tracef( 'Exiting get_info_about_code_package: %s', $info );
    return $info;
}

sub delete_code_package {
    my $self   = shift;
    my %params = validate(
        @_,
        {
            'id' => { type => SCALAR, },    # Code package id.
        }
    );
    $log->tracef( 'Entering delete_code_package(%s)', $params{'id'} );



( run in 0.690 second using v1.01-cache-2.11-cpan-98e64b0badf )