| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Hubot::Scripts::tweet; |
|
2
|
|
|
|
|
|
|
$Hubot::Scripts::tweet::VERSION = '0.2.7'; |
|
3
|
1
|
|
|
1
|
|
1136
|
use strict; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
31
|
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
|
1
|
|
|
|
|
1
|
|
|
|
1
|
|
|
|
|
26
|
|
|
5
|
1
|
|
|
1
|
|
7
|
use JSON::XS; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
62
|
|
|
6
|
1
|
|
|
1
|
|
621
|
use AnyEvent::HTTP::ScopedClient; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use URI::Escape; |
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub load { |
|
10
|
|
|
|
|
|
|
my ( $class, $robot ) = @_; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
my $authorization; |
|
13
|
|
|
|
|
|
|
$robot->hear( |
|
14
|
|
|
|
|
|
|
qr/https?:\/\/(mobile\.)?twitter\.com\/.*?\/status\/([0-9]+)/i, |
|
15
|
|
|
|
|
|
|
sub { |
|
16
|
|
|
|
|
|
|
my $msg = shift; |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
return unless $authorization; |
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
$msg->http('https://api.twitter.com/1.1/statuses/show.json') |
|
21
|
|
|
|
|
|
|
->header( { 'Authorization' => $authorization } ) |
|
22
|
|
|
|
|
|
|
->query( 'id' => $msg->match->[1] )->get( |
|
23
|
|
|
|
|
|
|
sub { |
|
24
|
|
|
|
|
|
|
my ( $body, $hdr ) = @_; |
|
25
|
|
|
|
|
|
|
return if ( !$body || !$hdr->{Status} =~ /^2/ ); |
|
26
|
|
|
|
|
|
|
my $tweet = decode_json($body); |
|
27
|
|
|
|
|
|
|
$msg->send("$tweet->{user}{screen_name}: $tweet->{text}"); |
|
28
|
|
|
|
|
|
|
} |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
$msg->message->finish; |
|
31
|
|
|
|
|
|
|
} |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
return |
|
35
|
|
|
|
|
|
|
unless $ENV{HUBOT_TWITTER_CONSUMER_KEY} |
|
36
|
|
|
|
|
|
|
&& $ENV{HUBOT_TWITTER_CONSUMER_SECRET}; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
my $client = AnyEvent::HTTP::ScopedClient->new( |
|
39
|
|
|
|
|
|
|
'https://api.twitter.com/oauth2/token', |
|
40
|
|
|
|
|
|
|
options => { |
|
41
|
|
|
|
|
|
|
auth => uri_escape( $ENV{HUBOT_TWITTER_CONSUMER_KEY} ) . ':' |
|
42
|
|
|
|
|
|
|
. uri_escape( $ENV{HUBOT_TWITTER_CONSUMER_SECRET} ) |
|
43
|
|
|
|
|
|
|
} |
|
44
|
|
|
|
|
|
|
); |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
$client->post( |
|
47
|
|
|
|
|
|
|
{ grant_type => 'client_credentials' }, |
|
48
|
|
|
|
|
|
|
sub { |
|
49
|
|
|
|
|
|
|
my ( $body, $hdr ) = @_; |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
return if !$body; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $data = decode_json($body); |
|
54
|
|
|
|
|
|
|
if ( $hdr->{Status} =~ /^2/ ) { |
|
55
|
|
|
|
|
|
|
my ( $token_type, $access_token ) |
|
56
|
|
|
|
|
|
|
= ( $data->{token_type}, $data->{access_token} ); |
|
57
|
|
|
|
|
|
|
$authorization = ucfirst $token_type . " $access_token"; |
|
58
|
|
|
|
|
|
|
} |
|
59
|
|
|
|
|
|
|
else { |
|
60
|
|
|
|
|
|
|
print STDERR __PACKAGE__ . " - $data->{errors}[0]{message}\n"; |
|
61
|
|
|
|
|
|
|
} |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
); |
|
64
|
|
|
|
|
|
|
} |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
1; |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=pod |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
=encoding utf-8 |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=head1 NAME |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Hubot::Scripts::tweet |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=head1 VERSION |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
version 0.2.7 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
<tweeturl> - Display tweet content |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 CONFIGURATION |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=over |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=item HUBOT_TWITTER_CONSUMER_KEY |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=item HUBOT_TWITTER_CONSUMER_SECRET |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=back |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Detect tweet URL and send tweet content |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 AUTHOR |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Hyungsuk Hong <hshong@perl.kr> |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
103
|
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
This software is copyright (c) 2012 by Hyungsuk Hong. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
107
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
108
|
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
=cut |