Amazon-Sites

 view release on metacpan or  search on metacpan

lib/Amazon/Sites.pm  view on Meta::CPAN

=head1 NAME

Amazon::Sites - A class to represent Amazon sites

=head1 SYNOPSIS

  use Amazon::Sites;

  my $sites = Amazon::Sites->new;
  my @sites = $sites->sites;
  my %sites = $sites->sites_hash;
  my @codes = $sites->codes;

  my $site  = $sites->site('UK');
  say $site->currency; # GBP
  say $site->tldn;     # co.uk
  # etc

  my %urls = $sites->asin_urls('XXXXXXX');
  say $urls{UK}; # https://amazon.co.uk/dp/XXXXXXX
  # etc

=head1 DESCRIPTION

A simple class that encapsulates information about Amazon sites.

=cut

use strict;
use warnings;

use Feature::Compat::Class;

use feature 'signatures';
no warnings 'experimental::signatures';

class Amazon::Sites;

our $VERSION = '0.1.10';

use Amazon::Site ();

field $include :param = [];
field $exclude :param = [];
field $assoc_codes :param = {};
field %sites = _init_sites($assoc_codes, $include, $exclude);

ADJUST {
  if (@$include and @$exclude) {
    die "You can't specify both include and exclude";
  }
}

=head1 METHODS

=head2 new

Creates a new Amazon::Sites object.

    my $sites = Amazon::Sites->new;

You can also specify a list of sites to include or exclude:

    # Only include the US site
    my $sites = Amazon::Sites->new(include => [ 'US' ]);
    # Exclude the US site
    my $sites = Amazon::Sites->new(exclude => [ 'US' ]);

At most one of `include` or `exclude` can be specified.

You can also specify a hash of associate codes:

    my $sites = Amazon::Sites->new(assoc_codes => {
      UK => 'My Associate Code',
    });

=head2 sites_hash

Returns a hash where the keys are the two-letter country codes and the values are
L<Amazon::Site> objects.



( run in 0.316 second using v1.01-cache-2.11-cpan-d7a12ab2c7f )