Merge lp:~systemdisc/shutter/imgur-fix into lp:shutter

Proposed by Timothy Zorn
Status: Merged
Merged at revision: 1279
Proposed branch: lp:~systemdisc/shutter/imgur-fix
Merge into: lp:shutter
Diff against target: 341 lines (+190/-62)
4 files modified
bin/shutter (+5/-2)
share/shutter/resources/modules/Shutter/App/Common.pm (+1/-1)
share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm (+4/-0)
share/shutter/resources/system/upload_plugins/upload/Imgur.pm (+180/-59)
To merge this branch: bzr merge lp:~systemdisc/shutter/imgur-fix
Reviewer Review Type Date Requested Status
Mario Kemper (Romario) Approve
Michael Kogan Approve
Manuel Razzari (community) Approve
Review via email: mp+313977@code.launchpad.net

Description of the change

I fixed Imgur Guest uploading and added Imgur OAuth uploading. Feel free to swap out the Client ID and Client Secret for your own imgur app registered here: https://api.imgur.com/oauth2/addclient (OAuth 2 authorization without a callback URL).

To post a comment you must log in.
Revision history for this message
Timothy Zorn (systemdisc) wrote :
Revision history for this message
Manuel Razzari (manael) wrote :

This worked for me!

Would be great if guest uploads had a wizard to create a config file.

For anyone who needs it:

1. Register here: https://api.imgur.com/oauth2/addclient (OAuth 2 authorization without a callback URL).
2. Create ~/.imgur-api-config (this will be a JSON config file in your home dir)
3. Populate it with the imgur keys from step 1:

{
"client_id": "xxxxxxxxxxxxxxx",
"client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
}

review: Approve
Revision history for this message
Timothy Zorn (systemdisc) wrote :

> This worked for me!
>
> Would be great if guest uploads had a wizard to create a config file.

There's not need for guest uploads to create a config file, since the user does not need to authenticate themselves.

>
> For anyone who needs it:
>
> 1. Register here: https://api.imgur.com/oauth2/addclient (OAuth 2
> authorization without a callback URL).
> 2. Create ~/.imgur-api-config (this will be a JSON config file in your home
> dir)
> 3. Populate it with the imgur keys from step 1:
>
> {
> "client_id": "xxxxxxxxxxxxxxx",
> "client_secret": "xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx"
> }

This is incorrect. The client_id and client_secret should be set by the software, not the end user. I was letting the owner of this repository know how to get their own client_id and client_secret if they wanted it.

Revision history for this message
Manuel Razzari (manael) wrote :

> There's not need for guest uploads to create a config file, since the user
> does not need to authenticate themselves.

Apologies for the confusion. Maybe it should've been a comment on #1565048.

My note was aimed at other people trying to use this Shutter feature, since it hasn't been updated in 2+ years, and your patch does fix it.

Since I had to get my own imgur keys for it to work, I wanted to let people know how to do it without having to review the code :)

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Since it is quite improbably that Mario will review this any time soon: Is there any way to make the guest upload work without user interaction? I would like to include this patch into Shutter's Arch Linux package and get stuck with a connection error.

Revision history for this message
Timothy Zorn (systemdisc) wrote :

Guest uploading to Imgur should work without anything more than selecting Imgur Guest. Can you provide more details on the issue you're having?

Revision history for this message
Michael Kogan (michael-kogan) wrote :

I'm getting this error in a popup window when trying Imgur guest uploading:

Invalid client_id: Maybe you or Imgur revoked or expired an access token. Please close this dialog and try again. Your account will be re-authenticated the next time you upload a file.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

P.S.: Obviously I tried to close the dialog and give the uploading another go, but I always get the same message.

Revision history for this message
Timothy Zorn (systemdisc) wrote :

I'll fix it as soon as I can. This is when choosing Imgur Guest, not Imgur OAuth, correct?

Revision history for this message
Manuel Razzari (manael) wrote :

> I'm getting this error in a popup window when trying Imgur guest uploading:
>
> Invalid client_id: Maybe you or Imgur revoked or expired an access token.
> Please close this dialog and try again. Your account will be re-authenticated
> the next time you upload a file.

You just need to create an ~/.imgur-api-config file (see my comment on 01-13).

Or, since you will be distributing this, edit the hardcoded client_id and client_secret you'll find in shutter/resources/system/upload_plugins/upload/Imgur.pm

Revision history for this message
Michael Kogan (michael-kogan) wrote :

@Timothy Zorn: Exactly!

@Manuel Razzari: I hoped that for guest access this is not necessary, but if it is, I will set the id and secret fields, I guess...

Revision history for this message
Timothy Zorn (systemdisc) wrote :

I'll fix it in under 24 hours. I'm just busy today.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

@Timothy Zorn: No worry, it won't run away. Thanks for taking care of it!

lp:~systemdisc/shutter/imgur-fix updated
1280. By Timothy Zorn

Fix Imgur Guest upload without config file

1281. By Timothy Zorn

Remove extra debug info which I was using

Revision history for this message
Timothy Zorn (systemdisc) wrote :

It should work out-of-the-box now.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Cool, works now, added the patch to Arch's Shutter package!

Revision history for this message
Michael Kogan (michael-kogan) :
review: Approve
Revision history for this message
Phil (phd21) wrote :

Hi Everyone,

Could any of you please explain to me so I can explain to others, where I can download these updated file(s), and how to install them? Do I need to download just the "imgur.pm" file, or are there other files needed to get this working with "imgur", if so where? Are there new Shutter ".deb" packages available or a PPA for these updates?

FYI: I am using Linux Mint 17.3 KDE and Linux Mint 18.1 KDE and using the "shutter-testing-team" PPA to keep my Shutter application updated, is this the correct one? Have these changes been uploaded to the Shutter PPAs?

Also, since all of you seem good at this, have you come up with other ".pm" files for other image hosting services like "postimage.org", etc...? It would be really nice if Shutter had a configuration option to add other image hosts as well based upon the host's authentication method ...

Best regards to all of you,
Phil
phd21
<email address hidden>

Revision history for this message
Timothy Zorn (systemdisc) wrote :

You need bzr to download the branch.

sudo apt-get install bzr
bzr branch lp:~systemdisc/shutter/imgur-fix

> Hi Everyone,
>
> Could any of you please explain to me so I can explain to others, where I can
> download these updated file(s), and how to install them? Do I need to download
> just the "imgur.pm" file, or are there other files needed to get this working
> with "imgur", if so where? Are there new Shutter ".deb" packages available or
> a PPA for these updates?
>
> FYI: I am using Linux Mint 17.3 KDE and Linux Mint 18.1 KDE and using the
> "shutter-testing-team" PPA to keep my Shutter application updated, is this the
> correct one? Have these changes been uploaded to the Shutter PPAs?
>
>
> Also, since all of you seem good at this, have you come up with other ".pm"
> files for other image hosting services like "postimage.org", etc...? It would
> be really nice if Shutter had a configuration option to add other image hosts
> as well based upon the host's authentication method ...
>
> Best regards to all of you,
> Phil
> phd21
> <email address hidden>

Revision history for this message
Timothy Zorn (systemdisc) wrote :

Photon also apparently added this patch to Arch's Shutter package: https://aur.archlinux.org/packages/shutter/

It looks like there's a nice patch for my imgur fix there, too: https://aur.archlinux.org/cgit/aur.git/tree/fix-imgur.patch?h=shutter

Revision history for this message
Timothy Zorn (systemdisc) wrote :
Revision history for this message
Timothy Zorn (systemdisc) wrote :

For Debian, you may consider approaching the package maintainer with this merge request.
https://packages.qa.debian.org/s/shutter.html

Revision history for this message
Phil (phd21) wrote :

Hi Timothy Zorn,

Thank you for your replies.

I try to help out the members on the Linux Mint forums. Their main distributions are based on Ubuntu 14.04 (Linux Mint 17.x) and Ubuntu 16.04 (Linux Mint 18.x)

Although I am an experienced computer user, I am not familiar with using Launchpad, or Arch Linux for downloading and installing software and or their updates. I am learning them, and help from people like yourself makes that better (Thanks).

I want to be able to provide the Linux Mint members (including myself) a relatively easy way to update their Shutter application to use your version of the "imgur-fix" which includes the "Guest" and the "0Auth" authentication, that latter is more important. I used the BZR command you provided which downloaded and created your imgur-fix folder underneath my "/home/user69" folder, now what do I do to install it?

Using the Arch method looks like a lot of work, including installing the Arch package manager?. Is this safe to do in my Linux Mint (Ubuntu) system?

Best regards,
Phil
Linux Mint forum user=phd21
<email address hidden>

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Hi Phil,

I think, you cannot install an AUR package in Mint. You can either install Shutter from source (not a good practice because there will be no easy way to remove it but possible), report the bug to the Debian people (Timothy Zorn posted a link to Debian's bug tracker above) wait till some Ubuntu dev incorporates the fix by Timothy Zorn into Ubuntu's Shutter package (there is already a pretty old bug report against Ubuntu's package: https://bugs.launchpad.net/shutter/+bug/1565048), report the bug to the Mint people and hope that they do this in the Mint package, find somebody who agrees to create a PPA for Shutter, switch to an Arch based distro and use my AUR package or not use the upload functionality. :)

Revision history for this message
Elvis de Freitas Souza (edigitalb) wrote :

I really want to know why this PR is not merged yet.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Because development is dead for years already, unfortunately. I think, this needs to be fixed on packaging level unless somebody likes to take over the development and at least merge all the patches which accumulated to far.

Revision history for this message
Timothy Zorn (systemdisc) wrote :

> Because development is dead for years already, unfortunately. I think, this
> needs to be fixed on packaging level unless somebody likes to take over the
> development and at least merge all the patches which accumulated to far.

How does one become the owner of lp:shutter? I wouldn't mind taking ownership and doing an initial cleanup just to keep the project alive - I could always assign other interested parties as contributors or however it works on LaunchPad/bzr.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Probably you need to get in touch with Mario (contact information in https://launchpad.net/~mario-kemper). If he is not reachable, maybe make a fork?

Revision history for this message
Adam Stokes (adam-stokes) wrote :

I think we should fork this project and get those merges in. Also create a team that could have several members who are willing to review code, get changes merged, and packages pushed out.

I'd like to participate and also would like to see what we can do about getting a confined snap built so that Fedora, Arch, Mint, and other Debian based distros can get these updates from a single distribution code base.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

In principle I would like to participate as well since I was involved in translating and testing from the very beginning of Shutter's development (it was called GScrot back then) and have now taken over the packaging for Arch Linux. However, I don't know Perl and have very little programming experience, so I would be not much of a help, I guess. But maybe we should try to get some reply from Mario before making further plans.

Revision history for this message
Michael Kogan (michael-kogan) wrote :

P.S.: Just got a notification that Mario added me to the Shutter team and I added you guys!

Revision history for this message
Mario Kemper (Romario) (mario-kemper) :
review: Approve
Revision history for this message
Mario Kemper (Romario) (mario-kemper) wrote :

Hi all,

sorry for being silent for some time, but unfortunately my time is very limited nowadays. I have added Michael Kogan to both relevant groups (Shutter Team and Shutter Testing Team) as Administrator. Please let me know if you are able to push/merge to lp:shutter (trunk) and please also let me know if you need any further information. Most of the things are working automatically (creating packages for PPAs via recipe et cetera).

Good luck and thanks for your contribution.

Bye
Mario

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Thanks, Mario, I hope, we will manage!

Adam, Thimothy: I added you to both groups as well, but I won't have time to deal with the merging before Saturday, so feel free to go ahead!

Revision history for this message
Timothy Zorn (systemdisc) wrote :

I won't be available until this weekend, either.

Revision history for this message
Adam Stokes (adam-stokes) wrote :

I attempted to do the merge tonight but I don't seem to have access to push to trunk

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Sorry for the delay, guys, I will look into it in the evening!

Revision history for this message
Michael Kogan (michael-kogan) wrote :

Looks like the permissions for the lp:shutter branch do not give push permissions to the Shutter group. I wrote a mail to Mario and asked for further instructions.

Revision history for this message
Timothy Zorn (systemdisc) wrote :

Do we have somewhere we can communicate in real-time, instead of communicating through the issue tracker? (IRC, Facebook, etc)

Maybe we should set up a channel in freenode or something.

Revision history for this message
Adam Stokes (adam-stokes) wrote :

Agreed, how about #shutter on freenode?

Revision history for this message
Timothy Zorn (systemdisc) wrote :

Sounds good to me

Revision history for this message
Michael Kogan (michael-kogan) wrote :

I joined you at the channel, guys!

Revision history for this message
Timothy Zorn (systemdisc) wrote :

Make sure to mention my nickname in IRC so I get a notification

Preview Diff

[H/L] Next/Prev Comment, [J/K] Next/Prev File, [N/P] Next/Prev Hunk
=== modified file 'bin/shutter'
--- bin/shutter 2014-12-23 23:02:02 +0000
+++ bin/shutter 2017-01-28 09:57:21 +0000
@@ -8353,7 +8353,10 @@
8353 #~ print $name, $folder, $type, "\n";8353 #~ print $name, $folder, $type, "\n";
83548354
8355 if ( !exists $accounts{$name}8355 if ( !exists $accounts{$name}
8356 || !exists $accounts{$name}->{module} )8356 || !exists $accounts{$name}->{module}
8357 || $accounts{$name}->{supports_anonymous_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_anonymous_upload' ) ||
8358 $accounts{$name}->{supports_authorized_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_authorized_upload' ) ||
8359 $accounts{$name}->{supports_oauth_upload} ne &fct_upload_plugin_get_info( $ukey, 'supports_oauth_upload' ) )
8357 {8360 {
83588361
8359 #show dialog and progress bar8362 #show dialog and progress bar
@@ -10632,7 +10635,7 @@
10632 my $uploader = $hosting_module->new( $hosting_host, $sc->get_debug, $shutter_root, $d, $window, SHUTTER_VERSION );10635 my $uploader = $hosting_module->new( $hosting_host, $sc->get_debug, $shutter_root, $d, $window, SHUTTER_VERSION );
1063310636
10634 #init module10637 #init module
10635 if ( $uploader->init ) {10638 if ( $uploader->init($hosting_username) ) {
1063610639
10637 my $counter = 1;10640 my $counter = 1;
10638 $hosting_progress->set_fraction(0);10641 $hosting_progress->set_fraction(0);
1063910642
=== modified file 'share/shutter/resources/modules/Shutter/App/Common.pm'
--- share/shutter/resources/modules/Shutter/App/Common.pm 2013-08-25 18:40:51 +0000
+++ share/shutter/resources/modules/Shutter/App/Common.pm 2017-01-28 09:57:21 +0000
@@ -48,7 +48,7 @@
48 my $self = { _shutter_root => shift, _mainwindow => shift, _appname => shift, _version => shift, _rev => shift, _pid => shift };48 my $self = { _shutter_root => shift, _mainwindow => shift, _appname => shift, _version => shift, _rev => shift, _pid => shift };
4949
50 #vars50 #vars
51 $self->{_debug_cparam} = FALSE;51 $self->{_debug_cparam} = TRUE;
52 $self->{_clear_cache} = FALSE;52 $self->{_clear_cache} = FALSE;
53 $self->{_min_cparam} = FALSE;53 $self->{_min_cparam} = FALSE;
54 $self->{_disable_systray_cparam} = FALSE;54 $self->{_disable_systray_cparam} = FALSE;
5555
=== modified file 'share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm'
--- share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm 2013-08-25 18:40:51 +0000
+++ share/shutter/resources/modules/Shutter/App/SimpleDialogs.pm 2017-01-28 09:57:21 +0000
@@ -59,6 +59,7 @@
59 my $detail_message = shift;59 my $detail_message = shift;
60 my $detail_checkbox = shift;60 my $detail_checkbox = shift;
61 my $content_widget = shift;61 my $content_widget = shift;
62 my $content_widget2 = shift;
6263
63 my $info_dialog = Gtk2::MessageDialog->new( $self->{_window}, [qw/modal destroy-with-parent/], 'info', 'none', undef );64 my $info_dialog = Gtk2::MessageDialog->new( $self->{_window}, [qw/modal destroy-with-parent/], 'info', 'none', undef );
6465
@@ -71,6 +72,9 @@
71 if($content_widget){72 if($content_widget){
72 $info_dialog->get_content_area()->add($content_widget);73 $info_dialog->get_content_area()->add($content_widget);
73 }74 }
75 if($content_widget2){
76 $info_dialog->get_content_area()->add($content_widget2);
77 }
7478
75 $info_dialog->add_button( $button_text_extra1, 10 ) if $button_text_extra1;79 $info_dialog->add_button( $button_text_extra1, 10 ) if $button_text_extra1;
76 $info_dialog->add_button( $button_text_extra2, 20 ) if $button_text_extra2;80 $info_dialog->add_button( $button_text_extra2, 20 ) if $button_text_extra2;
7781
=== modified file 'share/shutter/resources/system/upload_plugins/upload/Imgur.pm'
--- share/shutter/resources/system/upload_plugins/upload/Imgur.pm 2013-08-25 18:40:51 +0000
+++ share/shutter/resources/system/upload_plugins/upload/Imgur.pm 2017-01-28 09:57:21 +0000
@@ -29,7 +29,8 @@
29use strict;29use strict;
30use POSIX qw/setlocale/;30use POSIX qw/setlocale/;
31use Locale::gettext;31use Locale::gettext;
32use Glib qw/TRUE FALSE/; 32use Glib qw/TRUE FALSE/;
33use MIME::Base64;
3334
34use Shutter::Upload::Shared;35use Shutter::Upload::Shared;
35our @ISA = qw(Shutter::Upload::Shared);36our @ISA = qw(Shutter::Upload::Shared);
@@ -38,12 +39,13 @@
38$d->dir( $ENV{'SHUTTER_INTL'} );39$d->dir( $ENV{'SHUTTER_INTL'} );
3940
40my %upload_plugin_info = (41my %upload_plugin_info = (
41 'module' => "Imgur",42 'module' => "Imgur",
42 'url' => "http://imgur.com/",43 'url' => "http://imgur.com/",
43 'registration' => "https://imgur.com/register",44 'registration' => "https://imgur.com/register",
44 'description' => $d->get( "Imgur is used to share photos with social networks and online communities, and has the funniest pictures from all over the Internet" ),45 'description' => $d->get( "Imgur is used to share photos with social networks and online communities, and has the funniest pictures from all over the Internet" ),
45 'supports_anonymous_upload' => TRUE,46 'supports_anonymous_upload' => TRUE,
46 'supports_authorized_upload' => FALSE,47 'supports_authorized_upload' => FALSE,
48 'supports_oauth_upload' => TRUE,
47);49);
4850
49binmode( STDOUT, ":utf8" );51binmode( STDOUT, ":utf8" );
@@ -66,13 +68,128 @@
6668
67sub init {69sub init {
68 my $self = shift;70 my $self = shift;
71 my $username = shift;
6972
70 #do custom stuff here 73 #do custom stuff here
71 use JSON;74 use JSON;
72 use LWP::UserAgent;75 use LWP::UserAgent;
73 use HTTP::Request::Common;76 use HTTP::Request::Common;
74 77 use Path::Class;
75 return TRUE;78
79 $self->{_config} = { };
80 $self->{_config_file} = file( $ENV{'HOME'}, '.imgur-api-config' );
81
82 $self->load_config;
83 if ($username eq $d->get("OAuth"))
84 {
85 return $self->connect;
86 }
87
88 return TRUE;
89}
90
91sub load_config {
92 my $self = shift;
93
94 if (-f $self->{_config_file}) {
95 eval {
96 $self->{_config} = decode_json($self->{_config_file}->slurp);
97 };
98 if ($@) {
99 $self->{_config}->{client_id} = '9490811e0906b6e';
100 $self->{_config}->{client_secret} = '158b57f13e9a51f064276bd9e31529fb065f741e';
101 }
102 }
103 else {
104 $self->{_config}->{client_id} = '9490811e0906b6e';
105 $self->{_config}->{client_secret} = '158b57f13e9a51f064276bd9e31529fb065f741e';
106 }
107
108 return TRUE;
109}
110
111sub connect {
112 my $self = shift;
113 return $self->setup;
114}
115
116sub setup {
117 my $self = shift;
118
119 if ($self->{_debug_cparam}) {
120 print "Setting up Imgur...\n";
121 }
122
123 #some helpers
124 my $sd = Shutter::App::SimpleDialogs->new;
125
126 #Authentication
127 my $login_link = 'https://api.imgur.com/oauth2/authorize?response_type=pin&client_id=' . $self->{_config}->{client_id};
128
129 my $pin_entry = Gtk2::Entry->new();
130 my $pin = '';
131 $pin_entry->signal_connect(changed => sub {
132 $pin = $pin_entry->get_text;
133 });
134
135 my $response = $sd->dlg_info_message(
136 $d->get("Please click on the button below to authorize with Imgur. Input the PIN you receive and press 'Apply' when you are done."),
137 $d->get("Authorize with Imgur"),
138 'gtk-cancel','gtk-apply', undef,
139 undef, undef, undef, undef, undef,
140 Gtk2::LinkButton->new ($login_link, $d->get("Authorize")),
141 $pin_entry,
142 );
143 if ($response == 20) {
144
145 if ($self->{_debug_cparam}) {
146 print "Imgur: Authorizing...\n";
147 }
148
149 my %params = (
150 'client_id' => $self->{_config}->{client_id},
151 'client_secret' => $self->{_config}->{client_secret},
152 'grant_type' => 'pin',
153 'pin' => $pin,
154 );
155
156 my @params = (
157 "https://api.imgur.com/oauth2/token",
158 'Content' => [%params]
159 );
160
161 my $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Client-ID ' . $self->{_config}->{client_id});
162
163 my $client = LWP::UserAgent->new(
164 'timeout' => 20,
165 'keep_alive' => 10,
166 'env_proxy' => 1,
167 );
168 my $rsp = $client->request($req);
169
170 my $json = JSON->new();
171 my $json_rsp = $json->decode($rsp->content);
172
173 if ($self->{_debug_cparam}) {
174 print $pin . ' ' . $rsp->content;
175 }
176 if (exists $json_rsp->{status} && $json_rsp->{status} ne 200) {
177 return $self->setup;
178 }
179
180 $self->{_config}->{access_token} = $json_rsp->{access_token};
181 $self->{_config}->{refresh_token} = $json_rsp->{refresh_token};
182 $self->{_config}->{account_id} = $json_rsp->{account_id};
183 $self->{_config}->{account_username} = $json_rsp->{account_username};
184
185 $self->{_config_file}->openw->print(encode_json($self->{_config}));
186 chmod 0600, $self->{_config_file};
187
188 return TRUE;
189 }
190 else {
191 return FALSE;
192 }
76}193}
77194
78sub upload {195sub upload {
@@ -87,62 +204,66 @@
87 utf8::encode $password;204 utf8::encode $password;
88 utf8::encode $username;205 utf8::encode $username;
89206
90 #~ if ( $username ne "" && $password ne "" ) {207 my $client = LWP::UserAgent->new(
91208 'timeout' => 20,
92 my $client = LWP::UserAgent->new(209 'keep_alive' => 10,
93 'timeout' => 20,210 'env_proxy' => 1,
94 'keep_alive' => 10,211 );
95 'env_proxy' => 1,212
96 );213 eval {
97214
98 eval{215 my $json = JSON->new();
99216
100 my $json = JSON->new(); 217 open( IMAGE, $upload_filename ) or die "$!";
101218 my $binary_data = do { local $/ = undef; <IMAGE>; };
102 my %params = (219 close IMAGE;
103 'image' => [$upload_filename],220 my $encoded_image = encode_base64($binary_data);
104 'key' => '12ea5e932124142c5ef3c8d5a02557de',221
105 );222 my %params = (
106223 'image' => $encoded_image,
107 my @params = (224 );
108 "http://api.imgur.com/1/upload.json",225
109 'Content_Type' => 'multipart/form-data',226 my @params = (
110 'Content' => [%params]227 "https://api.imgur.com/3/image",
111 );228 'Content' => [%params]
112229 );
113 my $req = HTTP::Request::Common::POST(@params);230
114 my $rsp = $client->request($req);231 my $req;
115232 if ($username eq $d->get("OAuth") && $self->{_config}->{access_token}) {
116 #~ print Dumper $json->decode( $rsp->content ); 233 $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Bearer ' . $self->{_config}->{access_token});
117234 }
118 $self->{_links} = $json->decode( $rsp->content ); 235 else {
119 $self->{_links} = $self->{_links}->{'rsp'};236 $req = HTTP::Request::Common::POST(@params, 'Authorization' => 'Client-ID ' . $self->{_config}->{client_id});
120 if(defined $self->{_links}->{'stat'} && $self->{_links}->{'stat'} eq 'ok'){237 }
121 $self->{_links} = $self->{_links}->{'image'};238 my $rsp = $client->request($req);
122 #clean hash239
123 foreach (keys %{$self->{_links}}){240 #~ print Dumper $json->decode( $rsp->content );
124 if($_ eq 'delete_hash' || $_ eq 'image_hash'){241
125 delete $self->{_links}->{$_};242 my $json_rsp = $json->decode( $rsp->content );
126 next;243
127 }244 if ($json_rsp->{'status'} ne 200) {
128 if( $self->{_debug_cparam}) {245 unlink $self->{_config_file};
129 print $_.": ".$self->{_links}->{$_}, "\n";246 $self->{_links}{'status'} = '';
130 }247 if (exists $json_rsp->{'data'}->{'error'}) {
131 }248 $self->{_links}{'status'} .= $json_rsp->{'data'}->{'error'} . ': ';
132 #set status (success)
133 $self->{_links}{'status'} = 200;
134 }else{
135 $self->{_links}{'status'} = $self->{_links}->{'image'}->{'error_msg'};
136 }249 }
137 250 $self->{_links}{'status'} .= $d->get("Maybe you or Imgur revoked or expired an access token. Please close this dialog and try again. Your account will be re-authenticated the next time you upload a file.");
138 };251 return %{ $self->{_links} };
139 if($@){
140 $self->{_links}{'status'} = $@;
141 #~ print "$@\n";
142 }252 }
143253
144 #~ }254 $self->{_links}{'status'} = $json_rsp->{'status'};
145 255 $self->{_links}->{'direct_link'} = $json_rsp->{'data'}->{'link'};
256 $self->{_links}->{'deletion_link'} = 'https://imgur.com/delete/' . $json_rsp->{'data'}->{'deletehash'};
257 $self->{_links}->{'post_link'} = $json_rsp->{'data'}->{'link'};
258 $self->{_links}->{'post_link'} =~ s/i\.imgur/imgur/;
259 $self->{_links}->{'post_link'} =~ s/\.[^.]+$//;
260
261 };
262 if ($@) {
263 $self->{_links}{'status'} = $@;
264 #~ print "$@\n";
265 }
266
146 #and return links267 #and return links
147 return %{ $self->{_links} };268 return %{ $self->{_links} };
148}269}

Subscribers

People subscribed via source and target branches

to status/vote changes: