Net-Fastly
view release on metacpan or search on metacpan
lib/Net/Fastly/Client.pm view on Meta::CPAN
The first method is to pass a proxy option into the constructor
my $client = Net::Fastly::Client->new(user => $username, password => $password, proxy => "http://localhost:8080");
The second is to set your C<https_proxy> environment variable. So, in Bash
% export https_proxy=http://localhost:8080
or in CSH or TCSH
% setenv https_proxy=http://localhost:8080
=head1 METHODS
=cut
=head2 new <opt[s]>
Create a new Fastly user agent. Options are
=over 4
=item user
The login to use
=item password
Your password
=item api_key
Alternatively use the API Key (only some commands are available)
=item proxy
Optionally pass in an https proxy to use.
=back
=cut
sub new {
my $class = shift;
my %opts = @_;
my $self = bless \%opts, $class;
my $base = $opts{base_url} ||= "api.fastly.com";
my $port = $opts{base_port} ||= 80;
$self->{user} ||= $self->{username};
$self->{_ua} = Net::Fastly::Client::UserAgent->new($base, $port, $opts{proxy});
return $self unless $self->fully_authed;
# If we're fully authed (i.e username and password ) then we need to log in
my $res = $self->_ua->_post('/login', {}, user => $self->{user}, password => $self->{password});
carp "DEPRECATION WARNING: Username/password authentication is deprecated and will not be available starting September 2020; please migrate to API tokens as soon as possible.";
unless ($res->is_success) {
die "You must have IO::Socket::SSL or Crypt::SSLeay installed in order to do SSL requests\n" if $res->code == 501 && $res->status_line =~ /Protocol scheme 'https' is not supported/;
die "Unauthorized" unless $res->is_success;
}
my $content = decode_json($res->decoded_content);
$self->{_cookie} = $res->header('set-cookie');
return wantarray ? ($self, $content->{user}, $content->{customer}) : $self;
}
sub _ua { shift->{_ua} }
=head2 authed
Whether or not we're authed at all by either API key or username & password
=cut
sub authed {
my $self = shift;
$self->key_authed || $self->fully_authed;
}
=head2 key_authed
Whether or not we're authed by API key
=cut
sub key_authed {
my $self = shift;
defined $self->{api_key}
}
=head2 fully_authed
Whether or not we're authed by username & password
=cut
sub fully_authed {
my $self = shift;
defined $self->{user} && defined $self->{password};
}
=head2 set_customer <customer id>
Set the current customer to act as.
B<NOTE>: this will only work if you're an admin
=cut
sub set_customer {
my $self = shift;
my $id = shift;
$self->{explicit_customer} = $id;
}
=head2 timeout <number>
Get or set the timeout value in seconds. The default value is 180 seconds.
=cut
sub timeout {
my $self = shift;
( run in 2.086 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )