line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::CybozuOffice6; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
# !!! ATTENTION !!! |
5
|
|
|
|
|
|
|
# |
6
|
|
|
|
|
|
|
# This package is NOT a product of Cybozu, Inc. |
7
|
|
|
|
|
|
|
# DO NOT CONTACT CYBOZU, INC. for the use of the software. |
8
|
|
|
|
|
|
|
# |
9
|
|
|
|
|
|
|
# For support, please visit http://labs.cybozu.co.jp/blog/kazuho/ |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
31375
|
use 5.006; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
44
|
|
13
|
1
|
|
|
1
|
|
7
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
14
|
1
|
|
|
1
|
|
23
|
use warnings; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
46
|
|
15
|
1
|
|
|
1
|
|
798
|
use fields qw(url user id pass ua response ocode); |
|
1
|
|
|
|
|
1468
|
|
|
1
|
|
|
|
|
5
|
|
16
|
1
|
|
|
1
|
|
70
|
use vars qw($VERSION); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
28
|
|
17
|
|
|
|
|
|
|
|
18
|
1
|
|
|
1
|
|
4
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
85
|
|
19
|
1
|
|
|
1
|
|
811
|
use Jcode; |
|
1
|
|
|
|
|
64620
|
|
|
1
|
|
|
|
|
113
|
|
20
|
1
|
|
|
1
|
|
2060
|
use LWP; |
|
1
|
|
|
|
|
139143
|
|
|
1
|
|
|
|
|
40
|
|
21
|
1
|
|
|
1
|
|
1688
|
use Text::CSV_XS; |
|
1
|
|
|
|
|
45226
|
|
|
1
|
|
|
|
|
252
|
|
22
|
1
|
|
|
1
|
|
19
|
use URI::Escape; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6327
|
|
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
$VERSION = 0.04; |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
# instantiation |
29
|
|
|
|
|
|
|
sub new { |
30
|
|
|
|
|
|
|
# setup |
31
|
2
|
|
|
2
|
1
|
565
|
my WWW::CybozuOffice6 $self = shift; |
32
|
2
|
50
|
|
|
|
6
|
unless (ref $self) { |
33
|
2
|
|
|
|
|
11
|
$self = fields::new($self); |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
# set params |
36
|
2
|
|
|
|
|
4002
|
while ($#_ >= 0) { |
37
|
1
|
50
|
|
|
|
204
|
croak('CybozuOffice65->new() called with odd number of option parameters - should be of the form option => value') if ($#_ == 0); |
38
|
0
|
|
|
|
|
0
|
my $n = lc(shift); |
39
|
0
|
|
|
|
|
0
|
my $v = shift; |
40
|
0
|
|
|
|
|
0
|
$self->_init_param($n, $v); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
# set default |
43
|
1
|
50
|
|
|
|
14
|
$self->{ua} = LWP::UserAgent->new() unless defined($self->{ua}); |
44
|
1
|
50
|
|
|
|
5422
|
$self->{ocode} = 'utf8' unless defined($self->{ocode}); |
45
|
|
|
|
|
|
|
|
46
|
1
|
|
|
|
|
4
|
return $self; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# accessors |
50
|
|
|
|
|
|
|
sub url (\$@) { |
51
|
2
|
|
|
2
|
1
|
380
|
my $self = shift; |
52
|
2
|
|
|
|
|
6
|
return $self->_accessor('url', @_); |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
sub user (\$@) { |
56
|
2
|
|
|
2
|
1
|
4
|
my $self = shift; |
57
|
2
|
|
|
|
|
5
|
return $self->_accessor('user', @_); |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
sub id (\$@) { |
61
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
62
|
0
|
|
|
|
|
0
|
return $self->_accessor('id', @_); |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub password (\$@) { |
66
|
2
|
|
|
2
|
1
|
5
|
my $self = shift; |
67
|
2
|
|
|
|
|
6
|
return $self->_accessor('pass', @_); |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub ua (\$@) { |
71
|
3
|
|
|
3
|
1
|
4
|
my $self = shift; |
72
|
3
|
|
|
|
|
7
|
return $self->_accessor('ua', @_); |
73
|
|
|
|
|
|
|
} |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub response (\$) { |
76
|
|
|
|
|
|
|
# no setter |
77
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
78
|
0
|
|
|
|
|
0
|
return $self->{response}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub ocode (\$@) { |
82
|
4
|
|
|
4
|
1
|
6
|
my $self = shift; |
83
|
4
|
|
|
|
|
10
|
return $self->_accessor('ocode', @_); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
# checks if username/password is valid |
87
|
|
|
|
|
|
|
sub test_credentials (\$) { |
88
|
1
|
|
|
1
|
1
|
702
|
my $self = shift; |
89
|
1
|
|
|
|
|
6
|
my $items = $self->externalAPINotify; |
90
|
0
|
|
0
|
|
|
0
|
return defined($items) && ref($items) eq 'ARRAY'; |
91
|
|
|
|
|
|
|
} |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
# returns new items |
94
|
|
|
|
|
|
|
sub externalAPINotify (\$) { |
95
|
1
|
|
|
1
|
1
|
2
|
my $self = shift; |
96
|
|
|
|
|
|
|
# get RSS |
97
|
1
|
0
|
|
|
|
4
|
if (! $self->_request('ExternalAPINotify')) { |
98
|
0
|
|
|
|
|
0
|
return; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
# parse and return the result |
101
|
0
|
|
|
|
|
0
|
my $content = Jcode::convert($self->{response}->content, $self->{ocode}); |
102
|
0
|
|
|
|
|
0
|
return $self->parse_externalAPINotify($content); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub parse_externalAPINotify (\$$) { |
106
|
1
|
|
|
1
|
0
|
2
|
my ($self, $content) = @_; |
107
|
1
|
|
|
|
|
2
|
my @items; |
108
|
|
|
|
|
|
|
# split into lines |
109
|
1
|
|
|
|
|
13
|
my @lines = split(/\x0d\x0a/, $content); |
110
|
|
|
|
|
|
|
# check first line |
111
|
1
|
50
|
33
|
|
|
11
|
if ($#lines == -1 || $lines[0] !~ /ts\./) { |
112
|
0
|
|
|
|
|
0
|
return; |
113
|
|
|
|
|
|
|
} |
114
|
1
|
|
|
|
|
2
|
shift(@lines); |
115
|
|
|
|
|
|
|
# parse the rest (but not the last line) |
116
|
1
|
|
|
|
|
12
|
my $csv = Text::CSV_XS->new({ binary => 1 }); |
117
|
1
|
|
|
|
|
127
|
while ($#lines > 0) { |
118
|
11
|
|
|
|
|
12
|
my $line = shift(@lines); |
119
|
11
|
50
|
|
|
|
31
|
if (! $csv->parse($line)) { |
120
|
0
|
|
|
|
|
0
|
croak 'failed to parse CSV input'; |
121
|
|
|
|
|
|
|
} |
122
|
11
|
|
|
|
|
284
|
my @fields = $csv->fields; |
123
|
11
|
50
|
|
|
|
103
|
if ($#fields < 6) { |
124
|
0
|
|
|
|
|
0
|
croak 'unexpected number of fields in CSV'; |
125
|
|
|
|
|
|
|
} |
126
|
11
|
|
|
|
|
47
|
my $item = { |
127
|
|
|
|
|
|
|
app => $fields[0], |
128
|
|
|
|
|
|
|
app_jp => $fields[1], |
129
|
|
|
|
|
|
|
timestamp => $fields[3], |
130
|
|
|
|
|
|
|
title => $fields[4], |
131
|
|
|
|
|
|
|
description => $fields[5], |
132
|
|
|
|
|
|
|
from => $fields[6], |
133
|
|
|
|
|
|
|
link => $fields[7] }; |
134
|
11
|
|
|
|
|
40
|
$item->{timestamp} =~ s/^ts\.//; |
135
|
11
|
|
|
|
|
41
|
push(@items, $item); |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
1
|
|
|
|
|
30
|
return \@items; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
# initialization |
142
|
|
|
|
|
|
|
sub _init_param (\$$$) { |
143
|
0
|
|
|
0
|
|
0
|
my ($self, $n, $v) = @_; |
144
|
0
|
|
|
|
|
0
|
$self->{$n} = $v; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
# general accessor |
148
|
|
|
|
|
|
|
sub _accessor (\$$@) { |
149
|
13
|
|
|
13
|
|
15
|
my $self = shift; |
150
|
13
|
|
|
|
|
15
|
my $name = shift; |
151
|
13
|
100
|
|
|
|
29
|
if ($#_ <=> -1) { |
152
|
6
|
|
|
|
|
14
|
$self->{$name} = $_[0]; |
153
|
|
|
|
|
|
|
} |
154
|
13
|
|
|
|
|
77
|
return $self->{$name}; |
155
|
|
|
|
|
|
|
} |
156
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
# request handler |
158
|
|
|
|
|
|
|
sub _request (\$$) { |
159
|
1
|
|
|
1
|
|
2
|
my ($self, $page) = @_; |
160
|
1
|
50
|
|
|
|
172
|
croak 'url not set' unless defined($self->{url}); |
161
|
0
|
0
|
0
|
|
|
|
croak 'user/id not set' unless defined $self->{user} or defined $self->{id}; |
162
|
0
|
0
|
|
|
|
|
croak 'password not set' unless defined($self->{pass}); |
163
|
0
|
0
|
|
|
|
|
$self->{response} = |
|
|
0
|
|
|
|
|
|
164
|
|
|
|
|
|
|
$self->{ua}->post($self->{url} . '?page=' . uri_escape($page), |
165
|
|
|
|
|
|
|
{ _System => 'login', |
166
|
|
|
|
|
|
|
_Login => '1', |
167
|
|
|
|
|
|
|
GuideNavi => '1', |
168
|
|
|
|
|
|
|
defined $self->{user} ? (_Account => $self->{user}) : (), |
169
|
|
|
|
|
|
|
defined $self->{id} ? (_Id => $self->{id}) : (), |
170
|
|
|
|
|
|
|
Password => $self->{pass} }); |
171
|
0
|
|
|
|
|
|
return $self->{response}->is_success; |
172
|
|
|
|
|
|
|
} |
173
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
1; |
176
|
|
|
|
|
|
|
__END__ |