| 1 | package Net::Async::Trello; | ||||||||||||||||||||
| 2 | # ABSTRACT: Interaction with the trello.com API | ||||||||||||||||||||
| 3 | |||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 1 | ▶ | use parent qw(IO::Async::Notifier); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 8 | |||||||||||||||||||||
| 9 | 1 | our $VERSION = '0.006'; | |||||||||||||||||||
| 10 | |||||||||||||||||||||
| 11 | =head1 NAME | ||||||||||||||||||||
| 12 | |||||||||||||||||||||
| 13 | Net::Async::Trello - low-level Trello API access | ||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | =head1 DESCRIPTION | ||||||||||||||||||||
| 16 | |||||||||||||||||||||
| 17 | Provides a basic interface for interacting with the L<Trello|https://trello.com> webservice. | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | It's currently a very crude implementation, implementing a small subset of the available API | ||||||||||||||||||||
| 20 | features. | ||||||||||||||||||||
| 21 | |||||||||||||||||||||
| 22 | =cut | ||||||||||||||||||||
| 23 | |||||||||||||||||||||
| 24 | 1 | ▶ | no indirect; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 25 | |||||||||||||||||||||
| 26 | 1 | ▶ | use overload '""' => sub { 'Net::Async::Trello' }, bool => sub { 1 }, fallback => 1; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.6
Subroutine
__ANON__: not called CC=1 SCAR=0.6
| |||||||||||||||||||||
| 27 | |||||||||||||||||||||
| 28 | 1 | ▶ | use Dir::Self; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 1 | ▶ | use curry; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 1 | ▶ | use Future; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 1 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 1 | ▶ | use URI::QueryParam; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 1 | ▶ | use URI::Template; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | 1 | ▶ | use URI::wss; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 35 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | |||||||||||||||||||||
| 37 | 1 | ▶ | use JSON::MaybeUTF8 qw(:v1); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 38 | 1 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | |||||||||||||||||||||
| 40 | 1 | ▶ | use File::ShareDir (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | 1 | ▶ | use Log::Any qw($log); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 42 | 1 | ▶ | use Path::Tiny (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | ▶ | use IO::Async::SSL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | ▶ | use Net::Async::OAuth::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | ▶ | use Net::Async::Trello::WS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | 1 | ▶ | use Net::Async::Trello::Organisation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 1 | ▶ | use Net::Async::Trello::Member; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | use Net::Async::Trello::Board; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | 1 | ▶ | use Net::Async::Trello::Card; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 54 | 1 | ▶ | use Net::Async::Trello::CardAction; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | ▶ | use Net::Async::Trello::List; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | 1 | ▶ | use Ryu::Async; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 58 | 1 | ▶ | use Adapter::Async::OrderedList::Array; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | =head2 me | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | Returns profile information for the current user. | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =cut | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | sub me { | ||||||||||||||||||||
| 67 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
me: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 68 | $self->http_get( | ||||||||||||||||||||
| 69 | uri => URI->new($self->base_uri . 'members/me') | ||||||||||||||||||||
| 70 | )->transform( | ||||||||||||||||||||
| 71 | done => sub { | ||||||||||||||||||||
| 72 | Net::Async::Trello::Member->new( | ||||||||||||||||||||
| 73 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 74 | trello => $self, | ||||||||||||||||||||
| 75 | ) | ||||||||||||||||||||
| 76 | } | ||||||||||||||||||||
| 77 | ) | ||||||||||||||||||||
| 78 | 0 | } | |||||||||||||||||||
| 79 | |||||||||||||||||||||
| 80 | =head2 boards | ||||||||||||||||||||
| 81 | |||||||||||||||||||||
| 82 | Returns a L<Ryu::Source> representing the available boards. | ||||||||||||||||||||
| 83 | |||||||||||||||||||||
| 84 | =cut | ||||||||||||||||||||
| 85 | |||||||||||||||||||||
| 86 | sub boards { | ||||||||||||||||||||
| 87 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
boards: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 88 | 0 | $self->api_get_list( | |||||||||||||||||||
| 89 | endpoint => 'boards', | ||||||||||||||||||||
| 90 | class => 'Net::Async::Trello::Board', | ||||||||||||||||||||
| 91 | ) | ||||||||||||||||||||
| 92 | } | ||||||||||||||||||||
| 93 | |||||||||||||||||||||
| 94 | =head2 board | ||||||||||||||||||||
| 95 | |||||||||||||||||||||
| 96 | Resolves to the board with the corresponding ID. | ||||||||||||||||||||
| 97 | |||||||||||||||||||||
| 98 | Takes the following named parameters: | ||||||||||||||||||||
| 99 | |||||||||||||||||||||
| 100 | =over 4 | ||||||||||||||||||||
| 101 | |||||||||||||||||||||
| 102 | =item * id - the board ID to request | ||||||||||||||||||||
| 103 | |||||||||||||||||||||
| 104 | =back | ||||||||||||||||||||
| 105 | |||||||||||||||||||||
| 106 | Returns a L<Future>. | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =cut | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | sub board { | ||||||||||||||||||||
| 111 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
board: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 112 | 0 | my $id = delete $args{id}; | |||||||||||||||||||
| 113 | 0 | my $uri = URI->new($self->base_uri . 'board/' . $id); | |||||||||||||||||||
| 114 | 0 | $uri->query_param($_ => $args{$_}) for keys %args; | |||||||||||||||||||
| 115 | $self->http_get( | ||||||||||||||||||||
| 116 | uri => $uri | ||||||||||||||||||||
| 117 | )->transform( | ||||||||||||||||||||
| 118 | done => sub { | ||||||||||||||||||||
| 119 | Net::Async::Trello::Board->new( | ||||||||||||||||||||
| 120 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 121 | trello => $self, | ||||||||||||||||||||
| 122 | ) | ||||||||||||||||||||
| 123 | } | ||||||||||||||||||||
| 124 | ) | ||||||||||||||||||||
| 125 | 0 | } | |||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =head2 card | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | Returns information about a specific card. | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | Takes the following named parameters: | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =over 4 | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | =item * C<id> - the card ID to retrieve | ||||||||||||||||||||
| 136 | |||||||||||||||||||||
| 137 | =back | ||||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | Resolves to a L<Net::Async::Trello::Card> instance. | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | =cut | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | sub card { | ||||||||||||||||||||
| 144 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
card: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 145 | 0 | my $id = delete $args{id}; | |||||||||||||||||||
| 146 | 0 | my $uri = URI->new($self->base_uri . 'cards/' . $id); | |||||||||||||||||||
| 147 | 0 | $uri->query_param($_ => delete $args{$_}) for keys %args; | |||||||||||||||||||
| 148 | $self->http_get( | ||||||||||||||||||||
| 149 | uri => $uri, | ||||||||||||||||||||
| 150 | )->transform( | ||||||||||||||||||||
| 151 | done => sub { | ||||||||||||||||||||
| 152 | Net::Async::Trello::Card->new( | ||||||||||||||||||||
| 153 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 154 | trello => $self, | ||||||||||||||||||||
| 155 | ) | ||||||||||||||||||||
| 156 | } | ||||||||||||||||||||
| 157 | ) | ||||||||||||||||||||
| 158 | 0 | } | |||||||||||||||||||
| 159 | |||||||||||||||||||||
| 160 | =head2 member | ||||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | Returns information about a specific person (board/card member). | ||||||||||||||||||||
| 163 | |||||||||||||||||||||
| 164 | Takes the following named parameters: | ||||||||||||||||||||
| 165 | |||||||||||||||||||||
| 166 | =over 4 | ||||||||||||||||||||
| 167 | |||||||||||||||||||||
| 168 | =item * C<id> - the ID to retrieve | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | =back | ||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | Resolves to a L<Net::Async::Trello::Member> instance. | ||||||||||||||||||||
| 173 | |||||||||||||||||||||
| 174 | =cut | ||||||||||||||||||||
| 175 | |||||||||||||||||||||
| 176 | sub member { | ||||||||||||||||||||
| 177 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
member: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 178 | 0 | my $id = delete $args{id}; | |||||||||||||||||||
| 179 | $self->http_get( | ||||||||||||||||||||
| 180 | uri => URI->new($self->base_uri . 'members/' . $id) | ||||||||||||||||||||
| 181 | )->transform( | ||||||||||||||||||||
| 182 | done => sub { | ||||||||||||||||||||
| 183 | Net::Async::Trello::Member->new( | ||||||||||||||||||||
| 184 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 185 | trello => $self, | ||||||||||||||||||||
| 186 | ) | ||||||||||||||||||||
| 187 | } | ||||||||||||||||||||
| 188 | ) | ||||||||||||||||||||
| 189 | 0 | } | |||||||||||||||||||
| 190 | |||||||||||||||||||||
| 191 | =head2 search | ||||||||||||||||||||
| 192 | |||||||||||||||||||||
| 193 | Performs a search for Trello objects by string, see L<https://developers.trello.com/reference/#search> | ||||||||||||||||||||
| 194 | for details on search options available. | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | Example: | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | my (%result) = await $trello->search( | ||||||||||||||||||||
| 199 | card_fields => [ qw(name url dateLastActivity) ], | ||||||||||||||||||||
| 200 | query => 'Shopping List', | ||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||
| 202 | # print the url of the first card returned. | ||||||||||||||||||||
| 203 | my $card = $result{cards}->[0]; | ||||||||||||||||||||
| 204 | # This should be a Net::Async::Trello::Card instance, so we have a ->url method: | ||||||||||||||||||||
| 205 | printf "Card %s url\n", $card->url; | ||||||||||||||||||||
| 206 | |||||||||||||||||||||
| 207 | Takes the arguments as shown in the Trello API documentation as named parameters. | ||||||||||||||||||||
| 208 | |||||||||||||||||||||
| 209 | The only compulsory argument is C<query>, the text string to search for. | ||||||||||||||||||||
| 210 | |||||||||||||||||||||
| 211 | Returns a L<Future> which resolves to a list of key-value pairs. | ||||||||||||||||||||
| 212 | The value will be an instance of the appropriate | ||||||||||||||||||||
| 213 | type, with the exception of C<options> which is a plain hashref. | ||||||||||||||||||||
| 214 | |||||||||||||||||||||
| 215 | =cut | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | sub search { | ||||||||||||||||||||
| 218 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
search: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 219 | 0 | my $uri = $self->endpoint( | |||||||||||||||||||
| 220 | 'search', | ||||||||||||||||||||
| 221 | ); | ||||||||||||||||||||
| 222 | 0 | $uri->query_param($_ => $args{$_}) for keys %args; | |||||||||||||||||||
| 223 | |||||||||||||||||||||
| 224 | $self->http_get( | ||||||||||||||||||||
| 225 | uri => $uri, | ||||||||||||||||||||
| 226 | )->transform( | ||||||||||||||||||||
| 227 | done => sub { | ||||||||||||||||||||
| 228 | 0 | ▶ | my ($results) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 229 | my %types = ( | ||||||||||||||||||||
| 230 | 0 | options => delete($results->{options}), | |||||||||||||||||||
| 231 | ); | ||||||||||||||||||||
| 232 | 0 | for my $type (keys(%{$results})) { | |||||||||||||||||||
| 233 | # Drop the trailing `s` and hope that we don't run into English issues... | ||||||||||||||||||||
| 234 | 0 | my $module_postfix = ucfirst($type =~ s{s$}{}r); | |||||||||||||||||||
| 235 | |||||||||||||||||||||
| 236 | 0 | $types{$type} = []; | |||||||||||||||||||
| 237 | 0 | for my $item (@{$results->{$type}}) { | |||||||||||||||||||
| 238 | 0 | my $class = 'Net::Async::Trello::' . $module_postfix; | |||||||||||||||||||
| 239 | my $object = $class->new( | ||||||||||||||||||||
| 240 | trello => $self, | ||||||||||||||||||||
| 241 | 0 | %{$item}, | |||||||||||||||||||
| 242 | ); | ||||||||||||||||||||
| 243 | 0 | push @{$types{$type}}, $object; | |||||||||||||||||||
| 244 | } | ||||||||||||||||||||
| 245 | } | ||||||||||||||||||||
| 246 | 0 | return %types; | |||||||||||||||||||
| 247 | } | ||||||||||||||||||||
| 248 | ) | ||||||||||||||||||||
| 249 | 0 | } | |||||||||||||||||||
| 250 | |||||||||||||||||||||
| 251 | sub configure { | ||||||||||||||||||||
| 252 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
configure: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 253 | 0 | for my $k (grep exists $args{$_}, qw(key secret token token_secret ws_token)) { | |||||||||||||||||||
| 254 | 0 | $self->{$k} = delete $args{$k}; | |||||||||||||||||||
| 255 | } | ||||||||||||||||||||
| 256 | 0 | $self->SUPER::configure(%args); | |||||||||||||||||||
| 257 | } | ||||||||||||||||||||
| 258 | |||||||||||||||||||||
| 259 | 0 | ▶ | sub ws_token { shift->{ws_token} } | ||||||||||||||||||
|
Subroutine
ws_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 260 | |||||||||||||||||||||
| 261 | 0 | ▶ | sub key { shift->{key} } | ||||||||||||||||||
|
Subroutine
key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 262 | 0 | ▶ | sub secret { shift->{secret} } | ||||||||||||||||||
|
Subroutine
secret: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 263 | 0 | ▶ | sub token { shift->{token} } | ||||||||||||||||||
|
Subroutine
token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 264 | 0 | ▶ | sub token_secret { shift->{token_secret} } | ||||||||||||||||||
|
Subroutine
token_secret: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 265 | |||||||||||||||||||||
| 266 | sub http { | ||||||||||||||||||||
| 267 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
http: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 268 | 0 | ▶ | $self->{http} ||= do { | ||||||||||||||||||
|
Condition0%0/3
$self->{"http"} ||= do {
require Net::Async::HTTP;
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "close_after_request", 0, "max_connections_per_host", 2, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "stall_timeout", 15, "user_agent", "Mozilla/4.0 (perl; Net::Async::Trello; TEAM\@cpan.org)"));
$ua
}
MC/DC0%0/2
$self->{"http"} ||= do {
require Net::Async::HTTP;
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "close_after_request", 0, "max_connections_per_host", 2, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "stall_timeout", 15, "user_agent", "Mozilla/4.0 (perl; Net::Async::Trello; TEAM\@cpan.org)"));
$ua
}
$self->{"http"}
do {
require Net::Async::HTTP;
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "close_after_request", 0, "max_connections_per_host", 2, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "stall_timeout", 15, "user_agent", "Mozilla/4.0 (perl; Net::Async::Trello; TEAM\@cpan.org)"));
$ua
}
Truth table0%0/3
A ||= B
A= $self->{"http"}B= do {
require Net::Async::HTTP;
$self->add_child(my $ua = "Net::Async::HTTP"->new("fail_on_error", 1, "close_after_request", 0, "max_connections_per_host", 2, "pipeline", 1, "max_in_flight", 4, "decode_content", 1, "stall_timeout", 15, "user_agent", "Mozilla/4.0 (perl; Net::Async::Trello; TEAM\@cpan.org)"));
$ua
}
| |||||||||||||||||||||
| 269 | 0 | require Net::Async::HTTP; | |||||||||||||||||||
| 270 | 0 | $self->add_child( | |||||||||||||||||||
| 271 | my $ua = Net::Async::HTTP->new( | ||||||||||||||||||||
| 272 | fail_on_error => 1, | ||||||||||||||||||||
| 273 | close_after_request => 0, | ||||||||||||||||||||
| 274 | max_connections_per_host => 2, | ||||||||||||||||||||
| 275 | pipeline => 1, | ||||||||||||||||||||
| 276 | max_in_flight => 4, | ||||||||||||||||||||
| 277 | decode_content => 1, | ||||||||||||||||||||
| 278 | stall_timeout => 15, | ||||||||||||||||||||
| 279 | user_agent => 'Mozilla/4.0 (perl; Net::Async::Trello; TEAM@cpan.org)', | ||||||||||||||||||||
| 280 | ) | ||||||||||||||||||||
| 281 | ); | ||||||||||||||||||||
| 282 | 0 | $ua | |||||||||||||||||||
| 283 | } | ||||||||||||||||||||
| 284 | } | ||||||||||||||||||||
| 285 | |||||||||||||||||||||
| 286 | =head1 METHODS - Internal | ||||||||||||||||||||
| 287 | |||||||||||||||||||||
| 288 | None of these are likely to be stable or of much use to external callers. | ||||||||||||||||||||
| 289 | |||||||||||||||||||||
| 290 | =cut | ||||||||||||||||||||
| 291 | |||||||||||||||||||||
| 292 | 0 | ▶ | sub base_uri { shift->{base_uri} //= URI->new('https://api.trello.com/1/') } | ||||||||||||||||||
|
Subroutine
base_uri: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
+(shift())->{"base_uri"} //= "URI"->new("https://api.trello.com/1/")
MC/DC0%0/2
+(shift())->{"base_uri"} //= "URI"->new("https://api.trello.com/1/")
+(shift())->{"base_uri"}
"URI"->new("https://api.trello.com/1/")
Truth table0%0/3
A //= B
A= +(shift())->{"base_uri"}B= "URI"->new("https://api.trello.com/1/")
| |||||||||||||||||||||
| 293 | |||||||||||||||||||||
| 294 | 0 | ▶ | sub mime_type { shift->{mime_type} //= 'application/json' } | ||||||||||||||||||
|
Subroutine
mime_type: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/2
+(shift())->{"mime_type"} //= "application/json"
MC/DC0%0/1
+(shift())->{"mime_type"} //= "application/json"
+(shift())->{"mime_type"}
Truth table0%0/2
A
A= +(shift())->{"mime_type"}
| |||||||||||||||||||||
| 295 | |||||||||||||||||||||
| 296 | sub oauth { | ||||||||||||||||||||
| 297 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
oauth: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 298 | 0 | ▶ | $self->{oauth} //= Net::Async::OAuth::Client->new( | ||||||||||||||||||
|
Condition0%0/3
$self->{"oauth"} //= "Net::Async::OAuth::Client"->new("realm", "Trello", "consumer_key", $self->key, "consumer_secret", $self->secret, "token", $self->token, "token_secret", $self->token_secret)
MC/DC0%0/2
$self->{"oauth"} //= "Net::Async::OAuth::Client"->new("realm", "Trello", "consumer_key", $self->key, "consumer_secret", $self->secret, "token", $self->token, "token_secret", $self->token_secret)
$self->{"oauth"}
"Net::Async::OAuth::Client"->new("realm", "Trello", "consumer_key", $self->key, "consumer_secret", $self->secret, "token", $self->token, "token_secret", $self->token_secret)
Truth table0%0/3
A //= B
A= $self->{"oauth"}B= "Net::Async::OAuth::Client"->new("realm", "Trello", "consumer_key", $self->key, "consumer_secret", $self->secret, "token", $self->token, "token_secret", $self->token_secret)
| |||||||||||||||||||||
| 299 | realm => 'Trello', | ||||||||||||||||||||
| 300 | consumer_key => $self->key, | ||||||||||||||||||||
| 301 | consumer_secret => $self->secret, | ||||||||||||||||||||
| 302 | token => $self->token, | ||||||||||||||||||||
| 303 | token_secret => $self->token_secret, | ||||||||||||||||||||
| 304 | ) | ||||||||||||||||||||
| 305 | } | ||||||||||||||||||||
| 306 | |||||||||||||||||||||
| 307 | =head2 endpoints | ||||||||||||||||||||
| 308 | |||||||||||||||||||||
| 309 | =cut | ||||||||||||||||||||
| 310 | |||||||||||||||||||||
| 311 | sub endpoints { | ||||||||||||||||||||
| 312 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
endpoints: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 313 | 0 | ▶ | $self->{endpoints} ||= do { | ||||||||||||||||||
|
Condition0%0/3
$self->{"endpoints"} ||= do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Trello", "endpoints.json")) unless $path->exists;
decode_json_text($path->slurp_utf8)
}
MC/DC0%0/2
$self->{"endpoints"} ||= do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Trello", "endpoints.json")) unless $path->exists;
decode_json_text($path->slurp_utf8)
}
$self->{"endpoints"}
do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Trello", "endpoints.json")) unless $path->exists;
decode_json_text($path->slurp_utf8)
}
Truth table0%0/3
A ||= B
A= $self->{"endpoints"}B= do {
my $path = Path::Tiny::path(&__DIR__())->parent(3)->child("share/endpoints.json");
$path = Path::Tiny::path(File::ShareDir::dist_file("Net-Async-Trello", "endpoints.json")) unless $path->exists;
decode_json_text($path->slurp_utf8)
}
| |||||||||||||||||||||
| 314 | 0 | my $path = Path::Tiny::path(__DIR__)->parent(3)->child('share/endpoints.json'); | |||||||||||||||||||
| 315 | 0 | ▶ | $path = Path::Tiny::path( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 316 | File::ShareDir::dist_file( | ||||||||||||||||||||
| 317 | 'Net-Async-Trello', | ||||||||||||||||||||
| 318 | 'endpoints.json' | ||||||||||||||||||||
| 319 | ) | ||||||||||||||||||||
| 320 | ) unless $path->exists; | ||||||||||||||||||||
| 321 | 0 | decode_json_text($path->slurp_utf8) | |||||||||||||||||||
| 322 | }; | ||||||||||||||||||||
| 323 | } | ||||||||||||||||||||
| 324 | |||||||||||||||||||||
| 325 | =head2 endpoint | ||||||||||||||||||||
| 326 | |||||||||||||||||||||
| 327 | =cut | ||||||||||||||||||||
| 328 | |||||||||||||||||||||
| 329 | sub endpoint { | ||||||||||||||||||||
| 330 | 0 | ▶ | my ($self, $endpoint, %args) = @_; | ||||||||||||||||||
|
Subroutine
endpoint: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 331 | URI::Template->new( | ||||||||||||||||||||
| 332 | 0 | $self->endpoints->{$endpoint . '_url'} | |||||||||||||||||||
| 333 | )->process(%args); | ||||||||||||||||||||
| 334 | } | ||||||||||||||||||||
| 335 | |||||||||||||||||||||
| 336 | sub http_get { | ||||||||||||||||||||
| 337 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 338 | |||||||||||||||||||||
| 339 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 340 | method => 'GET', | ||||||||||||||||||||
| 341 | uri => $args{uri} | ||||||||||||||||||||
| 342 | 0 | ); | |||||||||||||||||||
| 343 | |||||||||||||||||||||
| 344 | 0 | $log->tracef("GET %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 345 | $self->http->GET( | ||||||||||||||||||||
| 346 | (delete $args{uri}), | ||||||||||||||||||||
| 347 | %args | ||||||||||||||||||||
| 348 | )->then(sub { | ||||||||||||||||||||
| 349 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 350 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 351 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 352 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 353 | try { | ||||||||||||||||||||
| 354 | 0 | return Future->done(decode_json_utf8($resp->content)) | |||||||||||||||||||
| 355 | 0 | } catch { | |||||||||||||||||||
| 356 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 357 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 358 | } | ||||||||||||||||||||
| 359 | })->else(sub { | ||||||||||||||||||||
| 360 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 361 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 362 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 363 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 364 | } else { | ||||||||||||||||||||
| 365 | 0 | ▶ | $log->errorf("Other failure (%s): %s", $src // 'unknown', $err); | ||||||||||||||||||
|
Condition0%0/2
$src // "unknown"
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 366 | } | ||||||||||||||||||||
| 367 | 0 | Future->fail(@_); | |||||||||||||||||||
| 368 | }) | ||||||||||||||||||||
| 369 | 0 | } | |||||||||||||||||||
| 370 | |||||||||||||||||||||
| 371 | sub http_post { | ||||||||||||||||||||
| 372 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 373 | |||||||||||||||||||||
| 374 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 375 | method => 'GET', | ||||||||||||||||||||
| 376 | uri => $args{uri} | ||||||||||||||||||||
| 377 | 0 | ); | |||||||||||||||||||
| 378 | |||||||||||||||||||||
| 379 | 0 | $log->tracef("POST %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 380 | $self->http->POST( | ||||||||||||||||||||
| 381 | (delete $args{uri}), | ||||||||||||||||||||
| 382 | encode_json_utf8(delete $args{body}), | ||||||||||||||||||||
| 383 | content_type => 'application/json', | ||||||||||||||||||||
| 384 | %args | ||||||||||||||||||||
| 385 | )->then(sub { | ||||||||||||||||||||
| 386 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 387 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 388 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 389 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 390 | try { | ||||||||||||||||||||
| 391 | 0 | return Future->done(decode_json_utf8($resp->content)) | |||||||||||||||||||
| 392 | 0 | } catch { | |||||||||||||||||||
| 393 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 394 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 395 | } | ||||||||||||||||||||
| 396 | })->else(sub { | ||||||||||||||||||||
| 397 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 398 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 399 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 400 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 401 | } else { | ||||||||||||||||||||
| 402 | 0 | ▶ | $log->errorf("Other failure (%s): %s", $src // 'unknown', $err); | ||||||||||||||||||
|
Condition0%0/2
$src // "unknown"
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 403 | } | ||||||||||||||||||||
| 404 | 0 | Future->fail(@_); | |||||||||||||||||||
| 405 | }) | ||||||||||||||||||||
| 406 | 0 | } | |||||||||||||||||||
| 407 | |||||||||||||||||||||
| 408 | sub http_put { | ||||||||||||||||||||
| 409 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 410 | |||||||||||||||||||||
| 411 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 412 | method => 'PUT', | ||||||||||||||||||||
| 413 | uri => $args{uri} | ||||||||||||||||||||
| 414 | 0 | ); | |||||||||||||||||||
| 415 | |||||||||||||||||||||
| 416 | 0 | $log->tracef("PUT %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 417 | $self->http->PUT( | ||||||||||||||||||||
| 418 | (delete $args{uri}), | ||||||||||||||||||||
| 419 | encode_json_utf8(delete $args{body}), | ||||||||||||||||||||
| 420 | content_type => 'application/json', | ||||||||||||||||||||
| 421 | %args | ||||||||||||||||||||
| 422 | )->then(sub { | ||||||||||||||||||||
| 423 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 424 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 425 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 426 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 427 | try { | ||||||||||||||||||||
| 428 | 0 | return Future->done(decode_json_utf8($resp->content)) | |||||||||||||||||||
| 429 | 0 | } catch { | |||||||||||||||||||
| 430 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 431 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 432 | } | ||||||||||||||||||||
| 433 | })->else(sub { | ||||||||||||||||||||
| 434 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 435 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 436 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 437 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 438 | } else { | ||||||||||||||||||||
| 439 | 0 | ▶ | $log->errorf("Other failure (%s): %s", $src // 'unknown', $err); | ||||||||||||||||||
|
Condition0%0/2
$src // "unknown"
MC/DC0%0/1
$src // "unknown"
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 440 | } | ||||||||||||||||||||
| 441 | 0 | Future->fail(@_); | |||||||||||||||||||
| 442 | }) | ||||||||||||||||||||
| 443 | 0 | } | |||||||||||||||||||
| 444 | |||||||||||||||||||||
| 445 | sub socket_io { | ||||||||||||||||||||
| 446 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
socket_io: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 447 | |||||||||||||||||||||
| 448 | 0 | my $uri = $self->endpoint('socket_io'); | |||||||||||||||||||
| 449 | 0 | $args{headers}{Authorization} = $self->oauth->authorization_header( | |||||||||||||||||||
| 450 | method => 'GET', | ||||||||||||||||||||
| 451 | uri => $uri, | ||||||||||||||||||||
| 452 | ); | ||||||||||||||||||||
| 453 | |||||||||||||||||||||
| 454 | 0 | $log->tracef("GET %s { }", ''. $uri); | |||||||||||||||||||
| 455 | $self->http->GET( | ||||||||||||||||||||
| 456 | $uri, | ||||||||||||||||||||
| 457 | %args | ||||||||||||||||||||
| 458 | )->then(sub { | ||||||||||||||||||||
| 459 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 460 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 461 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 462 | 0 | my @info = split /:/, $resp->decoded_content; | |||||||||||||||||||
| 463 | 0 | ▶ | die "expected websocket" unless $info[3] eq 'websocket'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 464 | 0 | Future->done($info[0]); | |||||||||||||||||||
| 465 | 0 | }); | |||||||||||||||||||
| 466 | } | ||||||||||||||||||||
| 467 | |||||||||||||||||||||
| 468 | sub api_get_list { | ||||||||||||||||||||
| 469 | 1 | ▶ | use Variable::Disposition qw(retain_future); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 470 | 1 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 471 | 1 | ▶ | use Future::Utils qw(fmap0); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 472 | 1 | ▶ | use namespace::clean qw(retain_future refaddr); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 473 | |||||||||||||||||||||
| 474 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
api_get_list: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||
| 475 | my $label = $args{endpoint} | ||||||||||||||||||||
| 476 | 0 | ▶ | ? ('Trello[' . $args{endpoint} . ']') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 477 | : (caller 1)[3]; | ||||||||||||||||||||
| 478 | |||||||||||||||||||||
| 479 | 0 | ▶ | die "Must be a member of a ::Loop" unless $self->loop; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 480 | |||||||||||||||||||||
| 481 | # Hoist our HTTP API call into a source of items | ||||||||||||||||||||
| 482 | 0 | my $src = $self->ryu->source( | |||||||||||||||||||
| 483 | label => $label | ||||||||||||||||||||
| 484 | ); | ||||||||||||||||||||
| 485 | my $uri = $args{endpoint} | ||||||||||||||||||||
| 486 | ? $self->endpoint( | ||||||||||||||||||||
| 487 | $args{endpoint}, | ||||||||||||||||||||
| 488 | 0 | ▶ | %{$args{endpoint_args}} | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 489 | ) | ||||||||||||||||||||
| 490 | : ref($args{uri}) | ||||||||||||||||||||
| 491 | ? $args{uri} | ||||||||||||||||||||
| 492 | : URI->new( | ||||||||||||||||||||
| 493 | $self->base_uri . $args{uri} | ||||||||||||||||||||
| 494 | 0 | ▶ | ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 495 | |||||||||||||||||||||
| 496 | 0 | ▶ | my $per_page = (delete $args{per_page}) || 100; | ||||||||||||||||||
|
Condition0%0/2
delete $args{'per_page'} || 100
MC/DC0%0/1
delete $args{'per_page'} || 100
delete $args{'per_page'}
Truth table0%0/2
A
A= delete $args{'per_page'}
| |||||||||||||||||||||
| 497 | 0 | $uri->query_param( | |||||||||||||||||||
| 498 | limit => $per_page | ||||||||||||||||||||
| 499 | ); | ||||||||||||||||||||
| 500 | my $f = (fmap0 { | ||||||||||||||||||||
| 501 | # $uri->query_param( | ||||||||||||||||||||
| 502 | # before => $per_page | ||||||||||||||||||||
| 503 | # ); | ||||||||||||||||||||
| 504 | $self->http_get( | ||||||||||||||||||||
| 505 | uri => $uri, | ||||||||||||||||||||
| 506 | )->on_done(sub { | ||||||||||||||||||||
| 507 | 0 | ▶ | $log->tracef("we received %s", $_[0]); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 508 | $src->emit( | ||||||||||||||||||||
| 509 | $args{class}->new( | ||||||||||||||||||||
| 510 | %$_, | ||||||||||||||||||||
| 511 | 0 | ($args{extra} ? %{$args{extra}} : ()), | |||||||||||||||||||
| 512 | trello => $self | ||||||||||||||||||||
| 513 | ) | ||||||||||||||||||||
| 514 | 0 | ▶ | ) for @{ $_[0] }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 515 | 0 | $src->finish; | |||||||||||||||||||
| 516 | })->on_fail(sub { | ||||||||||||||||||||
| 517 | 0 | ▶ | $src->fail(@_) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 518 | })->on_cancel(sub { | ||||||||||||||||||||
| 519 | 0 | ▶ | $src->cancel | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 520 | 0 | ▶ | }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 521 | 0 | } foreach => [1]); | |||||||||||||||||||
| 522 | |||||||||||||||||||||
| 523 | # If our source finishes earlier than our HTTP request, then cancel the request | ||||||||||||||||||||
| 524 | $src->completed->on_ready(sub { | ||||||||||||||||||||
| 525 | 0 | ▶ | return if $f->is_ready; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 526 | 0 | $log->tracef("Finishing HTTP request early for %s since our source is no longer active", $label); | |||||||||||||||||||
| 527 | 0 | $f->cancel | |||||||||||||||||||
| 528 | 0 | }); | |||||||||||||||||||
| 529 | |||||||||||||||||||||
| 530 | # Track active requests | ||||||||||||||||||||
| 531 | 0 | my $refaddr = Scalar::Util::refaddr($f); | |||||||||||||||||||
| 532 | retain_future( | ||||||||||||||||||||
| 533 | $self->pending_requests->push([ { | ||||||||||||||||||||
| 534 | id => $refaddr, | ||||||||||||||||||||
| 535 | src => $src, | ||||||||||||||||||||
| 536 | uri => $args{uri}, | ||||||||||||||||||||
| 537 | future => $f, | ||||||||||||||||||||
| 538 | } ])->then(sub { | ||||||||||||||||||||
| 539 | $f->on_ready(sub { | ||||||||||||||||||||
| 540 | retain_future( | ||||||||||||||||||||
| 541 | 0 | ▶ | $self->pending_requests->extract_first_by(sub { $_->{id} == $refaddr }) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 542 | 0 | ▶ | ) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 543 | 0 | ▶ | }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 544 | }) | ||||||||||||||||||||
| 545 | 0 | ); | |||||||||||||||||||
| 546 | 0 | $src | |||||||||||||||||||
| 547 | } | ||||||||||||||||||||
| 548 | |||||||||||||||||||||
| 549 | sub pending_requests { | ||||||||||||||||||||
| 550 | 0 | ▶ | shift->{pending_requests} //= Adapter::Async::OrderedList::Array->new | ||||||||||||||||||
|
Subroutine
pending_requests: not called CC=2 SCAR=17.9
Pod
undocumented
Condition0%0/3
+(shift())->{"pending_requests"} //= "Adapter::Async::OrderedList::Array"->new
MC/DC0%0/2
+(shift())->{"pending_requests"} //= "Adapter::Async::OrderedList::Array"->new
+(shift())->{"pending_requests"}
"Adapter::Async::OrderedList::Array"->new
Truth table0%0/3
A //= B
A= +(shift())->{"pending_requests"}B= "Adapter::Async::OrderedList::Array"->new
| |||||||||||||||||||||
| 551 | } | ||||||||||||||||||||
| 552 | |||||||||||||||||||||
| 553 | 0 | ▶ | sub ryu { shift->{ryu} } | ||||||||||||||||||
|
Subroutine
ryu: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 554 | |||||||||||||||||||||
| 555 | sub _add_to_loop { | ||||||||||||||||||||
| 556 | 0 | ▶ | my ($self, $loop) = @_; | ||||||||||||||||||
|
Subroutine
_add_to_loop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 557 | |||||||||||||||||||||
| 558 | $self->add_child( | ||||||||||||||||||||
| 559 | 0 | $self->{ryu} = Ryu::Async->new | |||||||||||||||||||
| 560 | ); | ||||||||||||||||||||
| 561 | |||||||||||||||||||||
| 562 | } | ||||||||||||||||||||
| 563 | |||||||||||||||||||||
| 564 | sub ws { | ||||||||||||||||||||
| 565 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
ws: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 566 | 0 | ▶ | $self->{ws} //= do { | ||||||||||||||||||
|
Condition0%0/3
$self->{"ws"} //= do {
$self->add_child(my $ws = "Net::Async::Trello::WS"->new("trello", $self, "token", $self->ws_token));
$ws
}
MC/DC0%0/2
$self->{"ws"} //= do {
$self->add_child(my $ws = "Net::Async::Trello::WS"->new("trello", $self, "token", $self->ws_token));
$ws
}
$self->{"ws"}
do {
$self->add_child(my $ws = "Net::Async::Trello::WS"->new("trello", $self, "token", $self->ws_token));
$ws
}
Truth table0%0/3
A //= B
A= $self->{"ws"}B= do {
$self->add_child(my $ws = "Net::Async::Trello::WS"->new("trello", $self, "token", $self->ws_token));
$ws
}
| |||||||||||||||||||||
| 567 | 0 | $self->add_child( | |||||||||||||||||||
| 568 | my $ws = Net::Async::Trello::WS->new( | ||||||||||||||||||||
| 569 | trello => $self, | ||||||||||||||||||||
| 570 | token => $self->ws_token, | ||||||||||||||||||||
| 571 | ) | ||||||||||||||||||||
| 572 | ); | ||||||||||||||||||||
| 573 | 0 | $ws | |||||||||||||||||||
| 574 | } | ||||||||||||||||||||
| 575 | } | ||||||||||||||||||||
| 576 | |||||||||||||||||||||
| 577 | 0 | ▶ | sub websocket { shift->ws->connection } | ||||||||||||||||||
|
Subroutine
websocket: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 578 | |||||||||||||||||||||
| 579 | sub oauth_request { | ||||||||||||||||||||
| 580 | 0 | ▶ | my ($self, $code) = @_; | ||||||||||||||||||
|
Subroutine
oauth_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 581 | |||||||||||||||||||||
| 582 | # We don't provide any scope or expiration details at this point. Those are added to the URI in the browser. | ||||||||||||||||||||
| 583 | 0 | my $uri = URI->new('https://trello.com/1/OAuthGetRequestToken'); | |||||||||||||||||||
| 584 | 0 | my $req = HTTP::Request->new(POST => "$uri"); | |||||||||||||||||||
| 585 | 0 | $req->protocol('HTTP/1.1'); | |||||||||||||||||||
| 586 | |||||||||||||||||||||
| 587 | # $req->header(Authorization => 'Bearer ' . $self->req); | ||||||||||||||||||||
| 588 | 0 | $self->oauth->configure( | |||||||||||||||||||
| 589 | token => '', | ||||||||||||||||||||
| 590 | token_secret => '', | ||||||||||||||||||||
| 591 | ); | ||||||||||||||||||||
| 592 | 0 | my $hdr = $self->oauth->authorization_header( | |||||||||||||||||||
| 593 | method => 'POST', | ||||||||||||||||||||
| 594 | uri => $uri, | ||||||||||||||||||||
| 595 | ); | ||||||||||||||||||||
| 596 | 0 | $req->header('Authorization' => $hdr); | |||||||||||||||||||
| 597 | 0 | $log->tracef("Resulting auth header for userstream was %s", $hdr); | |||||||||||||||||||
| 598 | |||||||||||||||||||||
| 599 | 0 | $req->header('Host' => $uri->host); | |||||||||||||||||||
| 600 | # $req->header('User-Agent' => 'OAuth gem v0.4.4'); | ||||||||||||||||||||
| 601 | 0 | $req->header('Connection' => 'close'); | |||||||||||||||||||
| 602 | 0 | $req->header('Accept' => '*/*'); | |||||||||||||||||||
| 603 | $self->http->do_request( | ||||||||||||||||||||
| 604 | request => $req, | ||||||||||||||||||||
| 605 | )->then(sub { | ||||||||||||||||||||
| 606 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 607 | 0 | $log->debugf("RequestToken response was %s", $resp->as_string("\n")); | |||||||||||||||||||
| 608 | 0 | my $rslt = URI->new('http://localhost?' . $resp->decoded_content)->query_form_hash; | |||||||||||||||||||
| 609 | 0 | $log->debugf("Extracted token [%s]", $rslt->{oauth_token}); | |||||||||||||||||||
| 610 | 0 | $self->oauth->configure(token => $rslt->{oauth_token}); | |||||||||||||||||||
| 611 | 0 | $log->debugf("Extracted secret [%s]", $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 612 | 0 | $self->oauth->configure(token_secret => $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 613 | |||||||||||||||||||||
| 614 | 0 | my $auth_uri = URI->new( | |||||||||||||||||||
| 615 | 'https://trello.com/1/OAuthAuthorizeToken' | ||||||||||||||||||||
| 616 | ); | ||||||||||||||||||||
| 617 | 0 | $auth_uri->query_param(oauth_token => $rslt->{oauth_token}); | |||||||||||||||||||
| 618 | 0 | $auth_uri->query_param(scope => 'read,write'); | |||||||||||||||||||
| 619 | 0 | $auth_uri->query_param(name => 'trelloctl'); | |||||||||||||||||||
| 620 | 0 | $auth_uri->query_param(expiration => 'never'); | |||||||||||||||||||
| 621 | 0 | $code->($auth_uri); | |||||||||||||||||||
| 622 | }, sub { | ||||||||||||||||||||
| 623 | 0 | ▶ | $log->errorf("Failed to do oauth lookup - %s", join ',', @_); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 624 | 0 | die @_; | |||||||||||||||||||
| 625 | })->then(sub { | ||||||||||||||||||||
| 626 | 0 | ▶ | my ($verify) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 627 | 0 | my $uri = URI->new('https://trello.com/1/OAuthGetAccessToken'); | |||||||||||||||||||
| 628 | 0 | my $req = HTTP::Request->new(POST => "$uri"); | |||||||||||||||||||
| 629 | 0 | $req->protocol('HTTP/1.1'); | |||||||||||||||||||
| 630 | |||||||||||||||||||||
| 631 | 0 | my $hdr = $self->oauth->authorization_header( | |||||||||||||||||||
| 632 | method => 'POST', | ||||||||||||||||||||
| 633 | uri => $uri, | ||||||||||||||||||||
| 634 | parameters => { | ||||||||||||||||||||
| 635 | oauth_verifier => $verify | ||||||||||||||||||||
| 636 | } | ||||||||||||||||||||
| 637 | ); | ||||||||||||||||||||
| 638 | 0 | $req->header('Authorization' => $hdr); | |||||||||||||||||||
| 639 | 0 | $log->tracef("Resulting auth header was %s", $hdr); | |||||||||||||||||||
| 640 | |||||||||||||||||||||
| 641 | 0 | $req->header('Host' => $uri->host); | |||||||||||||||||||
| 642 | 0 | $req->header('Connection' => 'close'); | |||||||||||||||||||
| 643 | 0 | $req->header('Accept' => '*/*'); | |||||||||||||||||||
| 644 | 0 | $self->http->do_request( | |||||||||||||||||||
| 645 | request => $req, | ||||||||||||||||||||
| 646 | ) | ||||||||||||||||||||
| 647 | })->then(sub { | ||||||||||||||||||||
| 648 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 649 | 0 | $log->tracef("GetAccessToken response was %s", $resp->as_string("\n")); | |||||||||||||||||||
| 650 | 0 | my $rslt = URI->new('http://localhost?' . $resp->decoded_content)->query_form_hash; | |||||||||||||||||||
| 651 | 0 | $log->tracef("Extracted token [%s]", $rslt->{oauth_token}); | |||||||||||||||||||
| 652 | 0 | $self->configure(token => $rslt->{oauth_token}); | |||||||||||||||||||
| 653 | 0 | $log->tracef("Extracted secret [%s]", $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 654 | 0 | $self->configure(token_secret => $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 655 | Future->done({ | ||||||||||||||||||||
| 656 | token => $rslt->{oauth_token}, | ||||||||||||||||||||
| 657 | token_secret => $rslt->{oauth_token_secret}, | ||||||||||||||||||||
| 658 | }) | ||||||||||||||||||||
| 659 | 0 | }) | |||||||||||||||||||
| 660 | 0 | } | |||||||||||||||||||
| 661 | |||||||||||||||||||||
| 662 | 1 | 1; | |||||||||||||||||||
| 663 | |||||||||||||||||||||
| 664 | __END__ | ||||||||||||||||||||