| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WWW::Asana; |
|
2
|
|
|
|
|
|
|
BEGIN { |
|
3
|
1
|
|
|
1
|
|
70568
|
$WWW::Asana::AUTHORITY = 'cpan:GETTY'; |
|
4
|
|
|
|
|
|
|
} |
|
5
|
|
|
|
|
|
|
{ |
|
6
|
|
|
|
|
|
|
$WWW::Asana::VERSION = '0.003'; |
|
7
|
|
|
|
|
|
|
} |
|
8
|
|
|
|
|
|
|
# ABSTRACT: Client Class for accessing Asana API |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
1
|
|
|
|
|
9
|
use MooX qw( |
|
12
|
|
|
|
|
|
|
+LWP::UserAgent |
|
13
|
|
|
|
|
|
|
+WWW::Asana::Response |
|
14
|
|
|
|
|
|
|
+WWW::Asana::Request |
|
15
|
|
|
|
|
|
|
+URI |
|
16
|
1
|
|
|
1
|
|
795
|
); |
|
|
1
|
|
|
|
|
42135
|
|
|
17
|
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
710
|
use Carp qw( croak ); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
1543
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our $VERSION ||= '0.000'; |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has api_key => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
required => 1, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has version => ( |
|
30
|
|
|
|
|
|
|
is => 'ro', |
|
31
|
|
|
|
|
|
|
lazy => 1, |
|
32
|
|
|
|
|
|
|
builder => 1, |
|
33
|
|
|
|
|
|
|
); |
|
34
|
|
|
|
|
|
|
|
|
35
|
0
|
|
|
0
|
|
|
sub _build_version { '1.0' } |
|
36
|
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has base_uri => ( |
|
39
|
|
|
|
|
|
|
is => 'ro', |
|
40
|
|
|
|
|
|
|
lazy => 1, |
|
41
|
|
|
|
|
|
|
builder => 1, |
|
42
|
|
|
|
|
|
|
); |
|
43
|
|
|
|
|
|
|
|
|
44
|
0
|
|
|
0
|
|
|
sub _build_base_uri { 'https://app.asana.com/api' } |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has useragent => ( |
|
48
|
|
|
|
|
|
|
is => 'ro', |
|
49
|
|
|
|
|
|
|
lazy => 1, |
|
50
|
|
|
|
|
|
|
builder => 1, |
|
51
|
|
|
|
|
|
|
); |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub _build_useragent { |
|
54
|
0
|
|
|
0
|
|
|
my ( $self ) = @_; |
|
55
|
0
|
0
|
|
|
|
|
LWP::UserAgent->new( |
|
56
|
|
|
|
|
|
|
agent => $self->useragent_agent, |
|
57
|
|
|
|
|
|
|
$self->has_useragent_timeout ? (timeout => $self->useragent_timeout) : (), |
|
58
|
|
|
|
|
|
|
); |
|
59
|
|
|
|
|
|
|
} |
|
60
|
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
has useragent_agent => ( |
|
63
|
|
|
|
|
|
|
is => 'ro', |
|
64
|
|
|
|
|
|
|
lazy => 1, |
|
65
|
|
|
|
|
|
|
builder => 1, |
|
66
|
|
|
|
|
|
|
); |
|
67
|
|
|
|
|
|
|
|
|
68
|
0
|
0
|
|
0
|
|
|
sub _build_useragent_agent { (ref $_[0] ? ref $_[0] : $_[0]).'/'.$VERSION } |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
has useragent_timeout => ( |
|
72
|
|
|
|
|
|
|
is => 'ro', |
|
73
|
|
|
|
|
|
|
predicate => 'has_useragent_timeout', |
|
74
|
|
|
|
|
|
|
); |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has request_class => ( |
|
78
|
|
|
|
|
|
|
is => 'ro', |
|
79
|
|
|
|
|
|
|
lazy => 1, |
|
80
|
|
|
|
|
|
|
builder => 1, |
|
81
|
|
|
|
|
|
|
); |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
0
|
|
|
sub _build_request_class { 'WWW::Asana::Request' } |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
has response_class => ( |
|
87
|
|
|
|
|
|
|
is => 'ro', |
|
88
|
|
|
|
|
|
|
lazy => 1, |
|
89
|
|
|
|
|
|
|
builder => 1, |
|
90
|
|
|
|
|
|
|
); |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
|
|
0
|
|
|
sub _build_response_class { 'WWW::Asana::Response' } |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
############################################################################################################# |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
sub BUILDARGS { |
|
97
|
0
|
|
|
0
|
0
|
|
my ( $class, @args ) = @_; |
|
98
|
0
|
0
|
0
|
|
|
|
unshift @args, "api_key" if @args % 2 && ref $args[0] ne 'HASH'; |
|
99
|
0
|
|
|
|
|
|
return { @args }; |
|
100
|
|
|
|
|
|
|
} |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub request { |
|
104
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
|
105
|
0
|
|
|
|
|
|
my $request; |
|
106
|
0
|
0
|
|
|
|
|
if (ref $args[0] eq $self->request_class) { |
|
107
|
0
|
|
|
|
|
|
$request = $args[0]; |
|
108
|
|
|
|
|
|
|
} else { |
|
109
|
0
|
|
|
|
|
|
$request = $self->get_request(@args); |
|
110
|
|
|
|
|
|
|
} |
|
111
|
0
|
|
|
|
|
|
my $http_response = $self->useragent->request($request->http_request); |
|
112
|
0
|
|
|
|
|
|
my $class_response = $self->response_class; |
|
113
|
0
|
|
|
|
|
|
return $class_response->new($request, $http_response, $request->to, $self); |
|
114
|
|
|
|
|
|
|
} |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_uri { |
|
118
|
0
|
|
|
0
|
0
|
|
my ( $self, @args ) = @_; |
|
119
|
0
|
|
|
|
|
|
return join('/',$self->base_uri,$self->version,@args); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub get_request { |
|
124
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
|
125
|
0
|
|
|
|
|
|
my $to = shift @args; |
|
126
|
0
|
|
|
|
|
|
my $method = shift @args; |
|
127
|
0
|
|
|
|
|
|
my @path_parts; |
|
128
|
|
|
|
|
|
|
my %data; |
|
129
|
0
|
|
|
|
|
|
my @params; |
|
130
|
0
|
|
|
|
|
|
my @codes; |
|
131
|
0
|
|
|
|
|
|
for my $arg (@args) { |
|
132
|
0
|
0
|
|
|
|
|
if (ref $arg eq 'HASH') { |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
133
|
0
|
|
|
|
|
|
$data{$_} = $arg->{$_} for (keys %{$arg}); |
|
|
0
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
} elsif (ref $arg eq 'ARRAY') { |
|
135
|
0
|
|
|
|
|
|
push @params, [@{$arg}]; |
|
|
0
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
} elsif (ref $arg eq 'CODE') { |
|
137
|
0
|
|
|
|
|
|
push @codes, $arg; |
|
138
|
|
|
|
|
|
|
} else { |
|
139
|
0
|
|
|
|
|
|
push @path_parts, $arg; |
|
140
|
|
|
|
|
|
|
} |
|
141
|
|
|
|
|
|
|
} |
|
142
|
0
|
|
|
|
|
|
my $uri = $self->get_uri(@path_parts); |
|
143
|
0
|
|
|
|
|
|
my $request_class = $self->request_class; |
|
144
|
0
|
0
|
|
|
|
|
return $request_class->new( |
|
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
api_key => $self->api_key, |
|
146
|
|
|
|
|
|
|
uri => $uri, |
|
147
|
|
|
|
|
|
|
to => $to, |
|
148
|
|
|
|
|
|
|
method => $method, |
|
149
|
|
|
|
|
|
|
%data ? ( data => \%data ) : (), |
|
150
|
|
|
|
|
|
|
@params ? ( params => \@params ) : (), |
|
151
|
|
|
|
|
|
|
@codes ? ( codes => \@codes ) : (), |
|
152
|
|
|
|
|
|
|
); |
|
153
|
|
|
|
|
|
|
} |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
sub do { |
|
157
|
0
|
|
|
0
|
1
|
|
my ( $self, @args ) = @_; |
|
158
|
0
|
|
|
|
|
|
my $response = $self->request(@args); |
|
159
|
0
|
0
|
|
|
|
|
if ($response->has_errors) { |
|
160
|
0
|
0
|
|
|
|
|
croak "Asana Errors:\n".join("\n",map { $_->message.( $_->has_phrase ? " [phrase:".$_->phrase."]" : "" ) } @{$response->errors})."\n"; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
} |
|
162
|
0
|
|
|
|
|
|
return $response->result; |
|
163
|
|
|
|
|
|
|
} |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
|
|
166
|
0
|
|
|
0
|
0
|
|
sub me_args { 'User','GET','users','me' } |
|
167
|
|
|
|
|
|
|
sub me { |
|
168
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
169
|
0
|
|
|
|
|
|
$self->do($self->me_args(@_)); |
|
170
|
|
|
|
|
|
|
} |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
|
|
173
|
0
|
|
|
0
|
0
|
|
sub users_args { '[User]','GET','users' } |
|
174
|
|
|
|
|
|
|
sub users { |
|
175
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
176
|
0
|
|
|
|
|
|
$self->do($self->users_args(@_)); |
|
177
|
|
|
|
|
|
|
} |
|
178
|
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
|
|
180
|
0
|
|
|
0
|
0
|
|
sub user_args { shift; '[User]','GET','users',shift } |
|
|
0
|
|
|
|
|
|
|
|
181
|
|
|
|
|
|
|
sub user { |
|
182
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
183
|
0
|
|
|
|
|
|
$self->do($self->user_args(@_)); |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
1; |
|
187
|
|
|
|
|
|
|
|
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
__END__ |