line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package WWW::SmartSheet; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
our $VERSION = '0.06'; |
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
125200
|
use Moo; |
|
2
|
|
|
|
|
18337
|
|
|
2
|
|
|
|
|
8
|
|
6
|
2
|
|
|
2
|
|
3022
|
use MooX::late; |
|
2
|
|
|
|
|
38860
|
|
|
2
|
|
|
|
|
10
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
252
|
use Carp (); |
|
2
|
|
|
|
|
5
|
|
|
2
|
|
|
|
|
34
|
|
9
|
2
|
|
|
2
|
|
511
|
use Data::Dumper qw(Dumper); |
|
2
|
|
|
|
|
5568
|
|
|
2
|
|
|
|
|
100
|
|
10
|
2
|
|
|
2
|
|
1048
|
use LWP::UserAgent; |
|
2
|
|
|
|
|
73890
|
|
|
2
|
|
|
|
|
65
|
|
11
|
2
|
|
|
2
|
|
998
|
use JSON qw(from_json to_json); |
|
2
|
|
|
|
|
15874
|
|
|
2
|
|
|
|
|
8
|
|
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has token => (is => 'ro', required => 1); |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
has sheets => (is => 'rw', isa => 'ArrayRef'); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my $API_URL = "https://api.smartsheet.com/2.0"; |
18
|
|
|
|
|
|
|
my @ACCESS_LEVELS = qw(VIEWER EDITOR EDITOR_SHARE ADMIN); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub ua { |
21
|
0
|
|
|
0
|
0
|
|
my ($self) = @_; |
22
|
|
|
|
|
|
|
|
23
|
0
|
|
|
|
|
|
my $ua = LWP::UserAgent->new( agent => "WWW::SmartSheet v$VERSION https://github.com/szabgab/WWW-SmartSheet" ); |
24
|
0
|
|
|
|
|
|
$ua->timeout(10); |
25
|
0
|
|
|
|
|
|
$ua->default_header("Authorization" => "Bearer " . $self->token); |
26
|
0
|
|
|
|
|
|
$ua->default_header("Content-Type" => "application/json"); |
27
|
0
|
|
|
|
|
|
return $ua; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub get_current_user { |
31
|
0
|
|
|
0
|
1
|
|
my ($self) = @_; |
32
|
|
|
|
|
|
|
|
33
|
0
|
|
|
|
|
|
my $current_user = $self->_get('users/me'); |
34
|
0
|
|
|
|
|
|
return $current_user; |
35
|
|
|
|
|
|
|
} |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
sub get_sheets { |
38
|
0
|
|
|
0
|
1
|
|
my ($self, $pagesize, $page) = @_; |
39
|
|
|
|
|
|
|
|
40
|
0
|
|
|
|
|
|
my $all_sheets = $self->_get("sheets", |
41
|
|
|
|
|
|
|
("pageSize" => $pagesize, |
42
|
|
|
|
|
|
|
"page" => $page, |
43
|
|
|
|
|
|
|
) |
44
|
|
|
|
|
|
|
); |
45
|
0
|
|
|
|
|
|
return $all_sheets; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
sub get_columns { |
49
|
0
|
|
|
0
|
1
|
|
my ($self, $sheetid, $pagesize, $page) = @_; |
50
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $cols = $self->_get("sheets/$sheetid/columns", |
52
|
|
|
|
|
|
|
("pageSize" => $pagesize, |
53
|
|
|
|
|
|
|
"page" => $page, |
54
|
|
|
|
|
|
|
) |
55
|
|
|
|
|
|
|
); |
56
|
0
|
|
|
|
|
|
return $cols; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
sub share_sheet { |
60
|
0
|
|
|
0
|
1
|
|
my ($self, $sheetid, $email, $access_level) = @_; |
61
|
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
my $result = $self->_post("sheets/$sheetid/shares?sendEmail=true", {email => $email, accessLevel => $access_level}); |
63
|
0
|
|
|
|
|
|
return $result; |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub create_sheet { |
67
|
0
|
|
|
0
|
1
|
|
my ($self, %args) = @_; |
68
|
|
|
|
|
|
|
|
69
|
0
|
|
|
|
|
|
return $self->_post('sheets', \%args); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
sub delete_sheet { |
73
|
0
|
|
|
0
|
1
|
|
my ($self, $id) = @_; |
74
|
|
|
|
|
|
|
|
75
|
0
|
|
|
|
|
|
$self->_delete("sheets/$id"); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub add_column { |
79
|
0
|
|
|
0
|
1
|
|
my ($self, $sheet_id, $column) = @_; |
80
|
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
return $self->_post("sheets/$sheet_id/columns", $column ); |
82
|
|
|
|
|
|
|
} |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub insert_rows { |
85
|
0
|
|
|
0
|
1
|
|
my ($self, $sheet_id, $loc, @rows) = @_; |
86
|
|
|
|
|
|
|
|
87
|
0
|
|
|
|
|
|
my @full_rows; |
88
|
0
|
|
|
|
|
|
foreach my $row (@rows) { |
89
|
0
|
|
|
|
|
|
my $lv = 1; |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my %r; |
92
|
0
|
|
|
|
|
|
$r{"cells"} = $row; |
93
|
|
|
|
|
|
|
|
94
|
0
|
0
|
|
|
|
|
if ($loc =~ m/(=)/) { |
95
|
|
|
|
|
|
|
|
96
|
0
|
|
|
|
|
|
my $l = $loc; |
97
|
0
|
0
|
|
|
|
|
if ($l =~ m/,above/) { |
98
|
0
|
|
|
|
|
|
$l =~ s/,above//; |
99
|
0
|
|
|
|
|
|
$r{"above"} = 1; |
100
|
|
|
|
|
|
|
} |
101
|
0
|
|
|
|
|
|
my ($k, $v) = split(/=/, $l); |
102
|
0
|
0
|
|
|
|
|
if ($v) { |
103
|
0
|
|
|
|
|
|
$r{$k}=$v; |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
} else { |
107
|
|
|
|
|
|
|
|
108
|
0
|
|
|
|
|
|
$r{"$loc"} = 1; |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
} |
111
|
0
|
|
|
|
|
|
push (@full_rows, \%r); |
112
|
|
|
|
|
|
|
} |
113
|
|
|
|
|
|
|
|
114
|
0
|
|
|
|
|
|
return $self->_post("sheets/$sheet_id/rows", \@full_rows); |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub get_sheet_by_id { |
118
|
0
|
|
|
0
|
1
|
|
my ($self, $id, $pagesize, $page) = @_; |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
my $sheet = $self->_get("sheets/$id", |
121
|
|
|
|
|
|
|
("pageSize" => $pagesize, |
122
|
|
|
|
|
|
|
"page" => $page, |
123
|
|
|
|
|
|
|
) |
124
|
|
|
|
|
|
|
); |
125
|
0
|
|
|
|
|
|
return $sheet; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
sub _post { |
129
|
0
|
|
|
0
|
|
|
my ($self, $path, $data) = @_; |
130
|
|
|
|
|
|
|
|
131
|
0
|
|
|
|
|
|
my $url = "$API_URL/$path"; |
132
|
0
|
|
|
|
|
|
my $ua = $self->ua; |
133
|
0
|
|
|
|
|
|
my $json = to_json($data); |
134
|
|
|
|
|
|
|
|
135
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( 'POST', $url ); |
136
|
0
|
|
|
|
|
|
$req->content( $json ); |
137
|
0
|
|
|
|
|
|
my $res = $ua->request( $req ); |
138
|
|
|
|
|
|
|
|
139
|
0
|
0
|
|
|
|
|
Carp::croak $res->status_line . $res->content if not $res->is_success; |
140
|
0
|
|
|
|
|
|
return from_json $res->decoded_content; |
141
|
|
|
|
|
|
|
} |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
sub _get { |
144
|
0
|
|
|
0
|
|
|
my ($self, $path, %params) = @_; |
145
|
|
|
|
|
|
|
|
146
|
0
|
|
|
|
|
|
my $paramstr; |
147
|
0
|
|
|
|
|
|
my $url = "$API_URL/$path"; |
148
|
|
|
|
|
|
|
|
149
|
0
|
|
|
|
|
|
foreach my $param (keys %params) { |
150
|
|
|
|
|
|
|
|
151
|
0
|
0
|
|
|
|
|
if (!$params{$param}) { |
152
|
|
|
|
|
|
|
# ignore empty params |
153
|
0
|
|
|
|
|
|
next; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
|
156
|
0
|
|
|
|
|
|
$paramstr .= $param . "=" . $params{$param} . "&"; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
0
|
0
|
|
|
|
|
if ($paramstr) { |
160
|
0
|
|
|
|
|
|
$paramstr =~ s/&$//; |
161
|
0
|
|
|
|
|
|
$url .= "?$paramstr"; |
162
|
|
|
|
|
|
|
} |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
|
my $res = $self->ua->get($url); |
165
|
0
|
0
|
|
|
|
|
Carp::croak $res->status_line . $res->content if not $res->is_success; |
166
|
0
|
|
|
|
|
|
return from_json $res->decoded_content; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub _delete { |
170
|
0
|
|
|
0
|
|
|
my ($self, $path) = @_; |
171
|
|
|
|
|
|
|
|
172
|
0
|
|
|
|
|
|
my $url = "$API_URL/$path"; |
173
|
0
|
|
|
|
|
|
my $res = $self->ua->delete($url); |
174
|
0
|
0
|
|
|
|
|
Carp::croak $res->status_line . $res->content if not $res->is_success; |
175
|
0
|
|
|
|
|
|
return from_json $res->decoded_content; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
1; |
179
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
__END__ |