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