Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse code

Fix RT #73671

Add a test for it too.
  • Loading branch information...
commit b98565b0ffc48e816a1995d6dbfaa1cb447e91a2 1 parent fc72737
Mark Allen authored
3  Changes
... ...
@@ -1,5 +1,8 @@
1 1
 Revision history for Net-API-Gett
2 2
 
  3
+1.02    2012-01-02
  4
+        Fix for RT #73671 - Thanks to Alexander Ost for the report and patch
  5
+
3 6
 1.01    2012-01-01
4 7
         Fix test dependency failure (from CPAN testers) D'oh
5 8
 
1  MANIFEST
@@ -12,6 +12,7 @@ README
12 12
 t/00-load.t
13 13
 t/01-basic.t
14 14
 t/02-use_auth.t
  15
+t/03-many_file_share.t
15 16
 t/manifest.t
16 17
 t/pod.t
17 18
 Makefile.PL
33  lib/Net/API/Gett.pm
@@ -3,7 +3,7 @@ package Net::API::Gett;
3 3
 use strict;
4 4
 use warnings;
5 5
 
6  
-use v5.10;
  6
+use 5.010;
7 7
 
8 8
 use Moo;
9 9
 use Carp qw(croak);
@@ -24,15 +24,15 @@ Net::API::Gett - Perl bindings for Ge.tt API
24 24
 
25 25
 =head1 VERSION
26 26
 
27  
-Version 1.01
  27
+Version 1.02
28 28
 
29 29
 =cut
30 30
 
31  
-our $VERSION = '1.01';
  31
+our $VERSION = '1.02';
32 32
 
33 33
 =head1 SYNOPSIS
34 34
 
35  
-    use v5.10;
  35
+    use 5.010;
36 36
     use Net::API::Gett;
37 37
 
38 38
     # Get API Key from http://ge.tt/developers
@@ -153,7 +153,8 @@ Constructs a new object.  Optionally accepts:
153 153
 
154 154
 If any of these parameters are passed, they will be proxied into the L<Net::API::Gett::User> object which
155 155
 will then permit you to make authenticated API calls.  Without an access token (or the means to acquire one)
156  
-only non-authenticated calls are allowed; they are: C<get_share()>, C<get_file()> and C<$file->contents()>.
  156
+only non-authenticated calls are allowed; they are: C<get_share()>, C<get_file()>, 
  157
+C<$file-E<gt>thumbnail()> and C<$file-E<gt>contents()>.
157 158
 
158 159
 =back
159 160
 
@@ -321,16 +322,17 @@ What to call the uploaded file when it's inside of the Gett service.
321 322
 
322 323
 =item * sharename (optional) 
323 324
     
324  
-If not specified, a new share will be automatically created.
  325
+Where to store the uploaded file. If not specified, a new share will be automatically created.
325 326
 
326 327
 =item * title (optional) 
327 328
     
328  
-If specified, this value is used when creating a new share to hold the file.
  329
+If specified, this value is used when creating a new share to hold the file. It will not change
  330
+the title of an existing share. See the C<update()> method on the share object to do that.
329 331
 
330 332
 =item * content (optional)
331 333
 
332 334
 A synonym for C<contents>. (Yes, I've typo'd this too many times.) Anything in C<contents> has 
333  
-precedent, though.
  335
+precedent, if they're both specified.
334 336
 
335 337
 =item * contents (optional) 
336 338
 
@@ -338,7 +340,7 @@ A representation of the file's contents.  This can be one of:
338 340
 
339 341
 =over
340 342
 
341  
-=item * A buffer
  343
+=item * A buffer (See note below)
342 344
 
343 345
 =item * An L<IO::Handle> object
344 346
 
@@ -348,11 +350,14 @@ A representation of the file's contents.  This can be one of:
348 350
 
349 351
 =back
350 352
 
351  
-If not specified, the C<filename> parameter is treated as a pathname.
  353
+If not specified, the C<filename> parameter is treated as a pathname. This attempts to be DWIM, 
  354
+in the sense that if C<contents> contains a value which is not a valid filename, it treats 
  355
+C<contents> as a buffer and uploads that data.
352 356
 
353 357
 =item * encoding
354 358
 
355  
-An encoding scheme for the file content. By default it uses C<:raw>
  359
+An encoding scheme for the file content. By default it uses C<:raw>. See C<perldoc -f binmode> 
  360
+for more information about encodings.
356 361
 
357 362
 =back
358 363
 
@@ -385,7 +390,7 @@ sub upload_file {
385 390
 
386 391
     # typo proof this - yeah I've been bitten by this!
387 392
     unless ( exists $opts->{'contents'} ) {
388  
-        if ( exists $opts->{'content'} ) {
  393
+            if ( exists $opts->{'content'} ) {
389 394
             $opts->{'contents'} = delete $opts->{'content'};
390 395
         }
391 396
         else {
@@ -559,6 +564,10 @@ Thanks to the following for patches:
559 564
 
560 565
 Keedi Kim (L<https://github.com/keedi>)
561 566
 
  567
+=item
  568
+
  569
+Alexander Ost
  570
+
562 571
 =back
563 572
 
564 573
 =head1 LICENSE AND COPYRIGHT
23  lib/Net/API/Gett/File.pm
@@ -12,7 +12,7 @@ use Carp qw(croak);
12 12
 use File::Slurp qw(read_file);
13 13
 use MooX::Types::MooseLike qw(Int Str);
14 14
 
15  
-our $VERSION = '1.01';
  15
+our $VERSION = '1.02';
16 16
 
17 17
 =head1 PURPOSE
18 18
 
@@ -31,7 +31,7 @@ Scalar string
31 31
 
32 32
 =item fileid
33 33
 
34  
-Scalar integer
  34
+Scalar string
35 35
 
36 36
 =item downloads
37 37
 
@@ -84,7 +84,7 @@ has 'filename' => (
84 84
 
85 85
 has 'fileid' => (
86 86
     is => 'ro',
87  
-    isa => Int,
  87
+    isa => Str,
88 88
 );
89 89
 
90 90
 has 'downloads' => (
@@ -187,7 +187,7 @@ file pathname.
187 187
 
188 188
 =item * encoding
189 189
 
190  
-an encoding scheme. By default, it uses C<:raw> (see C<perldoc -f binmode> for more information.)
  190
+an encoding scheme. By default, it uses C<:raw>.
191 191
 
192 192
 =back
193 193
 
@@ -203,8 +203,21 @@ sub send_file {
203 203
     my $contents = shift;
204 204
     my $encoding = shift || ":raw";
205 205
 
206  
-    my $data = read_file($contents, { binmode => $encoding });
  206
+    my $data;
  207
+    if ( ! ref($contents) ) {
  208
+        # $contents is scalar
  209
+        if ( ! -e $contents ) {
  210
+            # $contents doesn't point to a valid filename, 
  211
+            # assume it's a buffer
207 212
 
  213
+            # Make sure this data is stringified.
  214
+            $data = $contents . "";
  215
+        }
  216
+    }
  217
+
  218
+    unless ( $data ) {
  219
+        $data = read_file($contents, { binmode => $encoding });
  220
+    }
208 221
     return 0 unless $data;
209 222
 
210 223
     my $response = $self->request->put($url, $data);
2  lib/Net/API/Gett/Request.pm
@@ -7,7 +7,7 @@ use JSON;
7 7
 use LWP::UserAgent;
8 8
 use HTTP::Request::Common;
9 9
 
10  
-our $VERSION = '1.01';
  10
+our $VERSION = '1.02';
11 11
 
12 12
 =head1 NAME
13 13
 
2  lib/Net/API/Gett/Share.pm
@@ -11,7 +11,7 @@ use Carp qw(croak);
11 11
 use Array::Iterator;
12 12
 use MooX::Types::MooseLike qw(Int Str);
13 13
 
14  
-our $VERSION = '1.01';
  14
+our $VERSION = '1.02';
15 15
 
16 16
 =head1 PURPOSE
17 17
 
2  lib/Net/API/Gett/User.pm
@@ -6,7 +6,7 @@ use MooX::Types::MooseLike qw(Str Int);
6 6
 
7 7
 use Net::API::Gett::Request;
8 8
 
9  
-our $VERSION = '1.01';
  9
+our $VERSION = '1.02';
10 10
 
11 11
 =head1 NAME
12 12
 

0 notes on commit b98565b

Please sign in to comment.
Something went wrong with that request. Please try again.