line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Name.com API Client |
2
|
|
|
|
|
|
|
package API::Name; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
2397
|
use namespace::autoclean -except => 'has'; |
|
1
|
|
|
|
|
19878
|
|
|
1
|
|
|
|
|
8
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
797
|
use Data::Object::Class; |
|
1
|
|
|
|
|
14671
|
|
|
1
|
|
|
|
|
9
|
|
7
|
1
|
|
|
1
|
|
2413
|
use Data::Object::Class::Syntax; |
|
1
|
|
|
|
|
6395
|
|
|
1
|
|
|
|
|
4
|
|
8
|
1
|
|
|
1
|
|
910
|
use Data::Object::Signatures; |
|
1
|
|
|
|
|
253093
|
|
|
1
|
|
|
|
|
12
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8318
|
use Data::Object qw(load); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
93
|
|
11
|
1
|
|
|
1
|
|
6
|
use Data::Object::Library qw(Str); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
5
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
extends 'API::Client'; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
our $VERSION = '0.05'; # VERSION |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
our $DEFAULT_URL = "https://www.name.com"; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
# ATTRIBUTES |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
has user => rw; |
22
|
|
|
|
|
|
|
has token => rw; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# CONSTRAINTS |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
req user => Str; |
27
|
|
|
|
|
|
|
req token => Str; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# DEFAULTS |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
def identifier => 'API::Name (Perl)'; |
32
|
|
|
|
|
|
|
def url => method { load('Mojo::URL')->new($DEFAULT_URL) }; |
33
|
|
|
|
|
|
|
def version => 1; |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# CONSTRUCTION |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
after BUILD => method { |
38
|
|
|
|
|
|
|
my $identifier = $self->identifier; |
39
|
|
|
|
|
|
|
my $version = $self->version; |
40
|
|
|
|
|
|
|
my $agent = $self->user_agent; |
41
|
|
|
|
|
|
|
my $url = $self->url; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
$agent->transactor->name($identifier); |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# $url->path("/api/$version"); |
46
|
|
|
|
|
|
|
$url->path("/api"); |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
return $self; |
49
|
|
|
|
|
|
|
}; |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
# METHODS |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
0
|
0
|
|
method PREPARE ($ua, $tx, %args) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
my $headers = $tx->req->headers; |
55
|
0
|
|
|
|
|
|
my $url = $tx->req->url; |
56
|
|
|
|
|
|
|
|
57
|
0
|
|
|
|
|
|
my $user = $self->user; |
58
|
0
|
|
|
|
|
|
my $token = $self->token; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
# default headers |
61
|
0
|
|
|
|
|
|
$headers->header('Content-Type' => 'application/json'); |
62
|
0
|
|
|
|
|
|
$headers->header('Api-Username' => $user); |
63
|
0
|
|
|
|
|
|
$headers->header('Api-Token' => $token); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
0
|
|
|
0
|
0
|
|
method resource (@segments) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
# build new resource instance |
68
|
0
|
|
|
|
|
|
my $instance = __PACKAGE__->new( |
69
|
|
|
|
|
|
|
debug => $self->debug, |
70
|
|
|
|
|
|
|
fatal => $self->fatal, |
71
|
|
|
|
|
|
|
retries => $self->retries, |
72
|
|
|
|
|
|
|
timeout => $self->timeout, |
73
|
|
|
|
|
|
|
user_agent => $self->user_agent, |
74
|
|
|
|
|
|
|
identifier => $self->identifier, |
75
|
|
|
|
|
|
|
token => $self->token, |
76
|
|
|
|
|
|
|
user => $self->user, |
77
|
|
|
|
|
|
|
version => $self->version, |
78
|
|
|
|
|
|
|
); |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
# resource locator |
81
|
0
|
|
|
|
|
|
my $url = $instance->url; |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# modify resource locator if possible |
84
|
0
|
|
|
|
|
|
$url->path(join '/', $self->url->path, @segments); |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# return resource instance |
87
|
0
|
|
|
|
|
|
return $instance; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
1; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
__END__ |