Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #! /usr/bin/env perl
- ###################################################
- #
- # Copyright (C) 2010-2012 Mario Kemper <[email protected]> and Shutter Team
- #
- # This file is part of Shutter.
- #
- # Shutter is free software; you can redistribute it and/or modify
- # it under the terms of the GNU General Public License as published by
- # the Free Software Foundation; either version 3 of the License, or
- # (at your option) any later version.
- #
- # Shutter is distributed in the hope that it will be useful,
- # but WITHOUT ANY WARRANTY; without even the implied warranty of
- # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
- # GNU General Public License for more details.
- #
- # You should have received a copy of the GNU General Public License
- # along with Shutter; if not, write to the Free Software
- # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
- #
- ###################################################
- package ITmages_auth;
- use lib $ENV{'SHUTTER_ROOT'}.'/share/shutter/resources/modules';
- use utf8;
- use strict;
- use POSIX qw/setlocale/;
- use Locale::gettext;
- use Glib qw/TRUE FALSE/;
- use Shutter::Upload::Shared;
- our @ISA = qw(Shutter::Upload::Shared);
- my $d = Locale::gettext->domain("shutter-upload-plugins");
- $d->dir( $ENV{'SHUTTER_INTL'} );
- my %upload_plugin_info = (
- 'module' => "ITmages_auth",
- 'url' => "http://itmages.ru/",
- 'registration' => "http://itmages.ru/user/register",
- 'description' => $d->get( "Upload screenshots to itmages.ru" ),
- 'supports_anonymous_upload' => TRUE,
- 'supports_authorized_upload' => TRUE,
- 'supports_oauth_upload' => FALSE, #TRUE if OAuth is used (see Dropbox.pm as an example)
- );
- binmode( STDOUT, ":utf8" );
- if ( exists $upload_plugin_info{$ARGV[ 0 ]} ) {
- print $upload_plugin_info{$ARGV[ 0 ]};
- exit;
- }
- #don't touch this
- sub new {
- my $class = shift;
- #call constructor of super class (host, debug_cparam, shutter_root, gettext_object, main_gtk_window, ua)
- my $self = $class->SUPER::new( shift, shift, shift, shift, shift, shift );
- bless $self, $class;
- return $self;
- }
- #load some custom modules here (or do other custom stuff)
- sub init {
- my $self = shift;
- use JSON;
- use LWP::UserAgent;
- use HTTP::Request::Common;
- return TRUE;
- }
- #handle
- sub upload {
- my ( $self, $upload_filename, $username, $password ) = @_;
- utf8::encode $upload_filename;
- utf8::encode $password;
- utf8::encode $username;
- #examples related to the sub 'init'
- my $json_coder = JSON::XS->new;
- my $client = LWP::UserAgent->new();
- eval{
- my @opts;
- push(@opts, 'Content-Type' => 'form-data');
- push(@opts, 'X-Username' => $username) if $username;
- push(@opts, 'X-Password' => $password) if $password;
- push(@opts, Content => ["file" => [ $upload_filename, $upload_filename, content_type => 'image/png' ]]);
- my $request = HTTP::Request::Common::POST('https://itmages.com/api/v3/pictures/', @opts);
- push @{ $client->requests_redirectable }, 'POST';
- my $response = $client->request($request);
- my $picture = from_json( $response->content )->{ success };
- $self->{_links}->{'direct_link'} = 'http://'.$picture->{ storage }.'.static.itmages.ru/'.$picture->{ picture };
- $self->{_links}->{'thumbnail'} = 'http://'.$picture->{ storage }.'.static.itmages.ru/'.$picture->{ thumbnail };
- $self->{_links}{'status'} = 200;
- };
- if($@){
- $self->{_links}{'status'} = $@;
- #~ print "$@\n";
- }
- #and return links
- return %{ $self->{_links} };
- }
- 1;
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement