Gcis-Client

 view release on metacpan or  search on metacpan

eg/assign-keywords.pl  view on Meta::CPAN

#!/usr/bin/env perl

use lib '../lib';
use Gcis::Client;
use Data::Dumper;
use v5.14;

my $c = Gcis::Client->new;
$c->url($ARGV[0]) if $ARGV[0];
$c->find_credentials->login;
my $findings = $c->get('/report/nca3draft/finding');

for my $f (@$findings) {
    my $finding_identifer = $f->{identifier};
    say $finding_identifer;
    my $existing = $c->get($f->{uri});
    my $i = 1;
    my $post = $f->{uri};
    $post =~ s[finding][finding/keywords];
    for my $this (@{ $existing->{keywords} }) { 

lib/Gcis/Client.pm  view on Meta::CPAN

    $s->tx($tx);
    my $res = $tx->success or do {
        $s->logger->error("$path : ".$tx->error.$tx->res->body) unless $tx->res->code == 404;
        return;
    };
    return unless $res;
    my $json = $res->json or return $res->body;
    return $res->json;
}

sub find_credentials {
    my $s = shift;
    my $home = $ENV{HOME};
    die "need url to find credentials" unless $s->url;
    my $conf_file = "$home/etc/Gcis.conf";
    -e $conf_file or die "Missing $conf_file";
    my $conf = LoadFile($conf_file);
    my @found = grep { $_->{url} eq $s->url } @$conf;
    die "Multiple matches for ".$s->url." in $conf_file." if @found > 1;
    die "No matches for ".$s->url." in $conf_file." if @found < 1;
    my $key = $found[0]->{key} or die "no key for ".$s->url." in $conf_file";
    $s->logger->info("Loaded configuration from $conf_file");
    $s->key($key);
    return $s;

lib/Gcis/Client.pm  view on Meta::CPAN

    return $c->get($uri);
}

sub connect {
    my $class = shift;
    my %args = @_;

    my $url = $args{url} or die "missing url";
    my $c = $class->new;
    $c->url($url);
    $c->find_credentials->login or die "Failed to log in to $url";
    return $c;
}

1;

__END__

=head1 NAME

Gcis::Client -- Perl client for interacting with the Global Change Information System

lib/Gcis/Client.pm  view on Meta::CPAN

            number            => 12,
            sort_key          => 100,
            doi               => '10.1234/567',
            url               => 'http://example.com/report',
        }
    ) or die $c->error;

    my $c = Gcis::Client->new
        ->url('http://data.globalchange.gov')
        ->logger($logger)
        ->find_credentials
        ->login;

=head1 DESCRIPTION

This is a simple client for the GCIS API, based on L<Mojo::UserAgent>.

=head1 ATTRIBUTES

=head2 delay

lib/Gcis/Client.pm  view on Meta::CPAN

The Mojo::Transaction object from the most recent request.

=cut

=head1 METHODS

=head2 connect

    my $c = Gcis::Client->connect(url => $url);

Shorthand for Gcis::Client->new->url($url)->find_credentials->login or die "Failed to log in to $url";

=head2 find_credentials

Matches a URL with one in the configuration file.  See CONFIGURATION below.

=head2 login

Verify that a get request to /login succeeds.

Returns the client object if and only if it succeeds.

    $c->login;



( run in 0.238 second using v1.01-cache-2.11-cpan-4d50c553e7e )