NAME

ImgurAPI::Client - Imgur API client

DESCRIPTION

This is a client module for interfacing with the Imgur API.

SYNOPSIS

Instantiation

use ImgurAPI::Client;

my $client = ImgurAPI::Client->new({
    'client_id'    => 'your_client_id',
    'access_token' => 'your_access_token'
});

my $upload = $client->image_upload("helloimgur.png", 'file', {title => 'title', description => 'desc'});
my $image_info = $client->image($upload->{'data'}->{'id'};

Authorization

Imgur uses OAuth 2.0 for authentication. OAuth 2.0 has four steps: registration, authorization, making authenticated requests and getting new access tokens after the initial one expires using a refresh token and client secret.

After registering a client application with Imgur here, the user will need to manually authorize it. Generate a authorization url using the oauth2_authorize_url method and redirect the user to the generated url. The user will be prompted to authorize the application and upon authorization, the user will be redirected to the callback endpoint URL that was specified during application registration. The callback endpoint should collect the access token and refresh token and store them somewhere your code on the backend can pull the access token from and then pass it to the client. You can also visit the authorization url in the browser and manually pull the access token, refresh token and other parameters out of the redirect url and store them somewhere your code can pull them without having a collector endpoint setup. View the official imgur documentation for authorization here.

Authentication

The client can be authenticated by setting the access token and client id. Those can be set a couple of ways. The first way is to do it is by passing them to the constructor:

my $client = ImgurAPI::Client->new({
    'client_id'    => 'your_client_id',
    'access_token' => 'your_access_token'
});

The second way is to use the setter methods:

$client->set_access_token('your_access_token');
$client->set_client_id('your_client_id');

METHODS

new

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

Valid constructor argumentss are:

  • client_id - Client identifier used for authorization, refresh token requests and unauthenticated requests.

  • client_secret - Client secret used for acquiring a refresh token.

  • access_key - Access token used to authenticate requests.

  • rapidapi_key - Commercial use api key provided by RapidAPI.

  • format_type - Api endpoint response format type. Options are json (default) and xml.

  • oauth_cb_state - A parameter that's appended to the OAuth2 authorization callback URL. May be useful if you want to pass along a tracking value to the callback endpoint / collector.

A getter and setter method is provided for each constructor arg.

SETTER METHODS

set_access_token

$client->set_access_token('your_access_token');

set_client_id

$client->set_client_id('your_client_id');

set_client_secret

$client->set_client_secret('your_client_secret');

set_format_type

$client->set_format_type('xml');

set_oauth_cb_state

$client->set_oauth_cb_state('your_oauth_cb_state');

set_rapidapi_key

$client->set_rapidapi_key('rapidapi_key');

GETTER METHODS

access_token

$access_tok = $client->access_token;

client_id

$client_id = $client->client_id;

client_secret

$client_secret = $client->client_secret;

format_type

$format_type = $client->format_type;

oauth_cb_state

$oauth_cb_state = $client->oauth_cb_state;

rapidapi_key

$rapidapi_key = $client->rapidapi_key;

response

$response = $client->response;

response_content

$response_content = $client->response_content;

ratelimit_headers

$ratelimit_headers = $client->ratelimit_headers;

API REQUEST METHODS

AUTHOR

Dillan Hildebrand

LICENSE

MIT