IPP Software Navigation Tools IPP Links Communication Pan-STARRS Links

Changeset 5263


Ignore:
Timestamp:
Oct 10, 2005, 2:20:18 PM (21 years ago)
Author:
jhoblitt
Message:

add recipient to key new
add list_files()

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/PS-IPP-PSFTP/lib/PS/IPP/PSFTP.pm

    r5261 r5263  
    11# Copyright (C) 2005  Joshua Hoblitt
    22#
    3 # $Id: PSFTP.pm,v 1.2 2005-10-10 22:46:55 jhoblitt Exp $
     3# $Id: PSFTP.pm,v 1.3 2005-10-11 00:20:18 jhoblitt Exp $
    44
    55package PS::IPP::PSFTP;
     
    88use warnings FATAL => qw( all );
    99
     10use Carp qw( carp );
    1011use Data::Validate::URI qw( is_uri );
     12use LWP::UserAgent;
    1113use Params::Validate qw( validate SCALAR );
     14use PS::IPP::PSFTP::Parser;
    1215
    1316sub new
     
    1720    my %p = validate(@_,
    1821        {
    19             base_url => {
    20                 type    => SCALAR,
    21                 callbacks => {
     22            base_url    => {
     23                type        => SCALAR,
     24                callbacks   => {
    2225                    'is valid url' => sub { is_uri( $_[0] ) },
    2326                },
     27            },
     28            recipient   => {
     29                type        => SCALAR,
     30                regex       => qr/\S+/, # string with atleast 1 non WS char
    2431            },
    2532        },
    2633    );
    2734
    28     my $self = bless ({}, ref ($class) || $class);
     35    my $self = bless (\%p, ref ($class) || $class);
    2936
    3037    return $self;
     38}
     39
     40sub list_files
     41{
     42    my $self = shift;
     43
     44    validate(@_, {});
     45
     46    my $url = $self->{base_url}
     47              . "/files_available"
     48              . "?recipient="
     49              . $self->{recipient};
     50
     51    my $ua = LWP::UserAgent->new;
     52    my $response = $ua->get( $url );
     53
     54    if (! $response->is_success) {
     55        carp $response->status_line;
     56        return undef;
     57    }
     58
     59    my $parser = PS::IPP::PSFTP::Parser->new;
     60    my $records = $parser->parse($response->content);
     61
     62    return $records ? $records : undef;
    3163}
    3264
Note: See TracChangeset for help on using the changeset viewer.