<commit_before>## ----------------------------------------------------------------------------

package Amazon::AwsSum::SimpleDB;

use strict;
use warnings;
use Carp;

use base qw(Amazon::AwsSum::Service);

use URI::Escape;
use DateTime;

sub service_version { '2007-11-07' }
sub decode_xml { 1 }
sub method { 'GET' }
sub expect { 200 }

## ----------------------------------------------------------------------------
# constants

my $allowed = {
    AttributeNames => {
        All => 1,
        ApproximateNumberOfMessages => 1,
        VisibilityTimeout => 1,
    },
    setable_AttributeNames => {
        VisibilityTimeout => 1,
    },
};

## ----------------------------------------------------------------------------
# commands

sub CreateDomain {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to create' );
    }

    $self->action('CreateDomain');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    return $self->send();
}

sub ListDomains {
    my ($self, $params) = @_;
    $self->reset();

    $self->action('ListDomains');
    $self->add_param_value( 'MaxNumberOfDomains', $params->{MaxNumberOfDomains} );
    $self->add_param_value( 'NextToken', $params->{NextToken} );
    return $self->send();
}

sub DeleteDomain {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a key name to delete' );
    }

    $self->action('DeleteDomain');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    return $self->send();
}

sub PutAttributes {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to put the attributes into' );
    }

    unless ( defined $params->{ItemName} ) {
        croak( 'provide an item name' );
    }

    $self->action('PutAttributes');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    $self->add_param_value( 'ItemName', $params->{ItemName} );
    if ( defined $params->{AttributePair} ) {
        $self->add_attributes( $params->{AttributePair});
    }
    else {
        $self->add_numeral_tuples( 'Attribute', 'Name', $params->{AttributeName} );
        $self->add_numeral_tuples( 'Attribute', 'Value', $params->{AttributeValue} );
        $self->add_numeral_tuples( 'Attribute', 'Replace', $params->{AttributeReplace} );
    }

    return $self->send();
}

sub GetAttributes {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to query' );
    }

    unless ( defined $params->{ItemName} ) {
        croak( 'provide an item name to retrieve' );
    }
<commit_msg>Add the ability to do BatchPutAttributes<commit_after>## ----------------------------------------------------------------------------

package Amazon::AwsSum::SimpleDB;

use strict;
use warnings;
use Carp;

use base qw(Amazon::AwsSum::Service);

use URI::Escape;
use DateTime;

sub service_version { '2007-11-07' }
sub decode_xml { 1 }
sub method { 'GET' }
sub expect { 200 }

## ----------------------------------------------------------------------------
# constants

my $allowed = {
    AttributeNames => {
        All => 1,
        ApproximateNumberOfMessages => 1,
        VisibilityTimeout => 1,
    },
    setable_AttributeNames => {
        VisibilityTimeout => 1,
    },
};

## ----------------------------------------------------------------------------
# commands

sub CreateDomain {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to create' );
    }

    $self->action('CreateDomain');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    return $self->send();
}

sub ListDomains {
    my ($self, $params) = @_;
    $self->reset();

    $self->action('ListDomains');
    $self->add_param_value( 'MaxNumberOfDomains', $params->{MaxNumberOfDomains} );
    $self->add_param_value( 'NextToken', $params->{NextToken} );
    return $self->send();
}

sub DeleteDomain {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a key name to delete' );
    }

    $self->action('DeleteDomain');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    return $self->send();
}

sub PutAttributes {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to put the attributes into' );
    }

    unless ( defined $params->{ItemName} ) {
        croak( 'provide an item name' );
    }

    $self->action('PutAttributes');
    $self->add_param_value( 'DomainName', $params->{DomainName} );
    $self->add_param_value( 'ItemName', $params->{ItemName} );
    if ( defined $params->{AttributePair} ) {
        $self->add_attributes( $params->{AttributePair});
    }
    else {
        $self->add_numeral_tuples( 'Attribute', 'Name', $params->{AttributeName} );
        $self->add_numeral_tuples( 'Attribute', 'Value', $params->{AttributeValue} );
        $self->add_numeral_tuples( 'Attribute', 'Replace', $params->{AttributeReplace} );
    }

    return $self->send();
}

sub BatchPutAttributes {
    my ($self, $domain_name, @items) = @_;

    unless ( @items ) {
        croak( 'provide at least one set of params to put' );
    }

    # firstly, check that all the DomainNames are the same
    foreach my $item ( @items ) {
        if ( $item->{DomainName} ne $domain_name ) {
            croak( 'not all of these items are meant for the same domain' );
        }
    }

    # then check that they all have an item name
    foreach my $item ( @items ) {
        croak( 'provide an item name' )
            unless defined $item->{ItemName};
    }

    $self->action('BatchPutAttributes');
    $self->add_param_value( 'DomainName', $domain_name );

    # okay, loop through the @items
    my $y = 1;
    foreach my $item ( @items ) {
        # firstly, add the item name
        $self->add_param_value( "Item.$y.ItemName", $item->{ItemName} );

        # now add the params for this item
        my $x = 1;
        foreach my $k ( keys %$item ) {
            # skip the control keys
            next if $k =~ m{ \A [A-Z] }xms;

            # add all the params in
            if ( ref $item->{$k} eq 'ARRAY' ) {
                foreach my $v ( @{$item->{$k}} ) {
                    $self->add_param_value( "Item.$y.Attribute.$x.Name", $k);
                    $self->add_param_value( "Item.$y.Attribute.$x.Value", $v);
                    $x++;
                }
            }
            else {
                $self->add_param_value( "Item.$y.Attribute.$x.Name", $k);
                $self->add_param_value( "Item.$y.Attribute.$x.Value", $item->{$k});
            }
            $x++;
        }
        $y++;
    }
    return $self->send();
}

sub GetAttributes {
    my ($self, $params) = @_;
    $self->reset();

    unless ( defined $params->{DomainName} ) {
        croak( 'provide a domain name to query' );
    }

    unless ( defined $params->{ItemName} ) {
        croak( 'provide an item name to retrieve' );
    }

{'fraction_non_alphanumeric': 0.21958253227135402, 'fraction_numerical': 0.004669046965119473, 'mean_word_length': 2.0899448451421296, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 109, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 2}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3718749', 'n_tokens_mistral': 2279, 'n_tokens_neox': 2187, 'n_words': 517}