line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# ABSTRACT: Twitter.com API Client |
2
|
|
|
|
|
|
|
package API::Twitter; |
3
|
|
|
|
|
|
|
|
4
|
1
|
|
|
1
|
|
1463
|
use namespace::autoclean -except => 'has'; |
|
1
|
|
|
|
|
20971
|
|
|
1
|
|
|
|
|
7
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
882
|
use Data::Object::Class; |
|
1
|
|
|
|
|
17998
|
|
|
1
|
|
|
|
|
10
|
|
7
|
1
|
|
|
1
|
|
2882
|
use Data::Object::Class::Syntax; |
|
1
|
|
|
|
|
8243
|
|
|
1
|
|
|
|
|
6
|
|
8
|
1
|
|
|
1
|
|
1428
|
use Data::Object::Signatures; |
|
1
|
|
|
|
|
251408
|
|
|
1
|
|
|
|
|
12
|
|
9
|
|
|
|
|
|
|
|
10
|
1
|
|
|
1
|
|
8357
|
use Data::Object qw(load); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
89
|
|
11
|
1
|
|
|
1
|
|
6
|
use Data::Object::Library qw(Str); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
5
|
|
12
|
1
|
|
|
1
|
|
1565
|
use Net::OAuth (); |
|
1
|
|
|
|
|
625
|
|
|
1
|
|
|
|
|
298
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
extends 'API::Client'; |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
our $DEFAULT_URL = "https://api.twitter.com"; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$Net::OAuth::PROTOCOL_VERSION = Net::OAuth::PROTOCOL_VERSION_1_0A; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
our $VERSION = '0.04'; # VERSION |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
# ATTRIBUTES |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
has consumer_key => rw; |
27
|
|
|
|
|
|
|
has consumer_secret => rw; |
28
|
|
|
|
|
|
|
has access_token => rw; |
29
|
|
|
|
|
|
|
has access_token_secret => rw; |
30
|
|
|
|
|
|
|
has oauth_type => rw; |
31
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
# CONSTRAINTS |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
req consumer_key => Str; |
35
|
|
|
|
|
|
|
req consumer_secret => Str; |
36
|
|
|
|
|
|
|
opt access_token => Str; |
37
|
|
|
|
|
|
|
opt access_token_secret => Str; |
38
|
|
|
|
|
|
|
opt oauth_type => Str; |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
# DEFAULTS |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
def identifier => 'API::Twitter (Perl)'; |
43
|
|
|
|
|
|
|
def oauth_type => 'protected resource'; |
44
|
|
|
|
|
|
|
def url => method { load('Mojo::URL')->new($DEFAULT_URL) }; |
45
|
|
|
|
|
|
|
def version => '1.1'; |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# CONSTRUCTION |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
after BUILD => method { |
50
|
|
|
|
|
|
|
my $identifier = $self->identifier; |
51
|
|
|
|
|
|
|
my $version = $self->version; |
52
|
|
|
|
|
|
|
my $agent = $self->user_agent; |
53
|
|
|
|
|
|
|
my $url = $self->url; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
$agent->transactor->name($identifier); |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
$url->path("/$version"); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
return $self; |
60
|
|
|
|
|
|
|
}; |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
# METHODS |
63
|
|
|
|
|
|
|
|
64
|
0
|
|
|
0
|
0
|
|
method PREPARE ($ua, $tx, %args) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
|
my $req = $tx->req; |
66
|
0
|
|
|
|
|
|
my $headers = $req->headers; |
67
|
0
|
|
|
|
|
|
my $params = $req->params->to_hash; |
68
|
0
|
|
|
|
|
|
my $url = $req->url; |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
# default headers |
71
|
0
|
|
|
|
|
|
$headers->header('Content-Type' => 'application/json'); |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
# append path suffix |
74
|
0
|
0
|
|
|
|
|
$url->path("@{[$url->path]}.json") if $url->path !~ /\.json$/; |
|
0
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
# oauth data |
77
|
0
|
|
|
|
|
|
my $consumer_key = $self->consumer_key; |
78
|
0
|
|
|
|
|
|
my $consumer_secret = $self->consumer_secret; |
79
|
0
|
|
|
|
|
|
my $access_token = $self->access_token; |
80
|
0
|
|
|
|
|
|
my $access_token_secret = $self->access_token_secret; |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
# oauth variables |
83
|
0
|
|
|
|
|
|
my $oauth_consumer_key = $consumer_key; |
84
|
0
|
|
|
|
|
|
my $oauth_nonce = Digest::SHA::sha1_base64(time . $$ . rand); |
85
|
0
|
|
|
|
|
|
my $oauth_signature_method = 'HMAC-SHA1', |
86
|
|
|
|
|
|
|
my $oauth_timestamp = time, |
87
|
|
|
|
|
|
|
my $oauth_token = $access_token, |
88
|
|
|
|
|
|
|
my $oauth_version = '1.0'; |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
# oauth object |
91
|
0
|
|
|
|
|
|
my $base = $url->clone; $base->query(undef); |
|
0
|
|
|
|
|
|
|
92
|
0
|
|
|
|
|
|
my $oauth = Net::OAuth->request($self->oauth_type)->new(%$params, |
93
|
|
|
|
|
|
|
version => '1.0', |
94
|
|
|
|
|
|
|
consumer_key => $consumer_key, |
95
|
|
|
|
|
|
|
consumer_secret => $consumer_secret, |
96
|
|
|
|
|
|
|
request_method => uc($req->method), |
97
|
|
|
|
|
|
|
request_url => $base, |
98
|
|
|
|
|
|
|
signature_method => 'HMAC-SHA1', |
99
|
|
|
|
|
|
|
timestamp => time, |
100
|
|
|
|
|
|
|
token => $access_token, |
101
|
|
|
|
|
|
|
token_secret => $access_token_secret, |
102
|
|
|
|
|
|
|
nonce => Digest::SHA::sha1_base64(time . $$ . rand), |
103
|
|
|
|
|
|
|
); |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# oauth signature |
106
|
0
|
|
|
|
|
|
$oauth->sign; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
# authorization header |
109
|
0
|
|
|
|
|
|
$headers->header('Authorization' => $oauth->to_authorization_header); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
0
|
0
|
|
method resource (@segments) { |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
# build new resource instance |
114
|
0
|
|
|
|
|
|
my $instance = __PACKAGE__->new( |
115
|
|
|
|
|
|
|
debug => $self->debug, |
116
|
|
|
|
|
|
|
fatal => $self->fatal, |
117
|
|
|
|
|
|
|
retries => $self->retries, |
118
|
|
|
|
|
|
|
timeout => $self->timeout, |
119
|
|
|
|
|
|
|
user_agent => $self->user_agent, |
120
|
|
|
|
|
|
|
identifier => $self->identifier, |
121
|
|
|
|
|
|
|
version => $self->version, |
122
|
|
|
|
|
|
|
access_token => $self->access_token, |
123
|
|
|
|
|
|
|
access_token_secret => $self->access_token_secret, |
124
|
|
|
|
|
|
|
consumer_key => $self->consumer_key, |
125
|
|
|
|
|
|
|
consumer_secret => $self->consumer_secret, |
126
|
|
|
|
|
|
|
); |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# resource locator |
129
|
0
|
|
|
|
|
|
my $url = $instance->url; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
# modify resource locator if possible |
132
|
0
|
|
|
|
|
|
$url->path(join '/', $self->url->path, @segments); |
133
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
# return resource instance |
135
|
0
|
|
|
|
|
|
return $instance; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
1; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
__END__ |