API-Google

 view release on metacpan or  search on metacpan

bin/goauth  view on Meta::CPAN


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/";

bin/goauth  view on Meta::CPAN

  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.274 second using v1.01-cache-2.11-cpan-cc502c75498 )