| 1 | package WWW::Tumblr::Blog; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 16 | ▶ | use Moose; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 16 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 16 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||||||||||
| 6 | 16 | ▶ | use WWW::Tumblr::API; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 16 | extends 'WWW::Tumblr'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 16 | has 'base_hostname', is => 'rw', isa => 'Str', required => 1; | |||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | 16 | tumblr_api_method info => [ 'GET', 'apikey' ]; | |||||||||||||||||||||||||||||||||||||||||
| 12 | 16 | tumblr_api_method avatar => [ 'GET', 'none', undef, 'size' ]; | |||||||||||||||||||||||||||||||||||||||||
| 13 | 16 | tumblr_api_method likes => [ 'GET', 'apikey']; | |||||||||||||||||||||||||||||||||||||||||
| 14 | 16 | tumblr_api_method followers => [ 'GET', 'oauth' ]; | |||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||
| 16 | 16 | tumblr_api_method posts => [ 'GET', 'apikey', undef, 'type' ]; | |||||||||||||||||||||||||||||||||||||||||
| 17 | 16 | tumblr_api_method posts_queue => [ 'GET', 'oauth' ]; | |||||||||||||||||||||||||||||||||||||||||
| 18 | 16 | tumblr_api_method posts_draft => [ 'GET', 'oauth' ]; | |||||||||||||||||||||||||||||||||||||||||
| 19 | 16 | tumblr_api_method posts_submission => [ 'GET', 'oauth' ]; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | tumblr_api_method post_delete => [ 'POST', 'oauth' ]; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # posting methods! | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 16 | my %post_required_params = ( | |||||||||||||||||||||||||||||||||||||||||
| 26 | text => 'body', | ||||||||||||||||||||||||||||||||||||||||||
| 27 | photo => { any => [qw(source data)] }, | ||||||||||||||||||||||||||||||||||||||||||
| 28 | quote => 'quote', | ||||||||||||||||||||||||||||||||||||||||||
| 29 | link => 'url', | ||||||||||||||||||||||||||||||||||||||||||
| 30 | chat => 'conversation', | ||||||||||||||||||||||||||||||||||||||||||
| 31 | audio => { any => [qw(external_url data)] }, | ||||||||||||||||||||||||||||||||||||||||||
| 32 | video => { any => [qw(embed data)] }, | ||||||||||||||||||||||||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | sub post { | ||||||||||||||||||||||||||||||||||||||||||
| 36 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | 2 | $self->_post( %args ); | |||||||||||||||||||||||||||||||||||||||||
| 40 | } | ||||||||||||||||||||||||||||||||||||||||||
| 41 | |||||||||||||||||||||||||||||||||||||||||||
| 42 | sub _post { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_post: called CC=9 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||
| 44 | 2 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 2 | my $subr = join('/', split( /_/, [ split '::', [ caller( 1 ) ]->[3] ]->[-1] ) ); | |||||||||||||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||||||||||||||
| 48 | Carp::croak "no type specified when trying to post" | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 2 | ▶ | unless $args{ type }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||
| 51 | # check for required params per type: | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | if ( $post_required_params{ $args{ type } } ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 2 | my $req = $post_required_params{ $args{ type } }; | |||||||||||||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | if ( ref $req && ref $req eq 'HASH' && defined $req->{any} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
ref $req and ref $req eq "HASH" and defined $req->{"any"}
ref $req and ref $req eq "HASH"
MC/DC0%0/3
ref $req and ref $req eq "HASH" and defined $req->{"any"}
ref $req
ref $req eq "HASH"
defined $req->{"any"}
Truth table25%1/4
A and B and C
A= ref $reqB= ref $req eq "HASH"C= defined $req->{"any"}
| |||||||||||||||||||||||||||||||||||||||||||
| 56 | Carp::croak "Trying to post type ".$args{type}." without any of: " . | ||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | join( ' ', @{ $req->{any} } ) | |||||||||||||||||||||||||||||||||||||||||
| 58 | 2 | ▶ | if scalar( grep { $args{ $_ } } @{ $req->{any} } ) == 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 60 | Carp::croak "Trying to post type ".$args{type}." without: $req" | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 0 | ▶ | unless defined $args{ $req }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 62 | } | ||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | 2 | my $response = $self->_tumblr_api_request({ | |||||||||||||||||||||||||||||||||||||||||
| 66 | auth => 'oauth', | ||||||||||||||||||||||||||||||||||||||||||
| 67 | http_method => 'POST', | ||||||||||||||||||||||||||||||||||||||||||
| 68 | url_path => 'blog/' . $self->base_hostname . '/' . $subr, | ||||||||||||||||||||||||||||||||||||||||||
| 69 | extra_args => \%args, | ||||||||||||||||||||||||||||||||||||||||||
| 70 | }); | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | 2 | ▶ | if ( $response->is_success ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return decode_json( $response->decoded_content)->{response}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | $self->error( WWW::Tumblr::ResponseError->new( | |||||||||||||||||||||||||||||||||||||||||
| 76 | response => $response | ||||||||||||||||||||||||||||||||||||||||||
| 77 | )); | ||||||||||||||||||||||||||||||||||||||||||
| 78 | return | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 2 | } | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | sub post_edit { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_edit: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 85 | Carp::croak "no id specified when trying to edit a post!" | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | unless $args{ id }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | $self->_post( %args ); | |||||||||||||||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub post_reblog { | ||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
post_reblog: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 93 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | Carp::croak "no id specified when trying to reblog a post!" | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 0 | ▶ | unless $args{ id }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | $self->_post( %args ); | |||||||||||||||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | ▶ | sub blog { Carp::croak "Unsupported" } | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
blog: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 16 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | WWW::Tumblr::Blog | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | my $blog = $t->blog('stuff.tumblr.com'); | ||||||||||||||||||||||||||||||||||||||||||
| 113 | # or the domain name: | ||||||||||||||||||||||||||||||||||||||||||
| 114 | # my $blog = $t->blog('myblogontumblrandstuff.com'); | ||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # as per http://www.tumblr.com/docs/en/api/v2#blog-info | ||||||||||||||||||||||||||||||||||||||||||
| 117 | my $info = $blog->info; | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # as per http://www.tumblr.com/docs/en/api/v2#blog-likes | ||||||||||||||||||||||||||||||||||||||||||
| 120 | my $likes = $blog->likes; | ||||||||||||||||||||||||||||||||||||||||||
| 121 | my $likes = $blog->likes( | ||||||||||||||||||||||||||||||||||||||||||
| 122 | limit => 5, | ||||||||||||||||||||||||||||||||||||||||||
| 123 | offset => 10, | ||||||||||||||||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | # as per http://www.tumblr.com/docs/en/api/v2#photo-posts | ||||||||||||||||||||||||||||||||||||||||||
| 127 | my $posts = $blog->posts( | ||||||||||||||||||||||||||||||||||||||||||
| 128 | type => 'photo', | ||||||||||||||||||||||||||||||||||||||||||
| 129 | ... # etc | ||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||
| 132 | # Posting to the blog: | ||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | # using the source param: | ||||||||||||||||||||||||||||||||||||||||||
| 135 | my $post = $blog->post( | ||||||||||||||||||||||||||||||||||||||||||
| 136 | type => 'photo', | ||||||||||||||||||||||||||||||||||||||||||
| 137 | source => 'http://someserver.com/photo.jpg', | ||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||||||||||||||
| 140 | # using local files with the data param | ||||||||||||||||||||||||||||||||||||||||||
| 141 | # which needs to be an array reference | ||||||||||||||||||||||||||||||||||||||||||
| 142 | my $post = $blog->post( | ||||||||||||||||||||||||||||||||||||||||||
| 143 | type => 'photo', | ||||||||||||||||||||||||||||||||||||||||||
| 144 | data => [ '/home/david/larry.jpg' ], | ||||||||||||||||||||||||||||||||||||||||||
| 145 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | # you can post multiple files, as per the Tumblr API: | ||||||||||||||||||||||||||||||||||||||||||
| 148 | my $post = $blog->post( | ||||||||||||||||||||||||||||||||||||||||||
| 149 | type => 'photo', | ||||||||||||||||||||||||||||||||||||||||||
| 150 | data => [ '/file1.jpg', 'file2.jpg', ... ], | ||||||||||||||||||||||||||||||||||||||||||
| 151 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # if the result was false (empty list), then do something with the | ||||||||||||||||||||||||||||||||||||||||||
| 154 | # error: | ||||||||||||||||||||||||||||||||||||||||||
| 155 | do_something_with_the_error( $tumblr->error ) unless $post; | ||||||||||||||||||||||||||||||||||||||||||
| 156 | # or $likes | ||||||||||||||||||||||||||||||||||||||||||
| 157 | # or $info | ||||||||||||||||||||||||||||||||||||||||||
| 158 | # or anything else | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | =head1 CAVEATS | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | I never really tried posting audios or videos. | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | Please refer to L<WWW::Tumblr>. | ||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | =head1 AUTHOR(S) | ||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||
| 170 | The same folks as L<WWW::Tumblr>. | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | L<WWW::Tumblr>, L<WWW::Tumblr::ResponseError>. | ||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | =head1 COPYRIGHT and LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | Same as L<WWW::Tumblr>. | ||||||||||||||||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||||||||||||||||
| 180 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||||||||||||||