Mark Allen > Net-API-Gett-1.06 > Net::API::Gett

Download:
Net-API-Gett-1.06.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Module Version: 1.06   Source  

NAME ^

Net::API::Gett - Perl bindings for Ge.tt API

VERSION ^

Version 1.06

SYNOPSIS ^

    use 5.010;
    use Net::API::Gett;

    # Get API Key from http://ge.tt/developers

    my $gett = Net::API::Gett->new( 
        api_key      => 'GettAPIKey',
        email        => 'me@example.com',
        password     => 'mysecret',
    );

    my $file_obj = $gett->upload_file( 
        filename => "ossm.txt",
        contents => "/some/path/example.txt",
           title => "My Awesome File", 
        encoding => ":encoding(UTF-8)" 
    );

    say "File has been shared at " . $file_obj->getturl;

    # Download contents
    my $file_contents = $file_obj->contents();

    open my $fh, ">:encoding(UTF-8)", "/some/path/example-copy.txt" 
        or die $!;
    print $fh $file_contents;
    close $fh;

    # clean up share and file(s)
    my $share = $gett->get_share($file->sharename);
    $share->destroy();

ABOUT ^

Gett is a clutter-free file sharing service that allows its users to share up to 2 GB of files for free. They recently implemented a REST API; this is a binding for the API. See http://ge.tt/developers for full details and how to get an API key.

CHANGES FROM PREVIOUS VERSION ^

This library is more encapsulated. Share functions which act on shares are in the Net::API::Gett::Share object namespace, and likewise with Ge.tt files. Future versions of this library will modify the Request and User objects to be roles rather than objects.

ATTRIBUTES ^

user

Net::API::Gett::User object. has_user() predicate.

request

Net::API::Gett::Request object.

METHODS ^

Unless otherwise noted, these methods die if an error occurs or if they get a response from the API which is not successful. If you need to handle errors more gracefully, use Try::Tiny to catch fatal errors.

new()

Constructs a new object. Optionally accepts:

  • A Ge.tt API key, email, and password, or,
  • A Ge.tt refresh token, or,
  • A Ge.tt access token

If any of these parameters are passed, they will be proxied into the Net::API::Gett::User object which will then permit you to make authenticated API calls. Without an access token (or the means to acquire one) only non-authenticated calls are allowed; they are: get_share(), get_file(), $file->thumbnail() and $file->contents().

Share functions

All of these functions cache Net::API::Gett::Share objects. Retrieve objects from the cache using the shares method. Use the get_share method to update a cache entry if it is stale.

get_shares()

Retrieves all share information for the given user. Takes optional scalar integers offset and limit parameters, respectively.

Returns an unordered list of Net::API::Gett::Share objects.

get_share()

Retrieves (and/or refreshes cached) information about a specific single share. Requires a sharename parameter. Does not require an access token to call.

Returns a Net::API::Gett::Share object.

create_share()

This method creates a new share instance to hold files. Takes an optional string scalar parameter which sets the share's title attribute.

Returns the new share as a Net::API::Gett::Share object.

File functions

get_file()

Returns a Net::API::Gett::File object given a sharename and a fileid. Does not require an access token to call.

upload_file()

This method uploads a file to Gett. The following key/value pairs are valid:

  • filename (required)

    What to call the uploaded file when it's inside of the Gett service.

  • sharename (optional)

    Where to store the uploaded file. If not specified, a new share will be automatically created.

  • title (optional)

    If specified, this value is used when creating a new share to hold the file. It will not change the title of an existing share. See the update() method on the share object to do that.

  • content (optional)

    A synonym for contents. (Yes, I've typo'd this too many times.) Anything in contents has precedent, if they're both specified.

  • contents (optional)

    A representation of the file's contents. This can be one of:

    • A buffer (See note below)
    • An IO::Handle object
    • A FILEGLOB
    • A pathname to a file to be read

    If not specified, the filename parameter is treated as a pathname. This attempts to be DWIM, in the sense that if contents contains a value which is not a valid filename, it treats contents as a buffer and uploads that data.

  • encoding

    An encoding scheme for the file content. By default it uses :raw. See perldoc -f binmode for more information about encodings.

  • chunk_size

    The chunk_size in bytes to use when uploading a file. Defaults to 1 MB.

Returns a Net::API::Gett:File object representing the uploaded file.

add_share()

This method populates/updates the Net::API::Gett:Share object local cache.

It returns undef if the passed value isn't a Net::API::Gett::Share object.

shares()

This method retrieves one or more cached Net::API::Gett::Share objects. Objects are requested by sharename. If no parameter list is specified, all cached objects are returned in an unordered list. (The list will not be in the order shares were added to the cache.)

If no objects are cached, this method returns an empty list.

AUTHOR ^

Mark Allen, <mrallen1 at yahoo dot com>

BUGS ^

Please report any bugs or feature requests to bug-net-api-gett at rt.cpan.org, or through the web interface at http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-API-Gett. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.

SUPPORT ^

You can find documentation for this module with the perldoc command.

    perldoc Net::API::Gett

You can also look for information at:

SEE ALSO ^

Gett API documentation

CONTRIBUTORS ^

Thanks to the following for patches:

LICENSE AND COPYRIGHT ^

Copyright 2011 Mark Allen.

This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.

See http://dev.perl.org/licenses/ for more information.

syntax highlighting: