Google-OAuth
view release on metacpan or search on metacpan
lib/Google/OAuth/Install.pm view on Meta::CPAN
print $fh $config ;
printf <<eof ;
Please edit $configfile
Installation instructions are described within
Then run
perl -MGoogle::OAuth::Install -e settings $configfile
eof
}
sub init {
my $function = shift ;
return 0 & print STDERR <<eof unless @ARGV ;
Usage: perl -MGoogle::OAuth::Install -e $function configfile
eof
my $configfile = shift @ARGV ;
my $error = <<eof ;
Missing or invalid configfile: $configfile
Run: perl -MGoogle::OAuth::Install -e config $configfile
eof
return 0 & print STDERR $error unless -f $configfile ;
do $configfile or return 0 & print STDERR $error ;
return 0 & print STDERR $error
unless $Google::OAuth::Config::VERSION eq '1.00' ;
return $configfile ;
}
sub settings {
return unless @_ || init('settings') ;
my %client = Google::OAuth::Config->setclient ;
print join( "\n ", 'Settings:', %client ), "\n\n" unless @_ ;
$client{client_secret} ||= 'undefined' ;
my @client = grep $_, %client ;
return print STDERR <<'eof' unless @client == 8 ;
Configuration is incomplete- run settings
eof
Google::OAuth->setclient ;
my $dsn = Google::OAuth->dsn ;
my $ok = ref $dsn && $dsn->[0] && $dsn->dbconnected ;
return print STDERR <<'eof' unless $ok ;
Missing data source
eof
return 0 ;
}
sub grantcode {
return unless init('grantcode') ;
return if settings(1) ;
Google::OAuth->setclient ;
my $link = Google::OAuth::Client->new->scope(
'calendar.readonly' )->token_request ;
printf '<a href="%s">Get Grant Code</a>%s', $link, "\n" ;
}
sub test {
init('test') unless @_ ;
return if settings(1) ;
my $code = $Google::OAuth::Config::test{grantcode} ;
return print STDERR <<'eof' unless $code ;
Generate a URL to acquire Grant Code from Google
perl -MGoogle::OAuth::Install -e grantcode configfile
eof
my %client = Google::OAuth::Config->setclient ;
$client{dsn}->loadschema unless &testdb ;
return print STDERR <<'eof' unless &testdb ;
Unable to open database dsn
eof
Google::OAuth->setclient ;
my @ok = Google::OAuth->token_list ;
return print join( "\n ", "Successfully found tokens:", @ok ), "\n"
if @ok ;
my $response = Google::OAuth->grant_code( $code ) ;
return 0 & printf "Token successfully generated for %s\n",
$response->{emailkey} if $response->{emailkey} ;
print "Unknown Error. Here's what Google has to say:\n" ;
print ref $response? join( "\n ", '', %$response ): " $response" ;
return print "\n" ;
}
sub install {
return unless my $ok = init('install') ;
Google::OAuth->setclient ;
return if Google::OAuth->token_list == 0 && test( 1 ) ;
copy( $ok, $INC{'Google/OAuth/Config.pm'} ) ;
printf "Updated %s\n", $INC{'Google/OAuth/Config.pm'} ;
}
$config = <<'eof' ;
package Google::OAuth::Config ;
my %client ;
our %test ;
###############################################################################
# #
# Step 1 - Specify a NoSQL::PL2SQL database driver #
# #
# NoSQL::PL2SQL is ideal for the amorphous data structures used in #
# Google API's and other web services. In order to use NoSQL::PL2SQL, #
# you must install one of the NoSQL::PL2SQL::DBI drivers appropriate for #
# your installation. Specify the driver below. #
# #
# The only driver currently available is NoSQL::PL2SQL::DBI::MySQL. Please #
( run in 0.710 second using v1.01-cache-2.11-cpan-39bf76dae61 )