| 1 | package AnyEvent::Twitter; | ||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 3 | ▶ | use utf8; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use 5.008; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 3 | our $VERSION = '0.64'; | |||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use JSON; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use URI; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use URI::Escape; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use Digest::SHA; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Time::Piece; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use AnyEvent::HTTP; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 3 | ▶ | use HTTP::Request::Common 'POST'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Data::Recursive::Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Net::OAuth; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use Net::OAuth::ProtectedResourceRequest; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 20 | 3 | ▶ | use Net::OAuth::RequestTokenRequest; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | 3 | ▶ | use Net::OAuth::AccessTokenRequest; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||
| 23 | 3 | $Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; | |||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | 3 | our %PATH = ( | |||||||||||||||||||||||||||
| 26 | site => 'https://twitter.com/', | ||||||||||||||||||||||||||||
| 27 | request_token => 'https://api.twitter.com/oauth/request_token', | ||||||||||||||||||||||||||||
| 28 | authorize => 'https://api.twitter.com/oauth/authorize', | ||||||||||||||||||||||||||||
| 29 | access_token => 'https://api.twitter.com/oauth/access_token', | ||||||||||||||||||||||||||||
| 30 | authenticate => 'https://api.twitter.com/oauth/authenticate', | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | 3 | our %RESOURCE_URL_BASE = ( | |||||||||||||||||||||||||||
| 34 | '1.0' => 'http://api.twitter.com/1/%s.json', | ||||||||||||||||||||||||||||
| 35 | '1.1' => 'https://api.twitter.com/1.1/%s.json', | ||||||||||||||||||||||||||||
| 36 | ); | ||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||
| 38 | 3 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||
| 39 | 3 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 3 | ▶ | $args{api_version} ||= '1.1'; | ||||||||||||||||||||||||||
|
Condition50%1/2
$args{"api_version"} ||= "1.1"
MC/DC0%0/1
$args{"api_version"} ||= "1.1"
$args{"api_version"}
Truth table50%1/2
A
A= $args{"api_version"}
| |||||||||||||||||||||||||||||
| 42 | 3 | ▶ | $args{access_token} ||= $args{token}; | ||||||||||||||||||||||||||
|
Condition100%3/3
$args{"access_token"} ||= $args{"token"}
MC/DC100%2/2
$args{"access_token"} ||= $args{"token"}
$args{"access_token"}
$args{"token"}
Truth table100%3/3
A ||= B
A= $args{"access_token"}B= $args{"token"}
| |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | $args{access_token_secret} ||= $args{token_secret}; | ||||||||||||||||||||||||||
|
Condition66%2/3
$args{"access_token_secret"} ||= $args{"token_secret"}
MC/DC0%0/2
$args{"access_token_secret"} ||= $args{"token_secret"}
$args{"access_token_secret"}
$args{"token_secret"}
Truth table66%2/3
A ||= B
A= $args{"access_token_secret"}B= $args{"token_secret"}
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | my @required = qw(access_token access_token_secret consumer_key consumer_secret); | |||||||||||||||||||||||||||
| 46 | 3 | for my $item (@required) { | |||||||||||||||||||||||||||
| 47 | 9 | ▶ | defined $args{$item} or Carp::croak "$item is required"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 2 | return bless { %args }, $class; | |||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $cb = pop; | |||||||||||||||||||||||||||
| 55 | 0 | my ($self, $endpoint, $params) = @_; | |||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | my $type = $endpoint =~ /^http.+\.json$/ ? 'url' : 'api'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | 0 | $self->request($type => $endpoint, method => 'GET', params => $params, $cb); | |||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | return $self; | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | 0 | ▶ | sub post { | ||||||||||||||||||||||||||
|
Subroutine
post: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 64 | 0 | my ($self, $endpoint, $params, $cb) = @_; | |||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 0 | ▶ | my $type = $endpoint =~ /^http.+\.json$/ ? 'url' : 'api'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 67 | 0 | $self->request($type => $endpoint, method => 'POST', params => $params, $cb); | |||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||
| 69 | 0 | return $self; | |||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 0 | ▶ | sub request { | ||||||||||||||||||||||||||
|
Subroutine
request: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||
| 73 | 0 | my $cb = pop; | |||||||||||||||||||||||||||
| 74 | 0 | my ($self, %opt) = @_; | |||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | ($opt{api} || $opt{url}) | ||||||||||||||||||||||||||||
| 77 | 0 | ▶ | or Carp::croak "'api' or 'url' option is required"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$opt{"api"} or $opt{"url"}
MC/DC0%0/2
$opt{"api"} or $opt{"url"}
$opt{"api"}
$opt{"url"}
Truth table0%0/3
A or B
A= $opt{"api"}B= $opt{"url"}
| |||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||
| 79 | 0 | my $url_base = $RESOURCE_URL_BASE{ $self->{api_version} }; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | my $url = $opt{url} || sprintf $url_base, $opt{api}; | ||||||||||||||||||||||||||
|
Condition0%0/3
$opt{'url'} || sprintf($url_base, $opt{'api'})
MC/DC0%0/2
$opt{'url'} || sprintf($url_base, $opt{'api'})
$opt{'url'}
sprintf($url_base, $opt{'api'})
Truth table0%0/3
A || B
A= $opt{'url'}B= sprintf($url_base, $opt{'api'})
| |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 0 | ▶ | ref $cb eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 83 | or Carp::croak "callback coderef is required"; | ||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 0 | ▶ | my $params = $opt{params} || {}; | ||||||||||||||||||||||||||
|
Condition0%0/2
$opt{'params'} || {}
MC/DC0%0/1
$opt{'params'} || {}
$opt{'params'}
Truth table0%0/2
A
A= $opt{'params'}
| |||||||||||||||||||||||||||||
| 86 | 0 | my $is_multipart = ref $params eq 'ARRAY'; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 0 | my $method = uc $opt{method}; | |||||||||||||||||||||||||||
| 89 | 0 | ▶ | $method =~ /^(?:GET|POST)$/ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 90 | or Carp::croak "'method' option should be GET or POST"; | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | my $req = $self->_make_oauth_request( | ||||||||||||||||||||||||||||
| 93 | class => 'Net::OAuth::ProtectedResourceRequest', | ||||||||||||||||||||||||||||
| 94 | request_url => $url, | ||||||||||||||||||||||||||||
| 95 | request_method => $method, | ||||||||||||||||||||||||||||
| 96 | extra_params => ($is_multipart ? {} : $params), | ||||||||||||||||||||||||||||
| 97 | consumer_key => $self->{consumer_key}, | ||||||||||||||||||||||||||||
| 98 | consumer_secret => $self->{consumer_secret}, | ||||||||||||||||||||||||||||
| 99 | token => $self->{access_token}, | ||||||||||||||||||||||||||||
| 100 | token_secret => $self->{access_token_secret}, | ||||||||||||||||||||||||||||
| 101 | 0 | ▶ | ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | my $req_params = {}; | |||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 0 | ▶ | if ($method eq 'POST') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 106 | 0 | $url = $req->normalized_request_url; | |||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||
| 108 | 0 | ▶ | if ($is_multipart) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 109 | my $encoded_params = Data::Recursive::Encode::_apply( | ||||||||||||||||||||||||||||
| 110 | 0 | ▶ | sub { utf8::is_utf8($_[0]) ? Encode::encode_utf8($_[0]) : $_[0] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 111 | {}, | ||||||||||||||||||||||||||||
| 112 | 0 | $params | |||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | my $ireq = POST( | |||||||||||||||||||||||||||
| 116 | $url, | ||||||||||||||||||||||||||||
| 117 | Content_Type => 'multipart/form-data', | ||||||||||||||||||||||||||||
| 118 | Content => [ @$encoded_params ] | ||||||||||||||||||||||||||||
| 119 | ); | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 0 | $req_params->{body} = $ireq->content; | |||||||||||||||||||||||||||
| 122 | $req_params->{headers} = { | ||||||||||||||||||||||||||||
| 123 | 0 | Authorization => $req->to_authorization_header, | |||||||||||||||||||||||||||
| 124 | 'Content-Type' => join "; ", $ireq->content_type, | ||||||||||||||||||||||||||||
| 125 | }; | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | } else { | ||||||||||||||||||||||||||||
| 128 | 0 | $req_params->{body} = $req->to_post_body; | |||||||||||||||||||||||||||
| 129 | 0 | $req_params->{headers}{'Content-Type'} = 'application/x-www-form-urlencoded'; | |||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | 0 | $url = $req->to_url; | |||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||
| 136 | 0 | ▶ | AnyEvent::HTTP::http_request $method => $url, %$req_params, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 137 | 0 | my ($body, $hdr) = @_; | |||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||
| 139 | 0 | local $@; | |||||||||||||||||||||||||||
| 140 | 0 | my $json = eval { JSON::decode_json($body) }; | |||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 0 | ▶ | if ($hdr->{Status} =~ /^2/) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | 0 | ▶ | $cb->($hdr, $json, $@ ? "parse error: $@" : $hdr->{Reason}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | } else { | ||||||||||||||||||||||||||||
| 145 | 0 | $cb->($hdr, undef, $hdr->{Reason}, $json); | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | 0 | }; | |||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 0 | return $self; | |||||||||||||||||||||||||||
| 150 | } | ||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub _make_oauth_request { | ||||||||||||||||||||||||||
|
Subroutine
_make_oauth_request: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 153 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 154 | 0 | my %opt = @_; | |||||||||||||||||||||||||||
| 155 | 0 | my $class = delete $opt{class}; | |||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | 0 | local $Net::OAuth::SKIP_UTF8_DOUBLE_ENCODE_CHECK = 1; | |||||||||||||||||||||||||||
| 158 | 0 | my $req = $class->new( | |||||||||||||||||||||||||||
| 159 | version => '1.0', | ||||||||||||||||||||||||||||
| 160 | timestamp => time, | ||||||||||||||||||||||||||||
| 161 | nonce => Digest::SHA::sha1_base64(time . $$ . rand), | ||||||||||||||||||||||||||||
| 162 | signature_method => 'HMAC-SHA1', | ||||||||||||||||||||||||||||
| 163 | %opt, | ||||||||||||||||||||||||||||
| 164 | ); | ||||||||||||||||||||||||||||
| 165 | 0 | $req->sign; | |||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||
| 167 | 0 | return $req; | |||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||
| 170 | 0 | ▶ | sub get_request_token { | ||||||||||||||||||||||||||
|
Subroutine
get_request_token: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||
| 171 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | 0 | my @required = qw(consumer_key consumer_secret callback_url); | |||||||||||||||||||||||||||
| 174 | 0 | for my $item (@required) { | |||||||||||||||||||||||||||
| 175 | 0 | ▶ | defined $args{$item} or Carp::croak "$item is required"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | 0 | ▶ | ref $args{cb} eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 179 | or Carp::croak "cb must be callback coderef"; | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 0 | ▶ | $args{auth} ||= 'authorize'; | ||||||||||||||||||||||||||
|
Condition0%0/2
$args{"auth"} ||= "authorize"
MC/DC0%0/1
$args{"auth"} ||= "authorize"
$args{"auth"}
Truth table0%0/2
A
A= $args{"auth"}
| |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | my $req = __PACKAGE__->_make_oauth_request( | ||||||||||||||||||||||||||||
| 184 | class => 'Net::OAuth::RequestTokenRequest', | ||||||||||||||||||||||||||||
| 185 | request_method => 'GET', | ||||||||||||||||||||||||||||
| 186 | request_url => $PATH{request_token}, | ||||||||||||||||||||||||||||
| 187 | consumer_key => $args{consumer_key}, | ||||||||||||||||||||||||||||
| 188 | consumer_secret => $args{consumer_secret}, | ||||||||||||||||||||||||||||
| 189 | callback => $args{callback_url}, | ||||||||||||||||||||||||||||
| 190 | 0 | ); | |||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 0 | ▶ | AnyEvent::HTTP::http_request GET => $req->to_url, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 193 | 0 | my ($body, $header) = @_; | |||||||||||||||||||||||||||
| 194 | 0 | my %token = __PACKAGE__->_parse_response($body); | |||||||||||||||||||||||||||
| 195 | 0 | my $location = URI->new($PATH{ $args{auth} }); | |||||||||||||||||||||||||||
| 196 | 0 | $location->query_form(%token); | |||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||
| 198 | 0 | $args{cb}->($location->as_string, \%token, $body, $header); | |||||||||||||||||||||||||||
| 199 | 0 | }; | |||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | 0 | ▶ | sub get_access_token { | ||||||||||||||||||||||||||
|
Subroutine
get_access_token: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 203 | 0 | my ($class, %args) = @_; | |||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 0 | my @required = qw( | |||||||||||||||||||||||||||
| 206 | consumer_key consumer_secret | ||||||||||||||||||||||||||||
| 207 | oauth_token oauth_token_secret oauth_verifier | ||||||||||||||||||||||||||||
| 208 | ); | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 0 | for my $item (@required) { | |||||||||||||||||||||||||||
| 211 | 0 | ▶ | defined $args{$item} or Carp::croak "$item is required"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||
| 214 | 0 | ▶ | ref $args{cb} eq 'CODE' | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 215 | or Carp::croak "cb must be callback coderef"; | ||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | my $req = __PACKAGE__->_make_oauth_request( | ||||||||||||||||||||||||||||
| 218 | class => 'Net::OAuth::AccessTokenRequest', | ||||||||||||||||||||||||||||
| 219 | request_method => 'GET', | ||||||||||||||||||||||||||||
| 220 | request_url => $PATH{access_token}, | ||||||||||||||||||||||||||||
| 221 | consumer_key => $args{consumer_key}, | ||||||||||||||||||||||||||||
| 222 | consumer_secret => $args{consumer_secret}, | ||||||||||||||||||||||||||||
| 223 | token => $args{oauth_token}, | ||||||||||||||||||||||||||||
| 224 | token_secret => $args{oauth_token_secret}, | ||||||||||||||||||||||||||||
| 225 | verifier => $args{oauth_verifier}, | ||||||||||||||||||||||||||||
| 226 | 0 | ); | |||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||
| 228 | 0 | ▶ | AnyEvent::HTTP::http_request GET => $req->to_url, sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 229 | 0 | my ($body, $header) = @_; | |||||||||||||||||||||||||||
| 230 | 0 | my %response = __PACKAGE__->_parse_response($body); | |||||||||||||||||||||||||||
| 231 | 0 | $args{cb}->(\%response, $body, $header); | |||||||||||||||||||||||||||
| 232 | 0 | }; | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 0 | ▶ | sub _parse_response { | ||||||||||||||||||||||||||
|
Subroutine
_parse_response: not called CC=2 SCAR=17.9
| |||||||||||||||||||||||||||||
| 236 | 0 | my ($class, $body) = @_; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 0 | my %query; | |||||||||||||||||||||||||||
| 239 | 0 | for my $pair (split /&/, $body) { | |||||||||||||||||||||||||||
| 240 | 0 | my ($key, $value) = split /=/, $pair; | |||||||||||||||||||||||||||
| 241 | 0 | $query{$key} = URI::Escape::uri_unescape($value); | |||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||
| 244 | 0 | return %query; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 2 | ▶ | sub parse_timestamp { # Twitter uses weird created_at format: "Thu Mar 01 17:38:56 +0000 2012" | ||||||||||||||||||||||||||
|
Subroutine
parse_timestamp: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 248 | 2 | my ($class, $created_at) = @_; | |||||||||||||||||||||||||||
| 249 | 2 | localtime( Time::Piece->strptime($created_at, '%a %b %d %H:%M:%S %z %Y' )->epoch ) | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 3 | 1; | |||||||||||||||||||||||||||
| 253 | __END__ | ||||||||||||||||||||||||||||