OSDN Git Service

add otp_attach tool.
[otptools/otptools.git] / Otp / Attach.pm
1 # WWW::SourceForge.JP::Wiki
2 # by hylom
3 # This code is under GPL.
4 #
5
6 use LWP;
7 use HTTP::Cookies;
8 use HTTP::Request::Common;
9 use HTML::Entities;
10 use Encode;
11 use utf8;
12
13 package Otp::Attach;
14
15 sub new {
16     my $class = shift @_;
17     my $otp = shift @_;
18
19     my $self = {
20         'otp' => $otp,
21     };
22
23     return bless $self, $class;
24 }
25
26
27 sub otp {
28     my $self = shift @_;
29     return $self->{otp};
30 }
31
32 sub _get_attach_url {
33     my $self = shift @_;
34     my $sid = shift @_;
35
36         return "http://magazine.sourceforge.jp/fileadmin.pl";
37 }
38
39 # post_attachment( <sid>, <filename1>, <filename2>,... )
40 sub post_attachment {
41     my $self = shift @_;
42     my %args = @_;
43
44     my $sid = $args{sid};
45     my $file_name = $args{file};
46
47     my $url = $self->_get_attach_url( $sid );
48     my $ua = $self->otp->lwp_ua;
49     my $req = HTTP::Request::Common::POST $url, Content_Type => 'form-data',
50     Content => [ 
51                                 file_content => ["$file_name"],
52                                 description => "",
53                                 op => "addFileForStory",
54                                 sid => $sid,
55                                 Submit => "Submit",
56         ];
57
58     my $resp = $ua->request( $req );
59
60     if( $resp->is_error ) {
61         return 0; #print "upload $file_name: failed.\n";
62     } else {
63         return 1; #print "upload $file_name: succeed.\n";
64     }
65 }
66
67 1;