| 1 | package WWW::Authy; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 2 | $WWW::Authy::AUTHORITY = 'cpan:GETTY'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | { | ||||||||||||||||||||||||||||
| 6 | 2 | $WWW::Authy::VERSION = '0.002'; | |||||||||||||||||||||||||||
| 7 | } | ||||||||||||||||||||||||||||
| 8 | # ABSTRACT: Easy access to the already so easy Authy API | ||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use MooX qw( | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | +LWP::UserAgent | ||||||||||||||||||||||||||||
| 13 | +HTTP::Request::Common | ||||||||||||||||||||||||||||
| 14 | +URI | ||||||||||||||||||||||||||||
| 15 | +URI::QueryParam | ||||||||||||||||||||||||||||
| 16 | +JSON | ||||||||||||||||||||||||||||
| 17 | 2 | ); | |||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 2 | ▶ | use Carp qw( croak ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||
| 22 | 2 | ▶ | our $VERSION ||= '0.000'; | ||||||||||||||||||||||||||
|
Condition50%1/2
our $VERSION ||= "0.000"
MC/DC0%0/1
our $VERSION ||= "0.000"
our $VERSION
Truth table50%1/2
A
A= our $VERSION
| |||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 2 | has api_key => ( | |||||||||||||||||||||||||||
| 26 | is => 'ro', | ||||||||||||||||||||||||||||
| 27 | required => 1, | ||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||
| 31 | 2 | has sandbox => ( | |||||||||||||||||||||||||||
| 32 | is => 'ro', | ||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||
| 34 | builder => 1, | ||||||||||||||||||||||||||||
| 35 | ); | ||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||
| 37 | 1 | ▶ | sub _build_sandbox { 0 } | ||||||||||||||||||||||||||
|
Subroutine
_build_sandbox: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | |||||||||||||||||||||||||||||
| 40 | 2 | has errors => ( | |||||||||||||||||||||||||||
| 41 | is => 'rw', | ||||||||||||||||||||||||||||
| 42 | predicate => 1, | ||||||||||||||||||||||||||||
| 43 | clearer => 1, | ||||||||||||||||||||||||||||
| 44 | ); | ||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | 2 | has base_uri => ( | |||||||||||||||||||||||||||
| 48 | is => 'ro', | ||||||||||||||||||||||||||||
| 49 | lazy => 1, | ||||||||||||||||||||||||||||
| 50 | builder => 1, | ||||||||||||||||||||||||||||
| 51 | ); | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 2 | ▶ | sub _build_base_uri { | ||||||||||||||||||||||||||
|
Subroutine
_build_base_uri: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 54 | shift->sandbox | ||||||||||||||||||||||||||||
| 55 | 2 | ▶ | ? 'http://sandbox-api.authy.com' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | : 'https://api.authy.com' | ||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 2 | has useragent => ( | |||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||
| 62 | lazy => 1, | ||||||||||||||||||||||||||||
| 63 | builder => 1, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | sub _build_useragent { | ||||||||||||||||||||||||||
|
Subroutine
_build_useragent: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 67 | 0 | my ( $self ) = @_; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | LWP::UserAgent->new( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | agent => $self->useragent_agent, | ||||||||||||||||||||||||||||
| 70 | $self->has_useragent_timeout ? (timeout => $self->useragent_timeout) : (), | ||||||||||||||||||||||||||||
| 71 | ); | ||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | has useragent_agent => ( | |||||||||||||||||||||||||||
| 76 | is => 'ro', | ||||||||||||||||||||||||||||
| 77 | lazy => 1, | ||||||||||||||||||||||||||||
| 78 | builder => 1, | ||||||||||||||||||||||||||||
| 79 | ); | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 0 | ▶ | sub _build_useragent_agent { (ref $_[0] ? ref $_[0] : $_[0]).'/'.$VERSION } | ||||||||||||||||||||||||||
|
Subroutine
_build_useragent_agent: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | has useragent_timeout => ( | |||||||||||||||||||||||||||
| 85 | is => 'ro', | ||||||||||||||||||||||||||||
| 86 | predicate => 'has_useragent_timeout', | ||||||||||||||||||||||||||||
| 87 | ); | ||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 2 | has json => ( | |||||||||||||||||||||||||||
| 91 | is => 'ro', | ||||||||||||||||||||||||||||
| 92 | lazy => 1, | ||||||||||||||||||||||||||||
| 93 | builder => 1, | ||||||||||||||||||||||||||||
| 94 | ); | ||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||
| 96 | 0 | ▶ | sub _build_json { | ||||||||||||||||||||||||||
|
Subroutine
_build_json: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 97 | 0 | my $json = JSON->new; | |||||||||||||||||||||||||||
| 98 | 0 | $json->allow_nonref; | |||||||||||||||||||||||||||
| 99 | 0 | return $json; | |||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | ############################################################################################################# | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 2 | ▶ | sub BUILDARGS { | ||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=3 SCAR=12.5
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 2 | my ( $class, @args ) = @_; | |||||||||||||||||||||||||||
| 106 | 2 | ▶ | unshift @args, "api_key" if @args % 2 && ref $args[0] ne 'HASH'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
@args % 2 and ref $args[0] ne "HASH"
MC/DC0%0/2
@args % 2 and ref $args[0] ne "HASH"
@args % 2
ref $args[0] ne "HASH"
Truth table33%1/3
A and B
A= @args % 2B= ref $args[0] ne "HASH"
| |||||||||||||||||||||||||||||
| 107 | 2 | return { @args }; | |||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||
| 110 | 6 | ▶ | sub make_url { | ||||||||||||||||||||||||||
|
Subroutine
make_url: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 111 | 6 | my ( $self, @args ) = @_; | |||||||||||||||||||||||||||
| 112 | 6 | my $url = join('/',$self->base_uri,'protected','json',@args); | |||||||||||||||||||||||||||
| 113 | 6 | my $uri = URI->new($url); | |||||||||||||||||||||||||||
| 114 | 6 | $uri->query_param( api_key => $self->api_key ); | |||||||||||||||||||||||||||
| 115 | 6 | return $uri; | |||||||||||||||||||||||||||
| 116 | } | ||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 2 | ▶ | sub new_user_request { | ||||||||||||||||||||||||||
|
Subroutine
new_user_request: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 119 | 2 | my ( $self, $email, $cellphone, $country_code ) = @_; | |||||||||||||||||||||||||||
| 120 | 2 | my $uri = $self->make_url('users','new'); | |||||||||||||||||||||||||||
| 121 | 2 | my @post = ( | |||||||||||||||||||||||||||
| 122 | 'user[email]' => $email, | ||||||||||||||||||||||||||||
| 123 | 'user[cellphone]' => $cellphone, | ||||||||||||||||||||||||||||
| 124 | ); | ||||||||||||||||||||||||||||
| 125 | 2 | ▶ | push @post, 'user[country_code]' => $country_code if $country_code; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 2 | return POST($uri->as_string, [ @post ]); | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 0 | ▶ | sub new_user { | ||||||||||||||||||||||||||
|
Subroutine
new_user: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 131 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 132 | 0 | $self->clear_errors; | |||||||||||||||||||||||||||
| 133 | 0 | my $response = $self->useragent->request($self->new_user_request(@_)); | |||||||||||||||||||||||||||
| 134 | 0 | my $data = $self->json->decode($response->content); | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($response->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | return $data->{user}->{id}; | |||||||||||||||||||||||||||
| 137 | } else { | ||||||||||||||||||||||||||||
| 138 | 0 | $self->errors($data->{errors}); | |||||||||||||||||||||||||||
| 139 | 0 | return 0; | |||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||
| 143 | 2 | ▶ | sub verify_request { | ||||||||||||||||||||||||||
|
Subroutine
verify_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 144 | 2 | my ( $self, $id, $token ) = @_; | |||||||||||||||||||||||||||
| 145 | 2 | my $uri = $self->make_url('verify',$token,$id); | |||||||||||||||||||||||||||
| 146 | 2 | return GET($uri->as_string); | |||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 0 | ▶ | sub verify { | ||||||||||||||||||||||||||
|
Subroutine
verify: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 151 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 152 | 0 | $self->clear_errors; | |||||||||||||||||||||||||||
| 153 | 0 | my $response = $self->useragent->request($self->verify_request(@_)); | |||||||||||||||||||||||||||
| 154 | 0 | ▶ | if ($response->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | 0 | return 1; | |||||||||||||||||||||||||||
| 156 | } else { | ||||||||||||||||||||||||||||
| 157 | 0 | my $data = $self->json->decode($response->content); | |||||||||||||||||||||||||||
| 158 | 0 | $self->errors($data->{errors}); | |||||||||||||||||||||||||||
| 159 | 0 | return 0; | |||||||||||||||||||||||||||
| 160 | } | ||||||||||||||||||||||||||||
| 161 | } | ||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||
| 163 | 2 | ▶ | sub sms_request { | ||||||||||||||||||||||||||
|
Subroutine
sms_request: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 164 | 2 | my ( $self, $id ) = @_; | |||||||||||||||||||||||||||
| 165 | 2 | my $uri = $self->make_url('sms',$id); | |||||||||||||||||||||||||||
| 166 | 2 | return GET($uri->as_string); | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub sms { | ||||||||||||||||||||||||||
|
Subroutine
sms: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 172 | 0 | $self->clear_errors; | |||||||||||||||||||||||||||
| 173 | 0 | my $response = $self->useragent->request($self->sms_request(@_)); | |||||||||||||||||||||||||||
| 174 | 0 | ▶ | if ($response->is_success) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 175 | 0 | return 1; | |||||||||||||||||||||||||||
| 176 | } else { | ||||||||||||||||||||||||||||
| 177 | 0 | my $data = $self->json->decode($response->content); | |||||||||||||||||||||||||||
| 178 | 0 | $self->errors($data->{errors}); | |||||||||||||||||||||||||||
| 179 | 0 | return 0; | |||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 2 | 1; | |||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | __END__ | ||||||||||||||||||||||||||||