| 1 | package WebService::VaultPress::Partner; | ||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use WebService::VaultPress::Partner::Response; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use WebService::VaultPress::Partner::Request::GoldenTicket; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use WebService::VaultPress::Partner::Request::History; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use WebService::VaultPress::Partner::Request::Usage; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use JSON; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use LWP; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $abs_int = subtype as 'Int', where { $_ >= 0 }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 1 | our $VERSION = '0.05'; | |||||||||||||||||||||||||||||
| 15 | 1 | $VERSION = eval $VERSION; | |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||
| 17 | 1 | my %cache; | |||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||
| 19 | 1 | has 'key' => ( | |||||||||||||||||||||||||||||
| 20 | is => 'ro', | ||||||||||||||||||||||||||||||
| 21 | isa => 'Str', | ||||||||||||||||||||||||||||||
| 22 | required => 1, | ||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||
| 25 | 1 | has 'timeout' => ( | |||||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||||
| 27 | isa => $abs_int, | ||||||||||||||||||||||||||||||
| 28 | default => 30, | ||||||||||||||||||||||||||||||
| 29 | ); | ||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||
| 31 | 1 | has 'user_agent' => ( | |||||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||||
| 33 | isa => 'Str', | ||||||||||||||||||||||||||||||
| 34 | default => 'WebService::VaultPress::Partner/' . $VERSION, | ||||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||
| 37 | 1 | has _ua => ( | |||||||||||||||||||||||||||||
| 38 | is => 'ro', | ||||||||||||||||||||||||||||||
| 39 | init_arg => undef, | ||||||||||||||||||||||||||||||
| 40 | builder => '_build_ua', | ||||||||||||||||||||||||||||||
| 41 | ); | ||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||
| 43 | 1 | ▶ | no Moose; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | # CamelCase linking to Perly methods. | ||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | sub CreateGoldenTicket { shift->create_golden_ticket(@_) } | ||||||||||||||||||||||||||||
|
Subroutine
CreateGoldenTicket: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | sub GetUsage { shift->get_usage(@_) } | ||||||||||||||||||||||||||||
|
Subroutine
GetUsage: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | sub GetHistory { shift->get_history(@_) } | ||||||||||||||||||||||||||||
|
Subroutine
GetHistory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | sub GetRedeemedHistory { shift->get_redeemed_history(@_) } | ||||||||||||||||||||||||||||
|
Subroutine
GetRedeemedHistory: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | sub create_golden_ticket { | ||||||||||||||||||||||||||||
|
Subroutine
create_golden_ticket: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 52 | 0 | my ( $self, %request ) = @_; | |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||
| 54 | 0 | my $req = WebService::VaultPress::Partner::Request::GoldenTicket->new( %request ); | |||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||
| 56 | 0 | my $res = $self->_ua->post( | |||||||||||||||||||||||||||||
| 57 | $req->api, | ||||||||||||||||||||||||||||||
| 58 | { | ||||||||||||||||||||||||||||||
| 59 | key => $self->key, | ||||||||||||||||||||||||||||||
| 60 | email => $req->email, | ||||||||||||||||||||||||||||||
| 61 | fname => $req->fname, | ||||||||||||||||||||||||||||||
| 62 | lname => $req->lname, | ||||||||||||||||||||||||||||||
| 63 | }, | ||||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||
| 66 | # Check for HTTP transaction error (timeouts, etc) | ||||||||||||||||||||||||||||||
| 67 | 0 | $self->_croak_on_http_error( $res ); | |||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||
| 69 | 0 | my $json = decode_json( $res->content ); | |||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||
| 71 | # The API tells us if the call failed. | ||||||||||||||||||||||||||||||
| 72 | 0 | ▶ | die $json->{reason} unless $json->{status}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||||
| 74 | return WebService::VaultPress::Partner::Response->new( | ||||||||||||||||||||||||||||||
| 75 | api_call => 'CreateGoldenTicket', | ||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | ticket => exists $json->{url} ? $json->{url} : "", | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||
| 80 | 0 | ▶ | sub get_usage { | ||||||||||||||||||||||||||||
|
Subroutine
get_usage: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 81 | 0 | my ( $self, %request ) = @_; | |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | 0 | my $req = WebService::VaultPress::Partner::Request::Usage->new( %request ); | |||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||
| 85 | 0 | my $res = $self->_ua->post( $req->api, { key => $self->key } ); | |||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||
| 87 | # Check for HTTP transaction error (timeouts, etc) | ||||||||||||||||||||||||||||||
| 88 | 0 | $self->_croak_on_http_error( $res ); | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||
| 90 | 0 | my $json = decode_json( $res->content ); | |||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | # If GetUsage has a status, the call failed. | ||||||||||||||||||||||||||||||
| 93 | 0 | ▶ | die $json->{reason} if exists $json->{status}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||
| 95 | return WebService::VaultPress::Partner::Response->new( | ||||||||||||||||||||||||||||||
| 96 | api_call => 'GetUsage', | ||||||||||||||||||||||||||||||
| 97 | unused => exists $json->{unused} ? $json->{unused} : 0, | ||||||||||||||||||||||||||||||
| 98 | basic => exists $json->{basic} ? $json->{basic} : 0, | ||||||||||||||||||||||||||||||
| 99 | 0 | ▶ | premium => exists $json->{premium} ? $json->{premium} : 0, | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | ); | ||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | sub get_history { | ||||||||||||||||||||||||||||
|
Subroutine
get_history: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 105 | 0 | my ( $self, %request ) = @_; | |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | 0 | my $req = WebService::VaultPress::Partner::Request::History->new( %request ); | |||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||
| 109 | 0 | my $res = $self->_ua->post( | |||||||||||||||||||||||||||||
| 110 | $req->api, | ||||||||||||||||||||||||||||||
| 111 | { | ||||||||||||||||||||||||||||||
| 112 | key => $self->key, | ||||||||||||||||||||||||||||||
| 113 | offset => $req->offset, | ||||||||||||||||||||||||||||||
| 114 | limit => $req->limit, | ||||||||||||||||||||||||||||||
| 115 | }, | ||||||||||||||||||||||||||||||
| 116 | ); | ||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||
| 118 | # Check for HTTP transaction error (timeouts, etc) | ||||||||||||||||||||||||||||||
| 119 | 0 | $self->_croak_on_http_error( $res ); | |||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 0 | my $json = decode_json( $res->content ); | |||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||
| 123 | # If the call was successful, we should have | ||||||||||||||||||||||||||||||
| 124 | # an array ref. | ||||||||||||||||||||||||||||||
| 125 | 0 | ▶ | die $json->{reason} unless ( ref $json eq 'ARRAY' ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||
| 127 | 0 | my @responses; | |||||||||||||||||||||||||||||
| 128 | 0 | for my $elem ( @{$json} ) { | |||||||||||||||||||||||||||||
| 129 | push @responses, WebService::VaultPress::Partner::Response->new( | ||||||||||||||||||||||||||||||
| 130 | api_call => 'GetHistory', | ||||||||||||||||||||||||||||||
| 131 | email => $elem->{email} ? $elem->{email} : "", | ||||||||||||||||||||||||||||||
| 132 | lname => $elem->{lname} ? $elem->{lname} : "", | ||||||||||||||||||||||||||||||
| 133 | fname => $elem->{fname} ? $elem->{fname} : "", | ||||||||||||||||||||||||||||||
| 134 | created => $elem->{created_on} ? $elem->{created_on} : "", | ||||||||||||||||||||||||||||||
| 135 | redeemed => $elem->{redeemed_on} ? $elem->{redeemed_on} : "", | ||||||||||||||||||||||||||||||
| 136 | 0 | ▶ | type => $elem->{type} ? $elem->{type} : "", | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 137 | ); | ||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||
| 139 | 0 | return @responses; | |||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | # This isn't in the spec, but it will be very useful in some reports, | ||||||||||||||||||||||||||||||
| 143 | # and it's on line of code. | ||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | sub get_redeemed_history { | ||||||||||||||||||||||||||||
|
Subroutine
get_redeemed_history: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 145 | 0 | return grep { $_->redeemed ne '0000-00-00 00:00:00' } shift->GetHistory(@_); | |||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | sub _build_ua { | ||||||||||||||||||||||||||||
|
Subroutine
_build_ua: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 149 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||||
| 150 | 0 | return LWP::UserAgent->new( | |||||||||||||||||||||||||||||
| 151 | agent => $self->user_agent, | ||||||||||||||||||||||||||||||
| 152 | timeout => $self->timeout, | ||||||||||||||||||||||||||||||
| 153 | ); | ||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | sub _croak_on_http_error { | ||||||||||||||||||||||||||||
|
Subroutine
_croak_on_http_error: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||||
| 157 | 0 | my ( $self, $res ) = @_; | |||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||
| 159 | 0 | ▶ | croak $res->status_line unless $res->is_success; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 160 | 0 | return 0; | |||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||
| 163 | 1 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||
| 165 | 1 | 1; | |||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||
| 168 | __END__ | ||||||||||||||||||||||||||||||