| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Asana::Request; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
1543
|
$WWW::Asana::Request::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$WWW::Asana::Request::VERSION = '0.003'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Asana Request Class |
|
9
|
|
|
|
|
|
|
|
|
10
|
1
|
|
|
|
|
11
|
use MooX qw( |
|
11
|
|
|
|
|
|
|
+HTTP::Request |
|
12
|
|
|
|
|
|
|
+JSON |
|
13
|
|
|
|
|
|
|
+URI |
|
14
|
|
|
|
|
|
|
+URI::QueryParam |
|
15
|
1
|
|
|
1
|
|
12
|
); |
|
|
1
|
|
|
|
|
2
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has api_key => ( |
|
18
|
|
|
|
|
|
|
is => 'ro', |
|
19
|
|
|
|
|
|
|
required => 1, |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
has to => ( |
|
23
|
|
|
|
|
|
|
is => 'ro', |
|
24
|
|
|
|
|
|
|
required => 1, |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has to_type => ( |
|
28
|
|
|
|
|
|
|
is => 'ro', |
|
29
|
|
|
|
|
|
|
lazy => 1, |
|
30
|
|
|
|
|
|
|
builder => 1, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub _build_to_type { |
|
34
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
35
|
0
|
0
|
|
|
|
|
if ( $self->to =~ /\[(\w+)\]/ ) { |
|
36
|
0
|
|
|
|
|
|
return $1; |
|
37
|
|
|
|
|
|
|
} else { |
|
38
|
0
|
|
|
|
|
|
return $self->to; |
|
39
|
|
|
|
|
|
|
} |
|
40
|
|
|
|
|
|
|
} |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
has to_multi => ( |
|
43
|
|
|
|
|
|
|
is => 'ro', |
|
44
|
|
|
|
|
|
|
lazy => 1, |
|
45
|
|
|
|
|
|
|
builder => 1, |
|
46
|
|
|
|
|
|
|
); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub _build_to_multi { |
|
49
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
50
|
0
|
0
|
|
|
|
|
if ( $self->to =~ /\[(\w+)\]/ ) { |
|
51
|
0
|
|
|
|
|
|
return 1; |
|
52
|
|
|
|
|
|
|
} else { |
|
53
|
0
|
|
|
|
|
|
return 0; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
has uri => ( |
|
58
|
|
|
|
|
|
|
is => 'ro', |
|
59
|
|
|
|
|
|
|
required => 1, |
|
60
|
|
|
|
|
|
|
); |
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has data => ( |
|
63
|
|
|
|
|
|
|
is => 'ro', |
|
64
|
|
|
|
|
|
|
predicate => 'has_data', |
|
65
|
|
|
|
|
|
|
); |
|
66
|
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
has params => ( |
|
68
|
|
|
|
|
|
|
is => 'ro', |
|
69
|
|
|
|
|
|
|
predicate => 'has_params', |
|
70
|
|
|
|
|
|
|
); |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
has codes => ( |
|
73
|
|
|
|
|
|
|
is => 'ro', |
|
74
|
|
|
|
|
|
|
predicate => 'has_codes', |
|
75
|
|
|
|
|
|
|
); |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has method => ( |
|
78
|
|
|
|
|
|
|
is => 'ro', |
|
79
|
|
|
|
|
|
|
default => sub { 'GET' } |
|
80
|
|
|
|
|
|
|
); |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
has _http_request => ( |
|
83
|
|
|
|
|
|
|
is => 'ro', |
|
84
|
|
|
|
|
|
|
lazy => 1, |
|
85
|
|
|
|
|
|
|
builder => 1, |
|
86
|
|
|
|
|
|
|
); |
|
87
|
0
|
|
|
0
|
0
|
|
sub http_request { shift->_http_request } |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
has json => ( |
|
90
|
|
|
|
|
|
|
is => 'ro', |
|
91
|
|
|
|
|
|
|
lazy => 1, |
|
92
|
|
|
|
|
|
|
builder => 1, |
|
93
|
|
|
|
|
|
|
); |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub _build_json { |
|
96
|
0
|
|
|
0
|
|
|
my $json = JSON->new; |
|
97
|
0
|
|
|
|
|
|
$json->allow_nonref; |
|
98
|
0
|
|
|
|
|
|
return $json; |
|
99
|
|
|
|
|
|
|
} |
|
100
|
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
sub _build__http_request { |
|
102
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
103
|
0
|
|
|
|
|
|
my %data; |
|
104
|
0
|
0
|
|
|
|
|
%data = %{$self->data} if $self->has_data; |
|
|
0
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my @params; |
|
106
|
0
|
0
|
|
|
|
|
@params = @{$self->params} if $self->has_params; |
|
|
0
|
|
|
|
|
|
|
|
107
|
0
|
0
|
|
|
|
|
if ($self->to_multi) { |
|
108
|
0
|
|
|
|
|
|
my $type = $self->to_type; |
|
109
|
0
|
0
|
|
|
|
|
if ($type eq 'Task') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
110
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
111
|
|
|
|
|
|
|
assignee |
|
112
|
|
|
|
|
|
|
assignee_status |
|
113
|
|
|
|
|
|
|
created_at |
|
114
|
|
|
|
|
|
|
completed |
|
115
|
|
|
|
|
|
|
completed_at |
|
116
|
|
|
|
|
|
|
due_on |
|
117
|
|
|
|
|
|
|
modified_at |
|
118
|
|
|
|
|
|
|
name |
|
119
|
|
|
|
|
|
|
notes |
|
120
|
|
|
|
|
|
|
)) ]; |
|
121
|
|
|
|
|
|
|
} elsif ($type eq 'Story') { |
|
122
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
123
|
|
|
|
|
|
|
created_at |
|
124
|
|
|
|
|
|
|
created_by |
|
125
|
|
|
|
|
|
|
text |
|
126
|
|
|
|
|
|
|
target |
|
127
|
|
|
|
|
|
|
source |
|
128
|
|
|
|
|
|
|
type |
|
129
|
|
|
|
|
|
|
)) ]; |
|
130
|
|
|
|
|
|
|
} elsif ($type eq 'Project') { |
|
131
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
132
|
|
|
|
|
|
|
created_at |
|
133
|
|
|
|
|
|
|
modified_at |
|
134
|
|
|
|
|
|
|
name |
|
135
|
|
|
|
|
|
|
notes |
|
136
|
|
|
|
|
|
|
)) ]; |
|
137
|
|
|
|
|
|
|
} elsif ($type eq 'Tag') { |
|
138
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
139
|
|
|
|
|
|
|
created_at |
|
140
|
|
|
|
|
|
|
name |
|
141
|
|
|
|
|
|
|
notes |
|
142
|
|
|
|
|
|
|
)) ]; |
|
143
|
|
|
|
|
|
|
} elsif ($type eq 'User') { |
|
144
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
145
|
|
|
|
|
|
|
name |
|
146
|
|
|
|
|
|
|
email |
|
147
|
|
|
|
|
|
|
)) ]; |
|
148
|
|
|
|
|
|
|
} elsif ($type eq 'Workspace') { |
|
149
|
0
|
|
|
|
|
|
push @params, [ opt_fields => join(',',qw( |
|
150
|
|
|
|
|
|
|
name |
|
151
|
|
|
|
|
|
|
)) ]; |
|
152
|
|
|
|
|
|
|
} |
|
153
|
|
|
|
|
|
|
} |
|
154
|
0
|
0
|
|
|
|
|
if ($self->has_data) { |
|
155
|
0
|
|
|
|
|
|
$data{$_} = $self->data->{$_} for (keys %{$self->data}); |
|
|
0
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
} |
|
157
|
0
|
|
|
|
|
|
my @headers; |
|
158
|
|
|
|
|
|
|
my $uri; |
|
159
|
0
|
|
|
|
|
|
my $body; |
|
160
|
0
|
|
|
|
|
|
my $u = URI->new($self->uri); |
|
161
|
0
|
|
|
|
|
|
$u->query_param(@{$_}) for @params; |
|
|
0
|
|
|
|
|
|
|
|
162
|
0
|
|
|
|
|
|
$uri = $u->as_string; |
|
163
|
0
|
0
|
|
|
|
|
if ($self->method ne 'GET') { |
|
|
|
0
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
push @headers, ('Content-type', 'application/json'); |
|
165
|
0
|
|
|
|
|
|
$body = $self->json->encode({ data => $self->data }); |
|
166
|
|
|
|
|
|
|
} elsif (%data) { |
|
167
|
0
|
|
|
|
|
|
warn 'Request includes %data but is a GET request'; |
|
168
|
|
|
|
|
|
|
} |
|
169
|
0
|
0
|
|
|
|
|
my $request = HTTP::Request->new( |
|
170
|
|
|
|
|
|
|
$self->method, |
|
171
|
|
|
|
|
|
|
$uri, |
|
172
|
|
|
|
|
|
|
\@headers, |
|
173
|
|
|
|
|
|
|
defined $body ? $body : (), |
|
174
|
|
|
|
|
|
|
); |
|
175
|
0
|
|
|
|
|
|
$request->authorization_basic($self->api_key,""); |
|
176
|
|
|
|
|
|
|
|
|
177
|
|
|
|
|
|
|
# use DDP; |
|
178
|
|
|
|
|
|
|
# p($self->method); |
|
179
|
|
|
|
|
|
|
# p($uri); |
|
180
|
|
|
|
|
|
|
# p($body); |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
# p(%data); |
|
183
|
|
|
|
|
|
|
# p(@params); |
|
184
|
|
|
|
|
|
|
# p($request->uri->as_string); |
|
185
|
|
|
|
|
|
|
# p($request->content); |
|
186
|
|
|
|
|
|
|
|
|
187
|
0
|
|
|
|
|
|
return $request; |
|
188
|
|
|
|
|
|
|
} |
|
189
|
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
1; |
|
191
|
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
__END__ |