| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Badge::GoogleTalk; |
|
2
|
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
33802
|
use warnings; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
27
|
|
|
4
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
30
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
854
|
use version; |
|
|
1
|
|
|
|
|
1999
|
|
|
|
1
|
|
|
|
|
6
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = qv('0.4'); |
|
8
|
|
|
|
|
|
|
|
|
9
|
1
|
|
|
1
|
|
2964
|
use WWW::Mechanize; |
|
|
1
|
|
|
|
|
310301
|
|
|
|
1
|
|
|
|
|
778
|
|
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=head1 NAME |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
Badge::GoogleTalk - To get your status message/online status/chat link from google talk badge for website live chat. |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
=head1 VERSION |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
version 0.3 |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
use Badge::GoogleTalk; |
|
23
|
|
|
|
|
|
|
my $my_object = Badge::GoogleTalk->new( |
|
24
|
|
|
|
|
|
|
key => "your identification key", |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
# Get Your Badge's online status |
|
28
|
|
|
|
|
|
|
my $online_status = $my_object->is_online(); |
|
29
|
|
|
|
|
|
|
my $ol_status = $online_status == 0 ? "Offline" : "Online"; |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
# Get Your Badge's status message |
|
32
|
|
|
|
|
|
|
my $status = $my_object->get_status(); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
# Check Your Badge's away status |
|
35
|
|
|
|
|
|
|
my $away_status = $my_object->is_away(); |
|
36
|
|
|
|
|
|
|
my $aw_status = $away_status == 1 ? "Away" : "Online"; |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# Check Your Badge's Style |
|
39
|
|
|
|
|
|
|
my $style = $my_object->is_classic_style(); |
|
40
|
|
|
|
|
|
|
my $style_status = $style == 1 ? "Classic badge or one/two line style" : "Hyperlink and status icon style"; |
|
41
|
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
# Your Badge's in HTML format |
|
43
|
|
|
|
|
|
|
my $badge = $my_object->get_badge(); |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
# Your chat link for your website |
|
46
|
|
|
|
|
|
|
my $chat_link = $my_object->get_chat_box_link(); |
|
47
|
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
To create a simple Badge::GoogleTalk you must pass the key; |
|
49
|
|
|
|
|
|
|
key is your identification from the google authentication. |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
To create your chatback badge, visit http://www.google.com/talk/service/badge/New. |
|
52
|
|
|
|
|
|
|
If you're using a Google Apps account, |
|
53
|
|
|
|
|
|
|
you can create a chatback badge by visiting http://www.google.com/talk/service/a/DOMAIN/badge/New where DOMAIN is the name of your domain. |
|
54
|
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Use the alphanumeric account hash to pass as key in constructor |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
58
|
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
A simple perl module for retrieving a user's Google Talk status |
|
60
|
|
|
|
|
|
|
Google does provide a badge, to post your status/images/links to your |
|
61
|
|
|
|
|
|
|
website to start a chat. Using this code, we can extract the status messages, online status, |
|
62
|
|
|
|
|
|
|
chat box link and return that information to our perl application to keep up the live chat. |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 METHODS |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
=head1 DIAGNOSTICS |
|
67
|
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
This module depends on the output from a hosted web page by Google. If Google |
|
69
|
|
|
|
|
|
|
decides at any time to change this output, the module will likely fail. |
|
70
|
|
|
|
|
|
|
Please e-mail me if this is the case, so we can get it working again. |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
=over |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=back |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head2 |
|
78
|
|
|
|
|
|
|
=cut |
|
79
|
|
|
|
|
|
|
sub new |
|
80
|
|
|
|
|
|
|
{ |
|
81
|
0
|
|
|
0
|
1
|
|
my($class,%args) = @_; |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $query_link = 'http://www.google.com/talk/service/badge/Show?tk='; |
|
84
|
|
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
my $self = { %args }; |
|
86
|
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
_warn_user('Error',"User key is must to use this module :". |
|
88
|
|
|
|
|
|
|
"For more info please see the module pod") if(!defined $self->{'key'}); |
|
89
|
|
|
|
|
|
|
|
|
90
|
0
|
|
|
|
|
|
$self->{'talk_url'} = $query_link.$self->{'key'}; |
|
91
|
|
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
bless $self, $class or die "Can't bless $class: $!"; |
|
93
|
0
|
|
|
|
|
|
return $self; |
|
94
|
|
|
|
|
|
|
} |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
=head2 |
|
97
|
|
|
|
|
|
|
=cut |
|
98
|
|
|
|
|
|
|
sub _get_contents |
|
99
|
|
|
|
|
|
|
{ |
|
100
|
0
|
|
|
0
|
|
|
my $self = shift; |
|
101
|
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $mech = WWW::Mechanize->new(); |
|
103
|
0
|
|
|
|
|
|
$mech->get($self->{'talk_url'}); |
|
104
|
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my $page_contents = $mech->content(); |
|
106
|
0
|
|
|
|
|
|
my $content_type = $mech->ct(); |
|
107
|
0
|
|
|
|
|
|
my $response = $mech->status(); |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
_warn_user('Error','Provided user key is in-valid !') if($response == '400'); |
|
110
|
|
|
|
|
|
|
|
|
111
|
0
|
0
|
|
|
|
|
$self->{'is_badge_html'} = $mech->is_html() ? 1 : 0 ; |
|
112
|
|
|
|
|
|
|
|
|
113
|
0
|
0
|
|
|
|
|
_warn_user('Warning',"Your Badge's is Hyperlink and status icon style". |
|
114
|
|
|
|
|
|
|
"sorry can't process for this style") if(!$self->{'is_badge_html'}); |
|
115
|
|
|
|
|
|
|
|
|
116
|
0
|
|
|
|
|
|
return $page_contents; |
|
117
|
|
|
|
|
|
|
} |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
=head2 |
|
120
|
|
|
|
|
|
|
Title : is_online |
|
121
|
|
|
|
|
|
|
Function: this will return your online status |
|
122
|
|
|
|
|
|
|
return : 1 if online, 0 if offline |
|
123
|
|
|
|
|
|
|
=cut |
|
124
|
|
|
|
|
|
|
sub is_online{ |
|
125
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
126
|
0
|
|
|
|
|
|
my $content = $self->get_status(); |
|
127
|
0
|
0
|
|
|
|
|
if($content =~/Offline/) |
|
128
|
|
|
|
|
|
|
{ |
|
129
|
0
|
|
|
|
|
|
return 0; |
|
130
|
|
|
|
|
|
|
} |
|
131
|
0
|
|
|
|
|
|
return 1; |
|
132
|
|
|
|
|
|
|
} |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head2 |
|
135
|
|
|
|
|
|
|
Title : get_status |
|
136
|
|
|
|
|
|
|
Function: this will return your status message |
|
137
|
|
|
|
|
|
|
return : 1 if away |
|
138
|
|
|
|
|
|
|
=cut |
|
139
|
|
|
|
|
|
|
sub get_status { |
|
140
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
141
|
0
|
|
|
|
|
|
my $contents = $self->_get_contents(); |
|
142
|
0
|
|
|
|
|
|
$contents =~ / \s*(.*?)\s*<\/div><\/div>/; |
|
143
|
0
|
|
|
|
|
|
$contents =~ /\s*(.*?)\s*<\/a><\/div><\/body>/; |
|
144
|
0
|
|
|
|
|
|
$contents =~ / |
0
|
|
|
|
|
|
return $1; |
|
146
|
|
|
|
|
|
|
} |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
=head2 |
|
149
|
|
|
|
|
|
|
Title : get_chat_box_link |
|
150
|
|
|
|
|
|
|
Function: this will return you the link of you chat box |
|
151
|
|
|
|
|
|
|
=cut |
|
152
|
|
|
|
|
|
|
sub get_chat_box_link{ |
|
153
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
154
|
0
|
|
|
|
|
|
my $url = $self->{'talk_url'} ; |
|
155
|
0
|
|
|
|
|
|
$url =~ s/Show/Start/ig; |
|
156
|
0
|
|
|
|
|
|
return $url; |
|
157
|
|
|
|
|
|
|
} |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
=head2 |
|
160
|
|
|
|
|
|
|
Title : is_away |
|
161
|
|
|
|
|
|
|
Function: this will return your away status |
|
162
|
|
|
|
|
|
|
return : 1 if away |
|
163
|
|
|
|
|
|
|
=cut |
|
164
|
|
|
|
|
|
|
sub is_away{ |
|
165
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
166
|
0
|
|
|
|
|
|
my $content = $self->get_status(); |
|
167
|
0
|
0
|
|
|
|
|
if($content =~/Away/ig) |
|
168
|
|
|
|
|
|
|
{ |
|
169
|
0
|
|
|
|
|
|
return 1; |
|
170
|
|
|
|
|
|
|
} |
|
171
|
0
|
|
|
|
|
|
return 0; |
|
172
|
|
|
|
|
|
|
} |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
=head2 |
|
175
|
|
|
|
|
|
|
Title : get_badge |
|
176
|
|
|
|
|
|
|
Function: this will return you the badge iframe to use for your website |
|
177
|
|
|
|
|
|
|
=cut |
|
178
|
|
|
|
|
|
|
sub get_badge{ |
|
179
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
180
|
0
|
|
|
|
|
|
my $badge = ' |
|
|
|
|
|
|
$self->{'key'}. |
|
182
|
|
|
|
|
|
|
'&w=200&h=60" allowtransparency="true" width="200" frameborder="0" height="60">'; |
|
183
|
0
|
|
|
|
|
|
return $badge; |
|
184
|
|
|
|
|
|
|
} |
|
185
|
|
|
|
|
|
|
|
|
186
|
|
|
|
|
|
|
=head2 |
|
187
|
|
|
|
|
|
|
Title : is_classic_style |
|
188
|
|
|
|
|
|
|
Function: this will return your badge style |
|
189
|
|
|
|
|
|
|
return : 1 if Classic badge or one/two line style, 0 if Hyperlink and status icon style |
|
190
|
|
|
|
|
|
|
=cut |
|
191
|
|
|
|
|
|
|
sub is_classic_style { |
|
192
|
0
|
|
|
0
|
1
|
|
my $self = shift; |
|
193
|
0
|
|
|
|
|
|
return $self->{'is_badge_html'}; |
|
194
|
|
|
|
|
|
|
} |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head2 |
|
197
|
|
|
|
|
|
|
=cut |
|
198
|
|
|
|
|
|
|
sub _warn_user { |
|
199
|
0
|
|
|
0
|
|
|
my($type,$msg) = @_; |
|
200
|
0
|
|
|
|
|
|
print "[ $type ] $msg \n"; |
|
201
|
0
|
|
|
|
|
|
exit; |
|
202
|
|
|
|
|
|
|
} |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
1; # Magic true value required at end of module |
|
206
|
|
|
|
|
|
|
__END__ |