line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Twitpic; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
62653
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
38
|
|
4
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
34
|
|
5
|
1
|
|
|
1
|
|
1902
|
use utf8; |
|
1
|
|
|
|
|
17
|
|
|
1
|
|
|
|
|
6
|
|
6
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
1769
|
use LWP::UserAgent; |
|
1
|
|
|
|
|
97237
|
|
|
1
|
|
|
|
|
47
|
|
8
|
1
|
|
|
1
|
|
2172
|
use HTTP::Request::Common; |
|
1
|
|
|
|
|
2320
|
|
|
1
|
|
|
|
|
89
|
|
9
|
1
|
|
|
1
|
|
2929
|
use JSON; |
|
1
|
|
|
|
|
15559
|
|
|
1
|
|
|
|
|
5
|
|
10
|
1
|
|
|
1
|
|
1135
|
use Net::OAuth; |
|
1
|
|
|
|
|
747
|
|
|
1
|
|
|
|
|
473
|
|
11
|
|
|
|
|
|
|
our $DYNAMIC_FILE_UPLOAD = 1; |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 NAME |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Net::Twitpic - The great new Net::Twitpic! |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=head1 VERSION |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
Version 0.01 |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
=cut |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SYNOPSIS |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
Easily upload photos to Twitpic. |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
Perhaps a little code snippet. |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
use Net::Twitpic; |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
my $tp = Net::Twitpic->new( |
35
|
|
|
|
|
|
|
twitpic_api => $twitpic_api, # get from Twitpic Developers |
36
|
|
|
|
|
|
|
consumer_key => $consumer_key, # get from dev.twitter.com |
37
|
|
|
|
|
|
|
consumer_secret => $consumer_secret # get from dev.twitter.com |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
$tp->upload( |
40
|
|
|
|
|
|
|
oauth_token => $oauth_token, # get from API transaction |
41
|
|
|
|
|
|
|
oauth_secret => $oauth_secret, # get from API transaction |
42
|
|
|
|
|
|
|
file => $filename, # photo file path |
43
|
|
|
|
|
|
|
message => $message # message attached to Twitpic |
44
|
|
|
|
|
|
|
); |
45
|
|
|
|
|
|
|
if ($tp->is_success) { |
46
|
|
|
|
|
|
|
print $tp->info->{'url'}; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
=head2 new |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Construct new Net::Twitpic object. |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=cut |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub new { |
58
|
0
|
|
|
0
|
1
|
|
my $thing = shift; |
59
|
0
|
|
0
|
|
|
|
my $class = ref $thing || $thing; |
60
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new; |
61
|
0
|
|
|
|
|
|
bless { @_, ua => $ua, r => '' }, $class; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head2 upload |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
Upload the photo saved locally with message (both required). Specify OAuth token and OAuth secret you have aquired for your twitter-associated user. |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=cut |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub upload { |
71
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
72
|
0
|
|
|
|
|
|
my %params = @_; |
73
|
0
|
|
|
|
|
|
my $oauth_sign = Net::OAuth->request('Access Token')->new( |
74
|
|
|
|
|
|
|
consumer_key => $self->{'consumer_key'}, |
75
|
|
|
|
|
|
|
consumer_secret => $self->{'consumer_secret'}, |
76
|
|
|
|
|
|
|
token => $params{'oauth_token'}, |
77
|
|
|
|
|
|
|
token_secret => $params{'oauth_secret'}, |
78
|
|
|
|
|
|
|
signature_method => 'HMAC-SHA1', |
79
|
|
|
|
|
|
|
timestamp => time(), |
80
|
|
|
|
|
|
|
nonce => time() . '2323232323232323', |
81
|
|
|
|
|
|
|
request_method => 'GET', |
82
|
|
|
|
|
|
|
request_url => 'https://api.twitter.com/1/account/verify_credentials.json' |
83
|
|
|
|
|
|
|
); |
84
|
0
|
|
|
|
|
|
$oauth_sign->sign; |
85
|
0
|
|
|
|
|
|
my %uploadparams = ( |
86
|
|
|
|
|
|
|
'key' => $self->{'twitpic_api'}, |
87
|
|
|
|
|
|
|
'message' => $params{'message'}, |
88
|
|
|
|
|
|
|
'media' => [$params{'file'}] |
89
|
|
|
|
|
|
|
); |
90
|
0
|
|
|
|
|
|
my %req_headers = ( |
91
|
|
|
|
|
|
|
'X-Verify-Credentials-Authorization' => $oauth_sign->to_authorization_header, |
92
|
|
|
|
|
|
|
'X-Auth-Service-Provider' => 'https://api.twitter.com/1/account/verify_credentials.json', |
93
|
|
|
|
|
|
|
'Content-Type' => 'form-data' |
94
|
|
|
|
|
|
|
); |
95
|
0
|
|
|
|
|
|
my $request = POST('http://api.twitpic.com/2/upload.json',\%uploadparams,%req_headers); |
96
|
0
|
|
|
|
|
|
$self->{r} = $self->{ua}->request($request); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head2 is_success |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
Return true if the request has been proccessed correctly. |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=cut |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub is_success { |
106
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
107
|
0
|
|
|
|
|
|
return $self->{r}->is_success; |
108
|
|
|
|
|
|
|
} |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
=head2 info |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
Return uploaded info as hash. |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=cut |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
sub info { |
117
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
118
|
0
|
|
|
|
|
|
return decode_json($self->{r}->decoded_content); |
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
=head1 AUTHOR |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
Yusuke Sugiyama, C<< >> |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 BUGS |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Please report any bugs or feature requests to C, or through |
128
|
|
|
|
|
|
|
the web interface at L. I will be notified, and then you'll |
129
|
|
|
|
|
|
|
automatically be notified of progress on your bug as I make changes. |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 SUPPORT |
135
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
You can find documentation for this module with the perldoc command. |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
perldoc Net::Twitpic |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
You can also look for information at: |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
=over 4 |
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=item * RT: CPAN's request tracker |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
L |
148
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=item * AnnoCPAN: Annotated CPAN documentation |
150
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
L |
152
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=item * CPAN Ratings |
154
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
L |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=item * Search CPAN |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
L |
160
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=back |
162
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
=head1 ACKNOWLEDGEMENTS |
165
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
|
167
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
Copyright 2010 Yusuke Sugiyama. |
170
|
|
|
|
|
|
|
|
171
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
172
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
173
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
176
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=cut |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
1; # End of Net::Twitpic |