| 1 | package Image::Randim::Source::Desktoppr; | ||||||||||
| 2 | 1 | our $VERSION = '0.01'; | |||||||||
| 3 | 1 | ▶ | use v5.20; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 5 | 1 | ▶ | use JSON; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 1 | has 'name' => ( is => 'ro', | |||||||||
| 9 | isa => 'Str', | ||||||||||
| 10 | default => 'Desktoppr', | ||||||||||
| 11 | ); | ||||||||||
| 12 | 1 | has 'url' => ( is => 'ro', | |||||||||
| 13 | isa => 'Str', | ||||||||||
| 14 | default => 'https://api.desktoppr.co/1/wallpapers/random', | ||||||||||
| 15 | ); | ||||||||||
| 16 | |||||||||||
| 17 | 1 | with 'Image::Randim::Source::Role'; | |||||||||
| 18 | |||||||||||
| 19 | sub get_image { | ||||||||||
| 20 | 0 | ▶ | my $self = shift; | ||||||||
|
Subroutine
get_image: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||
| 21 | 0 | my $data = JSON->new->decode($self->get_response); | |||||||||
| 22 | 0 | $data = $$data{'response'}; | |||||||||
| 23 | |||||||||||
| 24 | my $image = Image::Randim::Image->new( | ||||||||||
| 25 | url => $$data{'image'}{'url'}, | ||||||||||
| 26 | id => $$data{'id'}, | ||||||||||
| 27 | width => $$data{'width'}, | ||||||||||
| 28 | height => $$data{'height'}, | ||||||||||
| 29 | 0 | link => $$data{'url'}, | |||||||||
| 30 | ); | ||||||||||
| 31 | |||||||||||
| 32 | 0 | ▶ | if (exists $$data{'uploader'}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 33 | 0 | $image->owner($$data{'uploader'}); | |||||||||
| 34 | } | ||||||||||
| 35 | |||||||||||
| 36 | 0 | return $image; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||
| 40 | 1 | 1; | |||||||||
| 41 | |||||||||||
| 42 | =pod | ||||||||||
| 43 | |||||||||||
| 44 | =head1 NAME | ||||||||||
| 45 | |||||||||||
| 46 | Image::Randim::Source::Desktoppr - Desktoppr source plugin | ||||||||||
| 47 | |||||||||||
| 48 | =head1 SYNOPSIS | ||||||||||
| 49 | |||||||||||
| 50 | use Image::Randim::Source; | ||||||||||
| 51 | |||||||||||
| 52 | $source = Image::Randim::Source->new; | ||||||||||
| 53 | $source->set_provider('Desktoppr'); | ||||||||||
| 54 | $image = $source->get_image; | ||||||||||
| 55 | |||||||||||
| 56 | say $image->url; | ||||||||||
| 57 | |||||||||||
| 58 | =head1 DESCRIPTION | ||||||||||
| 59 | |||||||||||
| 60 | You will probably not want to call this directly, and instead ose | ||||||||||
| 61 | Image::Randim::Source as described in that class' documentation. | ||||||||||
| 62 | |||||||||||
| 63 | This "plugin" conforms to the Image::Randim::Source::Role and provides | ||||||||||
| 64 | access to a random image information from Desktoppr. | ||||||||||
| 65 | |||||||||||
| 66 | =head1 AUTHOR | ||||||||||
| 67 | |||||||||||
| 68 | Mark Rushing <mark@orbislumen.net> | ||||||||||
| 69 | |||||||||||
| 70 | =head1 COPYRIGHT AND LICENSE | ||||||||||
| 71 | |||||||||||
| 72 | This software is copyright (c) 2017 by Home Grown Systems, SPC. | ||||||||||
| 73 | |||||||||||
| 74 | This is free software; you can redistribute it and/or modify it under | ||||||||||
| 75 | the same terms as the Perl 5 programming language system itself. | ||||||||||
| 76 | |||||||||||
| 77 | =cut | ||||||||||