=> '');
my $user = 'pavelsr@cpan.org'; # full gmail
$gapi->auth_storage->setup({type => 'jsonfile', path => '/path' }); # by default
# $gapi->auth_storage->setup({ type => 'dbi', path =>
api->do_autorefresh(1);
my $r1 = $gapi->Calendar->Events->list({ calendarId => 'primary' })->json;
warn scalar @{$r1->{items}};
To create authorization file with tokens in current folder run
fferent app credentials (client_id, client_secret, users access_token && refresh_token) storage - json file, DBI, MongoDB (u can add your own even)
=item Automatic access_token refresh (if user has r
::AuthStorage::ConfigJSON;
$Moo::Google::AuthStorage::ConfigJSON::VERSION = '0.03';
# ABSTRACT: Specific methods to fetch tokens from JSON data sources
use Moo;
use Config::JSON;
has 'pathToTokensF
ile' => ( is => 'rw', default => 'config.json' )
; # default is config.json
# has 'tokensfile'; # Config::JSON object pointer
my $tokensfile;
has 'debug' => ( is => 'rw', default => 0 );
sub s
etup {
my $self = shift;
$tokensfile = Config::JSON->new( $self->pathToTokensFile );
}
sub get_credentials_for_refresh {
my ( $self, $user ) = @_;
return {
client_id => $s
>{version}
. '/rest' )->result->json;
}
sub discover_all {
shift->ua->get('https://www.googleapis.com/discovery/v1/apis')
->result->json;
}
sub availableAPIs {
my $self = s
)
{
$tx = $self->ua->build_tx(
uc $http_method => $path => $headers => json => $optional_data );
}
elsif (
(
( lc $http_method eq 'post' )
# warn $response->json->{error}{message}; # Invalid Credentials
# warn $response->code; # 401
# warn $response->is_error; # 1
# my $res = $self->ua->start($tx)->res->json; # Mojo::Messag
post(
'https://www.googleapis.com/oauth2/v4/token' => form => $credentials )
->res->json; # tokens
}
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Moo::Google::Client - User Agent
mper;
use Config::JSON;
use Tie::File;
use Crypt::JWT qw(decode_jwt);
use feature 'say';
use Mojo::Util 'getopt';
use Mojolicious::Plugin::OAuth2;
# use Mojo::JWT;
# sub return_json_filename {
# u
iles = readdir $dir;
# my @j = grep { $_ =~ /\w+.json/ } @files;
# return $j[0];
# }
# my $f = return_json_filename();
my $config = Config::JSON->new( $ENV{'GOAUTH_TOKENSFILE'} );
delete $ENV{'G
c->ua->post(
'https://www.googleapis.com/oauth2/v4/token' => form => $hash )
->res->json;
return $tokens;
};
helper get_email => sub {
my ( $c, $access_token ) = @_;
my %h
hods to fetch tokens from different types of data sources. Default is jsonfile
use Moo;
use Moo::Google::AuthStorage::ConfigJSON;
use Moo::Google::AuthStorage::DBI;
use Moo::Google::AuthStorage::Mon
::AuthStorage::ConfigJSON->new } )
; # by default
has 'is_set' => ( is => 'rw', default => 0 );
sub setup {
my ( $self, $params ) = @_;
if ( $params->{type} eq 'jsonfile' ) {
$s
;
$self->is_set(1);
}
else {
die "Unknown storage type. Allowed types are jsonfile, dbi and mongo";
}
}
sub file_exists {
my ( $self, $filename ) = @_;
if ( -e $f