line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::Asana::Response; |
2
|
|
|
|
|
|
|
BEGIN { |
3
|
1
|
|
|
1
|
|
140570
|
$WWW::Asana::Response::AUTHORITY = 'cpan:GETTY'; |
4
|
|
|
|
|
|
|
} |
5
|
|
|
|
|
|
|
{ |
6
|
|
|
|
|
|
|
$WWW::Asana::Response::VERSION = '0.003'; |
7
|
|
|
|
|
|
|
} |
8
|
|
|
|
|
|
|
# ABSTRACT: Asana Response Class |
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
17
|
use MooX qw( |
11
|
|
|
|
|
|
|
+WWW::Asana::Error |
12
|
|
|
|
|
|
|
+JSON |
13
|
1
|
|
|
1
|
|
9
|
); |
|
1
|
|
|
|
|
3
|
|
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
1
|
|
61694
|
use Class::Load ':all'; |
|
1
|
|
|
|
|
45301
|
|
|
1
|
|
|
|
|
2226
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
with 'WWW::Asana::Role::HasClient'; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
has request => ( |
20
|
|
|
|
|
|
|
is => 'ro', |
21
|
|
|
|
|
|
|
required => 1, |
22
|
|
|
|
|
|
|
); |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
has http_response => ( |
25
|
|
|
|
|
|
|
is => 'ro', |
26
|
|
|
|
|
|
|
required => 1, |
27
|
|
|
|
|
|
|
handles => [qw( |
28
|
|
|
|
|
|
|
is_success |
29
|
|
|
|
|
|
|
code |
30
|
|
|
|
|
|
|
)], |
31
|
|
|
|
|
|
|
); |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has to => ( |
34
|
|
|
|
|
|
|
is => 'ro', |
35
|
|
|
|
|
|
|
required => 1, |
36
|
|
|
|
|
|
|
); |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has errors => ( |
39
|
|
|
|
|
|
|
is => 'ro', |
40
|
|
|
|
|
|
|
lazy => 1, |
41
|
|
|
|
|
|
|
builder => 1, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
0
|
|
sub has_errors { !shift->is_success } |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub _build_errors { |
47
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
48
|
0
|
0
|
|
|
|
|
return [] unless $self->has_errors; |
49
|
0
|
|
|
|
|
|
my @errors; |
50
|
0
|
0
|
|
|
|
|
if (defined $self->json_decoded_body->{errors}) { |
51
|
0
|
|
|
|
|
|
for (@{$self->json_decoded_body->{errors}}) { |
|
0
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
|
push @errors, WWW::Asana::Error->new( |
53
|
|
|
|
|
|
|
message => $_->{message}, |
54
|
|
|
|
|
|
|
defined $_->{phrase} ? ( phrase => $_->{phrase} ) : (), |
55
|
|
|
|
|
|
|
); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
} |
58
|
0
|
|
|
|
|
|
return \@errors; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
has status_error_message => ( |
62
|
|
|
|
|
|
|
is => 'ro', |
63
|
|
|
|
|
|
|
lazy => 1, |
64
|
|
|
|
|
|
|
builder => 1, |
65
|
|
|
|
|
|
|
); |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
sub _build_status_error_message { |
68
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
69
|
0
|
0
|
|
|
|
|
return if $self->is_success; |
70
|
0
|
0
|
|
|
|
|
return "Invalid request" if $self->code == 400; |
71
|
0
|
0
|
|
|
|
|
return "No authorization" if $self->code == 401; |
72
|
0
|
0
|
|
|
|
|
return "Access denied" if $self->code == 403; |
73
|
0
|
0
|
|
|
|
|
return "Not found" if $self->code == 404; |
74
|
0
|
0
|
|
|
|
|
return "Rate Limit Enforced" if $self->code == 429; |
75
|
0
|
0
|
|
|
|
|
return "Server error" if $self->code == 500; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
has json => ( |
79
|
|
|
|
|
|
|
is => 'ro', |
80
|
|
|
|
|
|
|
lazy => 1, |
81
|
|
|
|
|
|
|
builder => 1, |
82
|
|
|
|
|
|
|
); |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _build_json { |
85
|
0
|
|
|
0
|
|
|
my $json = JSON->new; |
86
|
0
|
|
|
|
|
|
$json->allow_nonref; |
87
|
0
|
|
|
|
|
|
return $json; |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
has json_decoded_body => ( |
91
|
|
|
|
|
|
|
is => 'ro', |
92
|
|
|
|
|
|
|
lazy => 1, |
93
|
|
|
|
|
|
|
builder => 1, |
94
|
|
|
|
|
|
|
); |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub _build_json_decoded_body { |
97
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
98
|
|
|
|
|
|
|
#use DDP; p($self->http_response->content); |
99
|
0
|
|
|
|
|
|
$self->json->decode($self->http_response->content); |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
has data => ( |
103
|
|
|
|
|
|
|
is => 'ro', |
104
|
|
|
|
|
|
|
lazy => 1, |
105
|
|
|
|
|
|
|
builder => 1, |
106
|
|
|
|
|
|
|
); |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
0
|
|
|
sub _build_data { shift->json_decoded_body->{data} } |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
sub BUILDARGS { |
111
|
0
|
|
|
0
|
0
|
|
my ( $class, @args ) = @_; |
112
|
0
|
|
|
|
|
|
my $request = shift @args; |
113
|
0
|
|
|
|
|
|
my $http_response = shift @args; |
114
|
0
|
|
|
|
|
|
my $to = shift @args; |
115
|
0
|
|
|
|
|
|
my $client = shift @args; |
116
|
0
|
|
|
|
|
|
return { request => $request, http_response => $http_response, to => $to, client => $client, @args }; |
117
|
|
|
|
|
|
|
} |
118
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
has result => ( |
120
|
|
|
|
|
|
|
is => 'ro', |
121
|
|
|
|
|
|
|
lazy => 1, |
122
|
|
|
|
|
|
|
builder => 1, |
123
|
|
|
|
|
|
|
); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
sub _build_result { |
126
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
127
|
0
|
|
|
|
|
|
my @codes; |
128
|
0
|
0
|
|
|
|
|
@codes = @{$self->request->codes} if $self->request->has_codes; |
|
0
|
|
|
|
|
|
|
129
|
0
|
0
|
|
|
|
|
if ($self->has_errors) { |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
130
|
0
|
|
|
|
|
|
return $self->errors; |
131
|
|
|
|
|
|
|
} elsif ($self->to eq '') { |
132
|
0
|
|
|
|
|
|
return 1; |
133
|
|
|
|
|
|
|
} elsif ($self->to =~ /\[([\w\d:]+)\]/) { |
134
|
0
|
|
|
|
|
|
my $class = 'WWW::Asana::'.$1; |
135
|
0
|
0
|
|
|
|
|
load_class($class) unless is_class_loaded($class); |
136
|
0
|
|
|
|
|
|
my @results; |
137
|
0
|
|
|
|
|
|
for (@{$self->data}) { |
|
0
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
my %data = %{$_}; |
|
0
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
$data{client} = $self->client if $self->has_client; |
140
|
0
|
|
|
|
|
|
$data{response} = $self; |
141
|
0
|
|
|
|
|
|
for (@codes) { |
142
|
0
|
|
|
|
|
|
my %extra_data = $_->(%data); |
143
|
0
|
|
|
|
|
|
$data{$_} = $extra_data{$_} for (keys %extra_data); |
144
|
|
|
|
|
|
|
} |
145
|
0
|
|
|
|
|
|
push @results, $class->new_from_response(\%data); |
146
|
|
|
|
|
|
|
} |
147
|
0
|
|
|
|
|
|
return \@results; |
148
|
|
|
|
|
|
|
} else { |
149
|
0
|
|
|
|
|
|
my $class = 'WWW::Asana::'.$self->to; |
150
|
0
|
0
|
|
|
|
|
load_class($class) unless is_class_loaded($class); |
151
|
0
|
|
|
|
|
|
my %data = %{$self->data}; |
|
0
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
$data{client} = $self->client if $self->has_client; |
153
|
0
|
|
|
|
|
|
$data{response} = $self; |
154
|
0
|
|
|
|
|
|
for (@codes) { |
155
|
0
|
|
|
|
|
|
my %extra_data = $_->(%data); |
156
|
0
|
|
|
|
|
|
$data{$_} = $extra_data{$_} for (keys %extra_data); |
157
|
|
|
|
|
|
|
} |
158
|
0
|
|
|
|
|
|
return $class->new_from_response(\%data); |
159
|
|
|
|
|
|
|
} |
160
|
|
|
|
|
|
|
} |
161
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
1; |
163
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
__END__ |