| 1 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 2 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 3 | package Net::CronIO; | ||||||||||
| 4 | { | ||||||||||
| 5 | 2 | $Net::CronIO::VERSION = '0.01'; | |||||||||
| 6 | } | ||||||||||
| 7 | |||||||||||
| 8 | # ABSTRACT: Perl binding for cron.io | ||||||||||
| 9 | |||||||||||
| 10 | 2 | ▶ | use Net::HTTP::API; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 2 | ▶ | use Carp qw(croak); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | |||||||||||
| 13 | |||||||||||
| 14 | 2 | net_api_declare cronio => ( | |||||||||
| 15 | api_base_url => 'http://api.cron.io/v1', | ||||||||||
| 16 | api_format => 'json', | ||||||||||
| 17 | api_format_mode => 'content-type', | ||||||||||
| 18 | authentication => 1, | ||||||||||
| 19 | ); | ||||||||||
| 20 | |||||||||||
| 21 | |||||||||||
| 22 | 2 | net_api_method create_user => ( | |||||||||
| 23 | description => "Sign up for service and get a username/password", | ||||||||||
| 24 | method => "POST", | ||||||||||
| 25 | path => '/users', | ||||||||||
| 26 | params => [qw(email username password)], | ||||||||||
| 27 | required => [qw(email username password)], | ||||||||||
| 28 | expected => [qw(201)], | ||||||||||
| 29 | ); | ||||||||||
| 30 | |||||||||||
| 31 | |||||||||||
| 32 | 2 | net_api_method get_all_crons => ( | |||||||||
| 33 | description => "List all the crons you have. Requires authentication.", | ||||||||||
| 34 | method => "GET", | ||||||||||
| 35 | path => '/crons', | ||||||||||
| 36 | authentication => 1, | ||||||||||
| 37 | ); | ||||||||||
| 38 | |||||||||||
| 39 | |||||||||||
| 40 | 2 | net_api_method create_cron => ( | |||||||||
| 41 | description => "Create a new cron entry for your account. Requires authentication.", | ||||||||||
| 42 | method => "POST", | ||||||||||
| 43 | path => '/crons', | ||||||||||
| 44 | params => [qw(name url schedule)], | ||||||||||
| 45 | required => [qw(name url schedule)], | ||||||||||
| 46 | authentication => 1, | ||||||||||
| 47 | ); | ||||||||||
| 48 | |||||||||||
| 49 | |||||||||||
| 50 | 2 | net_api_method get_cron => ( | |||||||||
| 51 | description => "List a specific cron entry. Requires a cron id and authentication.", | ||||||||||
| 52 | method => "GET", | ||||||||||
| 53 | path => '/crons/:id', | ||||||||||
| 54 | params => [qw(id)], | ||||||||||
| 55 | required => [qw(id)], | ||||||||||
| 56 | authentication => 1, | ||||||||||
| 57 | ); | ||||||||||
| 58 | |||||||||||
| 59 | |||||||||||
| 60 | 2 | net_api_method update_cron => ( | |||||||||
| 61 | description => "Update a cron entry. Requires cron id and authentication.", | ||||||||||
| 62 | method => "PUT", | ||||||||||
| 63 | path => '/crons/:id', | ||||||||||
| 64 | params => [qw(id name url schedule)], | ||||||||||
| 65 | required => [qw(id)], | ||||||||||
| 66 | authentication => 1, | ||||||||||
| 67 | ); | ||||||||||
| 68 | |||||||||||
| 69 | |||||||||||
| 70 | 2 | net_api_method delete_cron => ( | |||||||||
| 71 | descripton => "Delete a cron entry. Requires cron id and authentication.", | ||||||||||
| 72 | method => "DELETE", | ||||||||||
| 73 | path => '/crons/:id', | ||||||||||
| 74 | params => [qw(id)], | ||||||||||
| 75 | required => [qw(id)], | ||||||||||
| 76 | expected => [qw(204)], | ||||||||||
| 77 | authentication => 1, | ||||||||||
| 78 | ); | ||||||||||
| 79 | |||||||||||
| 80 | 0 | ▶ | around 'delete_cron' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 81 | 0 | my $orig = shift; | |||||||||
| 82 | 0 | my $self = shift; | |||||||||
| 83 | |||||||||||
| 84 | 0 | my ($content, $response) = $self->$orig(@_); | |||||||||
| 85 | |||||||||||
| 86 | 0 | ▶ | if ( $response->is_success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 87 | 0 | return 1; | |||||||||
| 88 | } | ||||||||||
| 89 | else { | ||||||||||
| 90 | 0 | croak $response->status_line; | |||||||||
| 91 | } | ||||||||||
| 92 | 2 | }; | |||||||||
| 93 | |||||||||||
| 94 | 0 | ▶ | around 'create_user' => sub { | ||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
| |||||||||||
| 95 | 0 | my $orig = shift; | |||||||||
| 96 | 0 | my $self = shift; | |||||||||
| 97 | |||||||||||
| 98 | 0 | my ($content, $response) = $self->$orig(@_); | |||||||||
| 99 | |||||||||||
| 100 | 0 | ▶ | if ( $response->is_success ) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 101 | 0 | return $content->{'message'}; | |||||||||
| 102 | } | ||||||||||
| 103 | else { | ||||||||||
| 104 | 0 | croak $response->status_line . ": " . $response->content; | |||||||||
| 105 | } | ||||||||||
| 106 | 2 | }; | |||||||||
| 107 | |||||||||||
| 108 | 2 | 1; | |||||||||
| 109 | |||||||||||
| 110 | |||||||||||
| 111 | __END__ | ||||||||||