NAME

Nuvol::Connector - Base class for Nuvol connectors

SYNOPSIS

    use Nuvol;
    my $configfile = '/path/to/configfile';
    
    # existing config file
    my $connector  = Nuvol::connect($configfile);

    # new or existing config file
    my $connector  = Nuvol::autoconnect($configfile);

    # with additional parameters
    use Nuvol::Connector;
    my $connector = Nuvol::Connector->new($configfile, $service, $params);

    $connector->authenticate;
    $connector->authenticated;
    $connector->config;
    $connector->configfile;
    $connector->disconnect;
    $connector->drive;
    $connector->drives;
    $connector->update_drives;
    $connector->url;

DESCRIPTION

Nuvol::Connector is the base class for Nuvol connectors.

CONSTRUCTOR

via Nuvol

    use Nuvol;
    $configfile = '/path/to/configfile';
    $connector  = Nuvol::connect($configfile);      # existing config file
    $connector  = Nuvol::autoconnect($configfile);  # new or existing config file

Connections are opened with Nuvol::connect or Nuvol::autoconnect.

new

    $connector = Nuvol::Connector->new($configfile, $service);

To create a new file, the parameter $service is required. It defines the type of service that will be activated in all objects created with this connector. Available services are Dropbox, Office365, and Dummy

    %params = (
      app_id       => $app_id,
      redirect_uri => $redirect_uri,
      scope        => $scope,
    );
    $connector = Nuvol::Connector->new($configfile, $service, \%params);

Optional parameters can be used to define app_id, redirect_uri, scope. Notice that the final value for the scope is set during authentication.

    $connector = Nuvol::Connector->new($configfile);

If the config file exists all values are read from it and additional parameters are ignored.

    $ perl -MNuvol::Connector -E'Nuvol::Connector->new("~/.office365.conf", "Office365")->authenticate'

New config files can be created and authenticated in the console.

METHODS

Nuvol::Connector inherits the following methods from Nuvol::Role::Metadata:

description
id
metadata
name
url

authenticate

    $connector->authenticate;

Starts an interactive authentication process. It will display a URL that has to be opened in a browser to start the authorization flow. The resulting URL is copied back to the console where it is used to retrieve the access tokens. If this process succeeds, the information is written to the config file. From now on it is possible to open the connector directly with Nuvol::connect.

authenticated

    %params = (
      access_token  => $access_token,
      expires_in    => $seconds,
      refresh_token => $refresh_token,
      scope         => $scope,
    );
    $connector = $connector->authenticated(\%params);

Setter for new authentication tokens. Can be used if the authentication is made in an external module.

config

    $value = $connector->config;

Getter for the config. Returns a Nuvol::Config.

configfile

    $value = $connector->configfile;

Getter for the path to the configfile.

disconnect

    $connector = $connector->disconnect($newvalue);

Deletes the confidential information (access token, refresh token and valitidy time) from the config file. On some services it invalidates the tokens on the server side, so it is always more secure to use this method instead of just deleting the file.

To use a disconnected config file again it has to be re-authenticated with "authenticate".

drive

    $drive = $connector->drive($path);

Getter for a drive with the specified path. Returns a Nuvol::Drive.

    $drive = $connector->drive;
    $drive = $connector->drive('~');

Called with no parameter or with ~ as path will return the default drive.

list_drives

    $drives        = $connector->list_drives;
    $default_drive = $connector->list_drives->first;

Lists the available drives. Returns a Mojo::Collection containing one or more Nuvol::Drive with the default drive at the first position. This list may be incomplete.

SEE ALSO

Nuvol, Nuvol::Config, Nuvol::Drive, Nuvol::Role::Metadata.