Amazon-SQS-Client

 view release on metacpan or  search on metacpan

lib/Amazon/SQS/Client.pm  view on Meta::CPAN

package Amazon::SQS::Credentials;

use strict;
use warnings;

# faux Credentials class - just provides getters

__PACKAGE__->follow_best_practice();
__PACKAGE__->mk_accessors(qw(aws_access_key_id aws_secret_access_key token loglevel));

use parent qw(Class::Accessor::Fast);

our $VERSION = '2.0.7';

########################################################################
sub new {
########################################################################
  my ( $class, @args ) = @_;

  my $client_options;

  if ( @args > 2 ) {
    if ( ref $args[2] ) {
      $client_options = $args[2];
    }
    else {
      $client_options = $args[3] // {};
      $client_options->{SecurityToken} = $args[2];
    }
  }

  return $class->SUPER::new(
    { aws_access_key_id     => $args[0],
      aws_secret_access_key => $args[1],
      $client_options->{SecurityToken} ? ( token    => $client_options->{SecurityToken} ) : (),
      $client_options->{loglevel}      ? ( loglevel => $client_options->{loglevel} )      : (),
    }
  );
}

################################################################################
#  Copyright 2008 Amazon Technologies, Inc.
#  Licensed under the Apache License, Version 2.0 (the "License");
#
#  You may not use this file except in compliance with the License.
#  You may obtain a copy of the License at: http://aws.amazon.com/apache2.0
#  This file is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR
#  CONDITIONS OF ANY KIND, either express or implied. See the License for the
#  specific language governing permissions and limitations under the License.
#
#  Copyright 2024 Robert C. Lauer
#
#  Note: The software contained in this distribution has been modified from the
#  original. You may freely use and distribute this software under the
#  terms of the original license.

package Amazon::SQS::Client;

use strict;
use warnings;

use Amazon::Credentials;
use Amazon::SQS::Constants qw(:all);
use Amazon::SQS::Exception;
use Carp qw(croak);
use Data::Dumper;
use Digest::SHA qw (hmac_sha1_base64 hmac_sha256_base64);
use English qw(-no_match_vars);
use LWP::UserAgent;
use Scalar::Util qw(reftype);
use Time::HiRes qw(usleep);
use URI::Escape;
use URI;
use XML::Simple;

__PACKAGE__->follow_best_practice();
__PACKAGE__->mk_accessors(
  qw(
    ServiceURL
    UserAgent
    SignatureVersion
    SignatureMethod
    MaxErrorRetry
    ServiceVersion
    SecurityToken
    Region
    v4_signer
    credentials
    last_request
    last_response
  )
);

use parent qw(Class::Accessor::Fast);

our $VERSION = '@PACKAGE_VERSION';

########################################################################
sub new {
########################################################################
  my ( $class, @args ) = @_;

  my $options;

  if ( ref $args[0] ) {
    $options = $args[0];
  }
  elsif ( $args[0] && $args[1] ) {
    my $credentials = Amazon::SQS::Credentials->new(@args);

    $options = { credentials => $credentials };

    if ( ref $args[2] ) {
      $options = { %{$options}, %{ $args[2] } };
    }
  }
  else {
    $options = ref $args[2] ? $args[2] : {};
    $options->{credentials} //= Amazon::Credentials->new();
  }

  set_defaults($options);

  my $self = $class->SUPER::new($options);

  $self->init_v4_signer;

  return $self;
}

########################################################################
sub set_defaults {
########################################################################
  my ($options) = @_;

  $options->{SignatureVersion} //= 2;



( run in 1.468 second using v1.01-cache-2.11-cpan-39bf76dae61 )