| 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.005'; | |||||||||||||||||||
| 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 Dir::Self; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 27 | 1 | ▶ | use curry; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 28 | 1 | ▶ | use Future; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 29 | 1 | ▶ | use URI; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 30 | 1 | ▶ | use URI::QueryParam; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 31 | 1 | ▶ | use URI::Template; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 32 | 1 | ▶ | use URI::wss; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 33 | 1 | ▶ | use HTTP::Request; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 34 | |||||||||||||||||||||
| 35 | 1 | ▶ | use JSON::MaybeUTF8 qw(:v1); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 36 | 1 | ▶ | use Syntax::Keyword::Try; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | 1 | ▶ | use File::ShareDir (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 39 | 1 | ▶ | use Log::Any qw($log); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 40 | 1 | ▶ | use Path::Tiny (); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 41 | |||||||||||||||||||||
| 42 | 1 | ▶ | use IO::Async::SSL; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | 1 | ▶ | use Net::Async::OAuth::Client; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 45 | |||||||||||||||||||||
| 46 | 1 | ▶ | use Net::Async::Trello::WS; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 47 | |||||||||||||||||||||
| 48 | 1 | ▶ | use Net::Async::Trello::Organisation; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 49 | 1 | ▶ | use Net::Async::Trello::Member; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 50 | 1 | ▶ | use Net::Async::Trello::Board; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 51 | 1 | ▶ | use Net::Async::Trello::Card; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 52 | 1 | ▶ | use Net::Async::Trello::List; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 53 | |||||||||||||||||||||
| 54 | 1 | ▶ | use Ryu::Async; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 55 | 1 | ▶ | use Adapter::Async::OrderedList::Array; | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | =head2 me | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | Returns profile information for the current user. | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =cut | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | sub me { | ||||||||||||||||||||
| 64 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
me: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 65 | $self->http_get( | ||||||||||||||||||||
| 66 | uri => URI->new($self->base_uri . 'members/me') | ||||||||||||||||||||
| 67 | )->transform( | ||||||||||||||||||||
| 68 | done => sub { | ||||||||||||||||||||
| 69 | Net::Async::Trello::Member->new( | ||||||||||||||||||||
| 70 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 71 | trello => $self, | ||||||||||||||||||||
| 72 | ) | ||||||||||||||||||||
| 73 | } | ||||||||||||||||||||
| 74 | ) | ||||||||||||||||||||
| 75 | 0 | } | |||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =head2 boards | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | Returns a L<Ryu::Source> representing the available boards. | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =cut | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | sub boards { | ||||||||||||||||||||
| 84 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
boards: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 85 | 0 | $self->api_get_list( | |||||||||||||||||||
| 86 | endpoint => 'boards', | ||||||||||||||||||||
| 87 | class => 'Net::Async::Trello::Board', | ||||||||||||||||||||
| 88 | ) | ||||||||||||||||||||
| 89 | } | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head2 board | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | Resolves to the board with the corresponding ID. | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | Takes the following named parameters: | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =over 4 | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =item * id - the board ID to request | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =back | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Returns a L<Future>. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =cut | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | sub board { | ||||||||||||||||||||
| 108 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
board: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 109 | 0 | my $id = delete $args{id}; | |||||||||||||||||||
| 110 | 0 | my $uri = URI->new($self->base_uri . 'board/' . $id); | |||||||||||||||||||
| 111 | 0 | $uri->query_param($_ => $args{$_}) for keys %args; | |||||||||||||||||||
| 112 | $self->http_get( | ||||||||||||||||||||
| 113 | uri => $uri | ||||||||||||||||||||
| 114 | )->transform( | ||||||||||||||||||||
| 115 | done => sub { | ||||||||||||||||||||
| 116 | Net::Async::Trello::Board->new( | ||||||||||||||||||||
| 117 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 118 | trello => $self, | ||||||||||||||||||||
| 119 | ) | ||||||||||||||||||||
| 120 | } | ||||||||||||||||||||
| 121 | ) | ||||||||||||||||||||
| 122 | 0 | } | |||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | sub card { | ||||||||||||||||||||
| 125 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
card: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 126 | 0 | my $id = delete $args{id}; | |||||||||||||||||||
| 127 | $self->http_get( | ||||||||||||||||||||
| 128 | uri => URI->new($self->base_uri . 'cards/' . $id) | ||||||||||||||||||||
| 129 | )->transform( | ||||||||||||||||||||
| 130 | done => sub { | ||||||||||||||||||||
| 131 | Net::Async::Trello::Card->new( | ||||||||||||||||||||
| 132 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 133 | trello => $self, | ||||||||||||||||||||
| 134 | ) | ||||||||||||||||||||
| 135 | } | ||||||||||||||||||||
| 136 | ) | ||||||||||||||||||||
| 137 | 0 | } | |||||||||||||||||||
| 138 | |||||||||||||||||||||
| 139 | =head2 search | ||||||||||||||||||||
| 140 | |||||||||||||||||||||
| 141 | Performs a search. | ||||||||||||||||||||
| 142 | |||||||||||||||||||||
| 143 | =cut | ||||||||||||||||||||
| 144 | |||||||||||||||||||||
| 145 | sub search { | ||||||||||||||||||||
| 146 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
search: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 147 | $self->http_get( | ||||||||||||||||||||
| 148 | uri => $self->endpoint( | ||||||||||||||||||||
| 149 | 'search', | ||||||||||||||||||||
| 150 | |||||||||||||||||||||
| 151 | ), | ||||||||||||||||||||
| 152 | )->transform( | ||||||||||||||||||||
| 153 | done => sub { | ||||||||||||||||||||
| 154 | Net::Async::Trello::Card->new( | ||||||||||||||||||||
| 155 | 0 | ▶ | %{ $_[0] }, | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 156 | trello => $self, | ||||||||||||||||||||
| 157 | ) | ||||||||||||||||||||
| 158 | } | ||||||||||||||||||||
| 159 | ) | ||||||||||||||||||||
| 160 | 0 | } | |||||||||||||||||||
| 161 | |||||||||||||||||||||
| 162 | sub configure { | ||||||||||||||||||||
| 163 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
configure: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 164 | 0 | for my $k (grep exists $args{$_}, qw(key secret token token_secret ws_token)) { | |||||||||||||||||||
| 165 | 0 | $self->{$k} = delete $args{$k}; | |||||||||||||||||||
| 166 | } | ||||||||||||||||||||
| 167 | 0 | $self->SUPER::configure(%args); | |||||||||||||||||||
| 168 | } | ||||||||||||||||||||
| 169 | |||||||||||||||||||||
| 170 | 0 | ▶ | sub ws_token { shift->{ws_token} } | ||||||||||||||||||
|
Subroutine
ws_token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 171 | |||||||||||||||||||||
| 172 | 0 | ▶ | sub key { shift->{key} } | ||||||||||||||||||
|
Subroutine
key: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 173 | 0 | ▶ | sub secret { shift->{secret} } | ||||||||||||||||||
|
Subroutine
secret: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 174 | 0 | ▶ | sub token { shift->{token} } | ||||||||||||||||||
|
Subroutine
token: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 175 | 0 | ▶ | sub token_secret { shift->{token_secret} } | ||||||||||||||||||
|
Subroutine
token_secret: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 176 | |||||||||||||||||||||
| 177 | sub http { | ||||||||||||||||||||
| 178 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
http: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 179 | 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, "max_connections_per_host", 2, "pipeline", 0, "max_in_flight", 4, "decode_content", 1, "timeout", 30, "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, "max_connections_per_host", 2, "pipeline", 0, "max_in_flight", 4, "decode_content", 1, "timeout", 30, "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, "max_connections_per_host", 2, "pipeline", 0, "max_in_flight", 4, "decode_content", 1, "timeout", 30, "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, "max_connections_per_host", 2, "pipeline", 0, "max_in_flight", 4, "decode_content", 1, "timeout", 30, "user_agent", "Mozilla/4.0 (perl; Net::Async::Trello; TEAM\@cpan.org)"));
$ua
}
| |||||||||||||||||||||
| 180 | 0 | require Net::Async::HTTP; | |||||||||||||||||||
| 181 | 0 | $self->add_child( | |||||||||||||||||||
| 182 | my $ua = Net::Async::HTTP->new( | ||||||||||||||||||||
| 183 | fail_on_error => 1, | ||||||||||||||||||||
| 184 | max_connections_per_host => 2, | ||||||||||||||||||||
| 185 | pipeline => 0, | ||||||||||||||||||||
| 186 | max_in_flight => 4, | ||||||||||||||||||||
| 187 | decode_content => 1, | ||||||||||||||||||||
| 188 | timeout => 30, | ||||||||||||||||||||
| 189 | user_agent => 'Mozilla/4.0 (perl; Net::Async::Trello; TEAM@cpan.org)', | ||||||||||||||||||||
| 190 | ) | ||||||||||||||||||||
| 191 | ); | ||||||||||||||||||||
| 192 | 0 | $ua | |||||||||||||||||||
| 193 | } | ||||||||||||||||||||
| 194 | } | ||||||||||||||||||||
| 195 | |||||||||||||||||||||
| 196 | =head1 METHODS - Internal | ||||||||||||||||||||
| 197 | |||||||||||||||||||||
| 198 | None of these are likely to be stable or of much use to external callers. | ||||||||||||||||||||
| 199 | |||||||||||||||||||||
| 200 | =cut | ||||||||||||||||||||
| 201 | |||||||||||||||||||||
| 202 | 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/")
| |||||||||||||||||||||
| 203 | |||||||||||||||||||||
| 204 | 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"}
| |||||||||||||||||||||
| 205 | |||||||||||||||||||||
| 206 | sub oauth { | ||||||||||||||||||||
| 207 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
oauth: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 208 | 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)
| |||||||||||||||||||||
| 209 | realm => 'Trello', | ||||||||||||||||||||
| 210 | consumer_key => $self->key, | ||||||||||||||||||||
| 211 | consumer_secret => $self->secret, | ||||||||||||||||||||
| 212 | token => $self->token, | ||||||||||||||||||||
| 213 | token_secret => $self->token_secret, | ||||||||||||||||||||
| 214 | ) | ||||||||||||||||||||
| 215 | } | ||||||||||||||||||||
| 216 | |||||||||||||||||||||
| 217 | =head2 endpoints | ||||||||||||||||||||
| 218 | |||||||||||||||||||||
| 219 | =cut | ||||||||||||||||||||
| 220 | |||||||||||||||||||||
| 221 | sub endpoints { | ||||||||||||||||||||
| 222 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
endpoints: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||
| 223 | 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)
}
| |||||||||||||||||||||
| 224 | 0 | my $path = Path::Tiny::path(__DIR__)->parent(3)->child('share/endpoints.json'); | |||||||||||||||||||
| 225 | 0 | ▶ | $path = Path::Tiny::path( | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 226 | File::ShareDir::dist_file( | ||||||||||||||||||||
| 227 | 'Net-Async-Trello', | ||||||||||||||||||||
| 228 | 'endpoints.json' | ||||||||||||||||||||
| 229 | ) | ||||||||||||||||||||
| 230 | ) unless $path->exists; | ||||||||||||||||||||
| 231 | 0 | decode_json_text($path->slurp_utf8) | |||||||||||||||||||
| 232 | }; | ||||||||||||||||||||
| 233 | } | ||||||||||||||||||||
| 234 | |||||||||||||||||||||
| 235 | =head2 endpoint | ||||||||||||||||||||
| 236 | |||||||||||||||||||||
| 237 | =cut | ||||||||||||||||||||
| 238 | |||||||||||||||||||||
| 239 | sub endpoint { | ||||||||||||||||||||
| 240 | 0 | ▶ | my ($self, $endpoint, %args) = @_; | ||||||||||||||||||
|
Subroutine
endpoint: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 241 | URI::Template->new( | ||||||||||||||||||||
| 242 | 0 | $self->endpoints->{$endpoint . '_url'} | |||||||||||||||||||
| 243 | )->process(%args); | ||||||||||||||||||||
| 244 | } | ||||||||||||||||||||
| 245 | |||||||||||||||||||||
| 246 | sub http_get { | ||||||||||||||||||||
| 247 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_get: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 248 | |||||||||||||||||||||
| 249 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 250 | method => 'GET', | ||||||||||||||||||||
| 251 | uri => $args{uri} | ||||||||||||||||||||
| 252 | 0 | ); | |||||||||||||||||||
| 253 | |||||||||||||||||||||
| 254 | 0 | $log->tracef("GET %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 255 | $self->http->GET( | ||||||||||||||||||||
| 256 | (delete $args{uri}), | ||||||||||||||||||||
| 257 | %args | ||||||||||||||||||||
| 258 | )->then(sub { | ||||||||||||||||||||
| 259 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 260 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 261 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 262 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 263 | try { | ||||||||||||||||||||
| 264 | 0 | return Future->done(decode_json_utf8($resp->decoded_content)) | |||||||||||||||||||
| 265 | 0 | } catch { | |||||||||||||||||||
| 266 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 267 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 268 | } | ||||||||||||||||||||
| 269 | })->else(sub { | ||||||||||||||||||||
| 270 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 271 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 272 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 273 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 274 | } else { | ||||||||||||||||||||
| 275 | 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
| |||||||||||||||||||||
| 276 | } | ||||||||||||||||||||
| 277 | 0 | Future->fail(@_); | |||||||||||||||||||
| 278 | }) | ||||||||||||||||||||
| 279 | 0 | } | |||||||||||||||||||
| 280 | |||||||||||||||||||||
| 281 | sub http_post { | ||||||||||||||||||||
| 282 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_post: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 283 | |||||||||||||||||||||
| 284 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 285 | method => 'GET', | ||||||||||||||||||||
| 286 | uri => $args{uri} | ||||||||||||||||||||
| 287 | 0 | ); | |||||||||||||||||||
| 288 | |||||||||||||||||||||
| 289 | 0 | $log->tracef("POST %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 290 | $self->http->POST( | ||||||||||||||||||||
| 291 | (delete $args{uri}), | ||||||||||||||||||||
| 292 | encode_json_utf8(delete $args{body}), | ||||||||||||||||||||
| 293 | content_type => 'application/json', | ||||||||||||||||||||
| 294 | %args | ||||||||||||||||||||
| 295 | )->then(sub { | ||||||||||||||||||||
| 296 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 297 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 298 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 299 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 300 | try { | ||||||||||||||||||||
| 301 | 0 | return Future->done(decode_json_utf8($resp->decoded_content)) | |||||||||||||||||||
| 302 | 0 | } catch { | |||||||||||||||||||
| 303 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 304 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 305 | } | ||||||||||||||||||||
| 306 | })->else(sub { | ||||||||||||||||||||
| 307 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 308 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 309 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 310 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 311 | } else { | ||||||||||||||||||||
| 312 | 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
| |||||||||||||||||||||
| 313 | } | ||||||||||||||||||||
| 314 | 0 | Future->fail(@_); | |||||||||||||||||||
| 315 | }) | ||||||||||||||||||||
| 316 | 0 | } | |||||||||||||||||||
| 317 | |||||||||||||||||||||
| 318 | sub http_put { | ||||||||||||||||||||
| 319 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
http_put: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 320 | |||||||||||||||||||||
| 321 | $args{headers}{Authorization} = $self->oauth->authorization_header( | ||||||||||||||||||||
| 322 | method => 'PUT', | ||||||||||||||||||||
| 323 | uri => $args{uri} | ||||||||||||||||||||
| 324 | 0 | ); | |||||||||||||||||||
| 325 | |||||||||||||||||||||
| 326 | 0 | $log->tracef("PUT %s { %s }", ''. $args{uri}, \%args); | |||||||||||||||||||
| 327 | $self->http->PUT( | ||||||||||||||||||||
| 328 | (delete $args{uri}), | ||||||||||||||||||||
| 329 | encode_json_utf8(delete $args{body}), | ||||||||||||||||||||
| 330 | content_type => 'application/json', | ||||||||||||||||||||
| 331 | %args | ||||||||||||||||||||
| 332 | )->then(sub { | ||||||||||||||||||||
| 333 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 334 | 0 | $log->tracef("%s => %s", $args{uri}, $resp->decoded_content); | |||||||||||||||||||
| 335 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 336 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 337 | try { | ||||||||||||||||||||
| 338 | 0 | return Future->done(decode_json_utf8($resp->decoded_content)) | |||||||||||||||||||
| 339 | 0 | } catch { | |||||||||||||||||||
| 340 | 0 | $log->errorf("JSON decoding error %s from HTTP response %s", $@, $resp->as_string("\n")); | |||||||||||||||||||
| 341 | 0 | return Future->fail($@ => json => $resp); | |||||||||||||||||||
| 342 | } | ||||||||||||||||||||
| 343 | })->else(sub { | ||||||||||||||||||||
| 344 | 0 | ▶ | my ($err, $src, $resp, $req) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 345 | 0 | ▶ | $src //= ''; | ||||||||||||||||||
|
Condition0%0/2
$src //= ""
MC/DC0%0/1
$src //= ""
$src
Truth table0%0/2
A
A= $src
| |||||||||||||||||||||
| 346 | 0 | ▶ | if($src eq 'http') { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 347 | 0 | $log->errorf("HTTP error %s, request was %s with response %s", $err, $req->as_string("\n"), $resp->as_string("\n")); | |||||||||||||||||||
| 348 | } else { | ||||||||||||||||||||
| 349 | 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
| |||||||||||||||||||||
| 350 | } | ||||||||||||||||||||
| 351 | 0 | Future->fail(@_); | |||||||||||||||||||
| 352 | }) | ||||||||||||||||||||
| 353 | 0 | } | |||||||||||||||||||
| 354 | |||||||||||||||||||||
| 355 | sub socket_io { | ||||||||||||||||||||
| 356 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
socket_io: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 357 | |||||||||||||||||||||
| 358 | 0 | my $uri = $self->endpoint('socket_io'); | |||||||||||||||||||
| 359 | 0 | $args{headers}{Authorization} = $self->oauth->authorization_header( | |||||||||||||||||||
| 360 | method => 'GET', | ||||||||||||||||||||
| 361 | uri => $uri, | ||||||||||||||||||||
| 362 | ); | ||||||||||||||||||||
| 363 | |||||||||||||||||||||
| 364 | 0 | $log->tracef("GET %s { }", ''. $uri); | |||||||||||||||||||
| 365 | $self->http->GET( | ||||||||||||||||||||
| 366 | $uri, | ||||||||||||||||||||
| 367 | %args | ||||||||||||||||||||
| 368 | )->then(sub { | ||||||||||||||||||||
| 369 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=4 SCAR=30.0
| |||||||||||||||||||||
| 370 | 0 | ▶ | return { } if $resp->code == 204; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 371 | 0 | ▶ | return { } if 3 == ($resp->code / 100); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 372 | 0 | my @info = split /:/, $resp->decoded_content; | |||||||||||||||||||
| 373 | 0 | ▶ | die "expected websocket" unless $info[3] eq 'websocket'; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 374 | 0 | Future->done($info[0]); | |||||||||||||||||||
| 375 | 0 | }); | |||||||||||||||||||
| 376 | } | ||||||||||||||||||||
| 377 | |||||||||||||||||||||
| 378 | sub api_get_list { | ||||||||||||||||||||
| 379 | 1 | ▶ | use Variable::Disposition qw(retain_future); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 380 | 1 | ▶ | use Scalar::Util qw(refaddr); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 381 | 1 | ▶ | use Future::Utils qw(fmap0); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 382 | 1 | ▶ | use namespace::clean qw(retain_future refaddr); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 383 | |||||||||||||||||||||
| 384 | 0 | ▶ | my ($self, %args) = @_; | ||||||||||||||||||
|
Subroutine
api_get_list: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||
| 385 | my $label = $args{endpoint} | ||||||||||||||||||||
| 386 | 0 | ▶ | ? ('Trello[' . $args{endpoint} . ']') | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 387 | : (caller 1)[3]; | ||||||||||||||||||||
| 388 | |||||||||||||||||||||
| 389 | 0 | ▶ | die "Must be a member of a ::Loop" unless $self->loop; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 390 | |||||||||||||||||||||
| 391 | # Hoist our HTTP API call into a source of items | ||||||||||||||||||||
| 392 | 0 | my $src = $self->ryu->source( | |||||||||||||||||||
| 393 | label => $label | ||||||||||||||||||||
| 394 | ); | ||||||||||||||||||||
| 395 | my $uri = $args{endpoint} | ||||||||||||||||||||
| 396 | ? $self->endpoint( | ||||||||||||||||||||
| 397 | $args{endpoint}, | ||||||||||||||||||||
| 398 | 0 | %{$args{endpoint_args}} | |||||||||||||||||||
| 399 | ) : URI->new( | ||||||||||||||||||||
| 400 | $self->base_uri . $args{uri} | ||||||||||||||||||||
| 401 | 0 | ▶ | ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 402 | |||||||||||||||||||||
| 403 | 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'}
| |||||||||||||||||||||
| 404 | 0 | $uri->query_param( | |||||||||||||||||||
| 405 | limit => $per_page | ||||||||||||||||||||
| 406 | ); | ||||||||||||||||||||
| 407 | my $f = (fmap0 { | ||||||||||||||||||||
| 408 | # $uri->query_param( | ||||||||||||||||||||
| 409 | # before => $per_page | ||||||||||||||||||||
| 410 | # ); | ||||||||||||||||||||
| 411 | $self->http_get( | ||||||||||||||||||||
| 412 | uri => $uri, | ||||||||||||||||||||
| 413 | )->on_done(sub { | ||||||||||||||||||||
| 414 | 0 | ▶ | $log->tracef("we received %s", $_[0]); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||
| 415 | $src->emit( | ||||||||||||||||||||
| 416 | $args{class}->new( | ||||||||||||||||||||
| 417 | %$_, | ||||||||||||||||||||
| 418 | 0 | ($args{extra} ? %{$args{extra}} : ()), | |||||||||||||||||||
| 419 | trello => $self | ||||||||||||||||||||
| 420 | ) | ||||||||||||||||||||
| 421 | 0 | ▶ | ) for @{ $_[0] }; | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 422 | 0 | $src->finish; | |||||||||||||||||||
| 423 | })->on_fail(sub { | ||||||||||||||||||||
| 424 | 0 | ▶ | $src->fail(@_) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 425 | })->on_cancel(sub { | ||||||||||||||||||||
| 426 | 0 | ▶ | $src->cancel | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 427 | 0 | ▶ | }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 428 | 0 | } foreach => [1]); | |||||||||||||||||||
| 429 | |||||||||||||||||||||
| 430 | # If our source finishes earlier than our HTTP request, then cancel the request | ||||||||||||||||||||
| 431 | $src->completed->on_ready(sub { | ||||||||||||||||||||
| 432 | 0 | ▶ | return if $f->is_ready; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||
| 433 | 0 | $log->tracef("Finishing HTTP request early for %s since our source is no longer active", $label); | |||||||||||||||||||
| 434 | 0 | $f->cancel | |||||||||||||||||||
| 435 | 0 | }); | |||||||||||||||||||
| 436 | |||||||||||||||||||||
| 437 | # Track active requests | ||||||||||||||||||||
| 438 | 0 | my $refaddr = Scalar::Util::refaddr($f); | |||||||||||||||||||
| 439 | retain_future( | ||||||||||||||||||||
| 440 | $self->pending_requests->push([ { | ||||||||||||||||||||
| 441 | id => $refaddr, | ||||||||||||||||||||
| 442 | src => $src, | ||||||||||||||||||||
| 443 | uri => $args{uri}, | ||||||||||||||||||||
| 444 | future => $f, | ||||||||||||||||||||
| 445 | } ])->then(sub { | ||||||||||||||||||||
| 446 | $f->on_ready(sub { | ||||||||||||||||||||
| 447 | retain_future( | ||||||||||||||||||||
| 448 | 0 | ▶ | $self->pending_requests->extract_first_by(sub { $_->{id} == $refaddr }) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 449 | 0 | ▶ | ) | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 450 | 0 | ▶ | }); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 451 | }) | ||||||||||||||||||||
| 452 | 0 | ); | |||||||||||||||||||
| 453 | 0 | $src | |||||||||||||||||||
| 454 | } | ||||||||||||||||||||
| 455 | |||||||||||||||||||||
| 456 | sub pending_requests { | ||||||||||||||||||||
| 457 | 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
| |||||||||||||||||||||
| 458 | } | ||||||||||||||||||||
| 459 | |||||||||||||||||||||
| 460 | 0 | ▶ | sub ryu { shift->{ryu} } | ||||||||||||||||||
|
Subroutine
ryu: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 461 | |||||||||||||||||||||
| 462 | sub _add_to_loop { | ||||||||||||||||||||
| 463 | 0 | ▶ | my ($self, $loop) = @_; | ||||||||||||||||||
|
Subroutine
_add_to_loop: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 464 | |||||||||||||||||||||
| 465 | $self->add_child( | ||||||||||||||||||||
| 466 | 0 | $self->{ryu} = Ryu::Async->new | |||||||||||||||||||
| 467 | ); | ||||||||||||||||||||
| 468 | |||||||||||||||||||||
| 469 | } | ||||||||||||||||||||
| 470 | |||||||||||||||||||||
| 471 | sub ws { | ||||||||||||||||||||
| 472 | 0 | ▶ | my ($self) = @_; | ||||||||||||||||||
|
Subroutine
ws: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||
| 473 | 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
}
| |||||||||||||||||||||
| 474 | 0 | $self->add_child( | |||||||||||||||||||
| 475 | my $ws = Net::Async::Trello::WS->new( | ||||||||||||||||||||
| 476 | trello => $self, | ||||||||||||||||||||
| 477 | token => $self->ws_token, | ||||||||||||||||||||
| 478 | ) | ||||||||||||||||||||
| 479 | ); | ||||||||||||||||||||
| 480 | 0 | $ws | |||||||||||||||||||
| 481 | } | ||||||||||||||||||||
| 482 | } | ||||||||||||||||||||
| 483 | |||||||||||||||||||||
| 484 | 0 | ▶ | sub websocket { shift->ws->connection } | ||||||||||||||||||
|
Subroutine
websocket: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 485 | |||||||||||||||||||||
| 486 | sub oauth_request { | ||||||||||||||||||||
| 487 | 0 | ▶ | my ($self, $code) = @_; | ||||||||||||||||||
|
Subroutine
oauth_request: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||
| 488 | |||||||||||||||||||||
| 489 | # We don't provide any scope or expiration details at this point. Those are added to the URI in the browser. | ||||||||||||||||||||
| 490 | 0 | my $uri = URI->new('https://trello.com/1/OAuthGetRequestToken'); | |||||||||||||||||||
| 491 | 0 | my $req = HTTP::Request->new(POST => "$uri"); | |||||||||||||||||||
| 492 | 0 | $req->protocol('HTTP/1.1'); | |||||||||||||||||||
| 493 | |||||||||||||||||||||
| 494 | # $req->header(Authorization => 'Bearer ' . $self->req); | ||||||||||||||||||||
| 495 | 0 | $self->oauth->configure( | |||||||||||||||||||
| 496 | token => '', | ||||||||||||||||||||
| 497 | token_secret => '', | ||||||||||||||||||||
| 498 | ); | ||||||||||||||||||||
| 499 | 0 | my $hdr = $self->oauth->authorization_header( | |||||||||||||||||||
| 500 | method => 'POST', | ||||||||||||||||||||
| 501 | uri => $uri, | ||||||||||||||||||||
| 502 | ); | ||||||||||||||||||||
| 503 | 0 | $req->header('Authorization' => $hdr); | |||||||||||||||||||
| 504 | 0 | $log->tracef("Resulting auth header for userstream was %s", $hdr); | |||||||||||||||||||
| 505 | |||||||||||||||||||||
| 506 | 0 | $req->header('Host' => $uri->host); | |||||||||||||||||||
| 507 | # $req->header('User-Agent' => 'OAuth gem v0.4.4'); | ||||||||||||||||||||
| 508 | 0 | $req->header('Connection' => 'close'); | |||||||||||||||||||
| 509 | 0 | $req->header('Accept' => '*/*'); | |||||||||||||||||||
| 510 | $self->http->do_request( | ||||||||||||||||||||
| 511 | request => $req, | ||||||||||||||||||||
| 512 | )->then(sub { | ||||||||||||||||||||
| 513 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 514 | 0 | $log->debugf("RequestToken response was %s", $resp->as_string("\n")); | |||||||||||||||||||
| 515 | 0 | my $rslt = URI->new('http://localhost?' . $resp->decoded_content)->query_form_hash; | |||||||||||||||||||
| 516 | 0 | $log->debugf("Extracted token [%s]", $rslt->{oauth_token}); | |||||||||||||||||||
| 517 | 0 | $self->oauth->configure(token => $rslt->{oauth_token}); | |||||||||||||||||||
| 518 | 0 | $log->debugf("Extracted secret [%s]", $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 519 | 0 | $self->oauth->configure(token_secret => $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 520 | |||||||||||||||||||||
| 521 | 0 | my $auth_uri = URI->new( | |||||||||||||||||||
| 522 | 'https://trello.com/1/OAuthAuthorizeToken' | ||||||||||||||||||||
| 523 | ); | ||||||||||||||||||||
| 524 | 0 | $auth_uri->query_param(oauth_token => $rslt->{oauth_token}); | |||||||||||||||||||
| 525 | 0 | $auth_uri->query_param(scope => 'read,write'); | |||||||||||||||||||
| 526 | 0 | $auth_uri->query_param(name => 'trelloctl'); | |||||||||||||||||||
| 527 | 0 | $auth_uri->query_param(expiration => 'never'); | |||||||||||||||||||
| 528 | 0 | $code->($auth_uri); | |||||||||||||||||||
| 529 | }, sub { | ||||||||||||||||||||
| 530 | 0 | ▶ | $log->errorf("Failed to do oauth lookup - %s", join ',', @_); | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 531 | 0 | die @_; | |||||||||||||||||||
| 532 | })->then(sub { | ||||||||||||||||||||
| 533 | 0 | ▶ | my ($verify) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 534 | 0 | my $uri = URI->new('https://trello.com/1/OAuthGetAccessToken'); | |||||||||||||||||||
| 535 | 0 | my $req = HTTP::Request->new(POST => "$uri"); | |||||||||||||||||||
| 536 | 0 | $req->protocol('HTTP/1.1'); | |||||||||||||||||||
| 537 | |||||||||||||||||||||
| 538 | 0 | my $hdr = $self->oauth->authorization_header( | |||||||||||||||||||
| 539 | method => 'POST', | ||||||||||||||||||||
| 540 | uri => $uri, | ||||||||||||||||||||
| 541 | parameters => { | ||||||||||||||||||||
| 542 | oauth_verifier => $verify | ||||||||||||||||||||
| 543 | } | ||||||||||||||||||||
| 544 | ); | ||||||||||||||||||||
| 545 | 0 | $req->header('Authorization' => $hdr); | |||||||||||||||||||
| 546 | 0 | $log->tracef("Resulting auth header was %s", $hdr); | |||||||||||||||||||
| 547 | |||||||||||||||||||||
| 548 | 0 | $req->header('Host' => $uri->host); | |||||||||||||||||||
| 549 | 0 | $req->header('Connection' => 'close'); | |||||||||||||||||||
| 550 | 0 | $req->header('Accept' => '*/*'); | |||||||||||||||||||
| 551 | 0 | $self->http->do_request( | |||||||||||||||||||
| 552 | request => $req, | ||||||||||||||||||||
| 553 | ) | ||||||||||||||||||||
| 554 | })->then(sub { | ||||||||||||||||||||
| 555 | 0 | ▶ | my ($resp) = @_; | ||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||
| 556 | 0 | $log->tracef("GetAccessToken response was %s", $resp->as_string("\n")); | |||||||||||||||||||
| 557 | 0 | my $rslt = URI->new('http://localhost?' . $resp->decoded_content)->query_form_hash; | |||||||||||||||||||
| 558 | 0 | $log->tracef("Extracted token [%s]", $rslt->{oauth_token}); | |||||||||||||||||||
| 559 | 0 | $self->configure(token => $rslt->{oauth_token}); | |||||||||||||||||||
| 560 | 0 | $log->tracef("Extracted secret [%s]", $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 561 | 0 | $self->configure(token_secret => $rslt->{oauth_token_secret}); | |||||||||||||||||||
| 562 | Future->done({ | ||||||||||||||||||||
| 563 | token => $rslt->{oauth_token}, | ||||||||||||||||||||
| 564 | token_secret => $rslt->{oauth_token_secret}, | ||||||||||||||||||||
| 565 | }) | ||||||||||||||||||||
| 566 | 0 | }) | |||||||||||||||||||
| 567 | 0 | } | |||||||||||||||||||
| 568 | |||||||||||||||||||||
| 569 | 1 | 1; | |||||||||||||||||||
| 570 | |||||||||||||||||||||
| 571 | =head1 AUTHOR | ||||||||||||||||||||
| 572 | |||||||||||||||||||||
| 573 | Tom Molesworth <TEAM@cpan.org> | ||||||||||||||||||||
| 574 | |||||||||||||||||||||
| 575 | =head1 LICENSE | ||||||||||||||||||||
| 576 | |||||||||||||||||||||
| 577 | Copyright Tom Molesworth 2014-2017. Licensed under the same terms as Perl itself. | ||||||||||||||||||||
| 578 | |||||||||||||||||||||