blib/lib/Net/Twitpic.pm

filter: Statementstmt 60.0% 24 / 40 Branchbran n/a Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 63.6% 7 / 11 Podpod 100% 4 / 4 totaltotal 58.3% 35 / 60 CC 2 SCAR 7.3
CC
2
Cov
56%
new
6.0
upload
2.0
is_success
2.0
CRAP 2.1
↑ Summary
1 package Net::Twitpic;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use HTTP::Request::Common;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use JSON;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Net::OAuth;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 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 2 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 0 ▶sub new {
Subroutine new: not called CC=2 SCAR=17.9
Pod documented
58 0 my $thing = shift;
59 0 ▶ my $class = ref $thing || $thing;
Condition0%0/3
ref $thing || $thing
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $thing || $thing
ref $thing $thing
Truth table0%0/3
A || B
A= ref $thingB= $thing
ABresult
1X1
011
000
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 0 ▶sub upload {
Subroutine upload: not called CC=1 SCAR=6.9
Pod documented
71 0 my $self = shift;
72 0 my %params = @_;
73 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 0 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 my %uploadparams = (
86 'key' => $self->{'twitpic_api'},
87 'message' => $params{'message'},
88 0 '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 0 ▶sub is_success {
Subroutine is_success: not called CC=1 SCAR=6.9
Pod documented
106 0 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 0 ▶sub info {
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
117 0 my $self = shift;
118 0 return decode_json($self->{r}->decoded_content);
119 }
120  
121 =head1 AUTHOR
122  
123 Yusuke Sugiyama, C<< <ally at blinkingstar.net> >>
124  
125 =head1 BUGS
126  
127 Please report any bugs or feature requests to C<bug-net-twitpic at rt.cpan.org>, or through
128 the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Net-Twitpic>. 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<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Net-Twitpic>
148  
149 =item * AnnoCPAN: Annotated CPAN documentation
150  
151 L<http://annocpan.org/dist/Net-Twitpic>
152  
153 =item * CPAN Ratings
154  
155 L<http://cpanratings.perl.org/d/Net-Twitpic>
156  
157 =item * Search CPAN
158  
159 L<http://search.cpan.org/dist/Net-Twitpic/>
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 2 1; # End of Net::Twitpic
↑ Summary