ImgurAPI

ImgurAPI::Client is an Imgur API client perl module.

Installation

CPAN/M

cpan ImgurAPI::Client or cpanm ImgurAPI::Client

Manual

  1. Clone the repository git clone https://github.com/selftaught/ImgurAPI.git
  2. Cd into the repo root and generate a makefile: perl Makefile.pl
  3. Make it: make && make test && make install

Usage

Instantiation

use ImgurAPI::Client;

my %args = (
  # ...
);

my $client = ImgurAPI::Client->new(\%args);

Valid constructor arg keys are:

You can also set the values using the setter member subroutines listed at the bottom of the page.

Authorization

If you haven't already, register an application for an OAuth2 client ID and secret here.

You will need to authorize your OAuth2 application if you haven't already done so. You can get the authorization URL with oauth2_authorize_url:

my $auth_url = $client->oauth2_authorize_url();

# return to user for manual authorization

Authentication

Once the application has been authorized, the access token, refresh token and expires_in values will be passed to the callback endpoint URL that was specified during application registration. The callback endpoint should collect the values and store them somewhere your code on the backend can pull them from and pass them to the client.

my $client = ImgurAPI::Client->new({
  access_token => get_access_token_from_some_db()
});
# OR $client->set_access_token(get_access_token_from_some_db());

The client library doesn't handle refreshing the access token for you automatically. It is left up to the calling code to refresh the access token when it expires. This is so you can keep the refresh token updated in the database you stored it in initially.

Refreshing access tokens

Access tokens expire after a period of time. To get a new access token, you can use the refresh_access_token method. This method requires the refresh_token, client_id and client_secret. You can pass these values to the method or set them using the setter methods. If you don't pass them and they're not set internally in the client, the method will die with an error. If the call is successful, the internal access_token will be updated to the new token for use in subsequent requests. However, the new refresh and access tokens should be stored somewhere persistent for later use.

my %args = (
    'refresh_token' => get_refresh_token_from_db(),
    'client_id' => get_client_id_from_db(),
    'client_secret' => get_client_secret_from_db()
);

# returns a hashref containing 'access_token' and 'refresh_token' keys
my $resp = $client->refresh_access_token(\%args);

# Store the refresh & access token somewhere persistent they can be pulled from later.
# store_refresh_and_access_token_in_db($resp)

Examples

Checkout the examples directory.

Requests

Account

Album

Comment

Image

Feed

Client member subroutines

Getters

Setters

Publishing to CPAN

Prepare distribution

perl Makefile.PL && make dist && make clean

Upload

cpan-upload -u <PAUSEUSERNAME> ImgurAPI-Client-$VERSION.tar.gz