API-Google
view release on metacpan or search on metacpan
my $filename;
if ($ARGV[0]) {
$filename = $ARGV[0];
} else {
$filename = 'config.json';
}
if (-e $filename) {
say "File $filename exists";
input_if_not_exists(['gapi/client_id', 'gapi/client_secret']);
runserver();
} else {
say "JSON file $filename with API tokens not found. Creating new file...";
setup();
runserver();
}
sub setup {
my $oauth = {};
say "Obtain app client_id and client_secret from http://console.developers.google.com/";
my $tokensfile = Config::JSON->create($filename);
$tokensfile->set('gapi/client_id', $oauth->{client_id});
$tokensfile->set('gapi/client_secret', $oauth->{client_secret});
say 'OAuth details was updated!';
# Remove comment for Mojolicious::Plugin::JSONConfig compatibility
tie my @array, 'Tie::File', $filename or die $!;
shift @array;
untie @array;
};
sub input_if_not_exists {
my $fields = shift;
my $config = Config::JSON->new($filename);
for my $i (@$fields) {
if (!defined $config->get($i) ) {
print "$i: ";
chomp (my $val = <STDIN>);
$config->set($i, $val);
}
}
}
( run in 0.522 second using v1.01-cache-2.11-cpan-b61123c0432 )