| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::Toggl; |
|
2
|
|
|
|
|
|
|
|
|
3
|
5
|
|
|
5
|
|
379660
|
use Module::Runtime qw(use_package_optimistically); |
|
|
5
|
|
|
|
|
11
|
|
|
|
5
|
|
|
|
|
26
|
|
|
4
|
|
|
|
|
|
|
|
|
5
|
5
|
|
|
5
|
|
203
|
use Moo; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
20
|
|
|
6
|
|
|
|
|
|
|
with 'WebService::Toggl::Role::Base'; |
|
7
|
5
|
|
|
5
|
|
1530
|
use namespace::clean; |
|
|
5
|
|
|
|
|
6
|
|
|
|
5
|
|
|
|
|
29
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
our $VERSION = "0.10"; |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has 'me' => (is =>'ro', lazy => 1, builder => 1); |
|
13
|
0
|
|
|
0
|
|
|
sub _build_me { shift->_new_thing('::API::Me') } |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
0
|
|
|
0
|
|
|
sub workspace { shift->_new_thing_by_id('::API::Workspace', @_) } |
|
17
|
0
|
|
|
0
|
|
|
sub client { shift->_new_thing_by_id('::API::Client', @_) } |
|
18
|
0
|
|
|
0
|
|
|
sub project { shift->_new_thing_by_id('::API::Project', @_) } |
|
19
|
0
|
|
|
0
|
|
|
sub project_user { shift->_new_thing_by_id('::API::ProjectUser', @_) } |
|
20
|
0
|
|
|
0
|
|
|
sub tag { shift->_new_thing_by_id('::API::Tag', @_) } |
|
21
|
0
|
|
|
0
|
|
|
sub task { shift->_new_thing_by_id('::API::Task', @_) } |
|
22
|
0
|
|
|
0
|
|
|
sub time_entry { shift->_new_thing_by_id('::API::TimeEntry', @_) } |
|
23
|
0
|
|
|
0
|
|
|
sub user { shift->_new_thing_by_id('::API::User', @_) } |
|
24
|
0
|
|
|
0
|
|
|
sub workspace_user { shift->_new_thing_by_id('::API::WorkspaceUser', @_) } |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
|
|
27
|
0
|
|
|
0
|
|
|
sub details { shift->_new_thing('::Report::Details', @_) } |
|
28
|
0
|
|
|
0
|
|
|
sub summary { shift->_new_thing('::Report::Summary', @_) } |
|
29
|
0
|
|
|
0
|
|
|
sub weekly { shift->_new_thing('::Report::Weekly', @_) } |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub _new_thing { |
|
33
|
0
|
|
|
0
|
|
|
my ($self, $class, $args) = @_; |
|
34
|
0
|
0
|
|
|
|
|
return use_package_optimistically('WebService::Toggl' . $class) |
|
35
|
0
|
|
|
|
|
|
->new({_request => $self->_request, %{$args || {}}}); |
|
36
|
|
|
|
|
|
|
} |
|
37
|
|
|
|
|
|
|
|
|
38
|
0
|
|
|
0
|
|
|
sub _new_thing_by_id { shift->_new_thing(shift, {id => shift}) } |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
|
41
|
|
|
|
|
|
|
__END__ |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
=encoding utf-8 |
|
44
|
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=head1 NAME |
|
46
|
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
WebService::Toggl - Wrapper for the toggl.com task logging API |
|
48
|
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
use WebService::Toggl; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
my $toggl = WebService::Toggl->new({api_key => $ENV{API_KEY}}); |
|
54
|
|
|
|
|
|
|
my $me = $toggl->me(); |
|
55
|
|
|
|
|
|
|
say "Me: " . $me->fullname . " <" . $me->email . ">:"; |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
say "My Workspaces:"; |
|
58
|
|
|
|
|
|
|
for my $ws ($me->workspaces->all) { |
|
59
|
|
|
|
|
|
|
say " " . $ws->name . " (" . $ws->id . ")"; |
|
60
|
|
|
|
|
|
|
say " Projects:"; |
|
61
|
|
|
|
|
|
|
say " " . $_->name . " (" . $_->id . ") " for ($ws->projects->all); |
|
62
|
|
|
|
|
|
|
} |
|
63
|
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
B<< NB: This is a new module, and the API is still under development. |
|
67
|
|
|
|
|
|
|
While I'm pretty happy with the current interface, expect the |
|
68
|
|
|
|
|
|
|
internals to be heavily refactored before v1.0. This version |
|
69
|
|
|
|
|
|
|
currently only supports read access to the API, but I plan to add |
|
70
|
|
|
|
|
|
|
write access in the near future. >> |
|
71
|
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
L<WebService::Toggl> is a perl interface to the |
|
73
|
|
|
|
|
|
|
L<Toggl|http://www.toggl.com> API, as described at |
|
74
|
|
|
|
|
|
|
L<https://github.com/toggl/toggl_api_docs>. When a new |
|
75
|
|
|
|
|
|
|
C<WebService::Toggl> object is created, it is associated with a |
|
76
|
|
|
|
|
|
|
particulars user's credentials via their API token. The API token can |
|
77
|
|
|
|
|
|
|
be found at the bottom of your 'My Profile' on Toggl. Any new objects |
|
78
|
|
|
|
|
|
|
created by the C<WebService::Toggl> object will inherit its credentials. |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head2 Laziness |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
All C<Webservice::Toggl::API::> and C<WebService::Toggl::Report::> |
|
83
|
|
|
|
|
|
|
objects are created lazily. If you ask for a particular |
|
84
|
|
|
|
|
|
|
C<::API::Workspace> object by id, no GET request against the Toggl API |
|
85
|
|
|
|
|
|
|
will be issued until you request an attribute that has not yet been set. E.g. |
|
86
|
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
my $workspace = $toggl->workspace(1234); |
|
88
|
|
|
|
|
|
|
say $workspace->id; # prints 1234, no GET yet issued |
|
89
|
|
|
|
|
|
|
say $workspace->name; # name is not yet set, will issue GET request |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head2 Raw data |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
Each C<API::> and C<Report::> object stores the raw response received |
|
94
|
|
|
|
|
|
|
from Toggl in an attribute called C<raw>. If you want to force the |
|
95
|
|
|
|
|
|
|
object to fill itself in with data from the API, calling |
|
96
|
|
|
|
|
|
|
C<< $object->raw() >> will do so. |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head2 Set objects |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
Each C<API::> class has a corresponding class that represents a set of |
|
101
|
|
|
|
|
|
|
the objects. These set objects store the raw response query and will |
|
102
|
|
|
|
|
|
|
return a list of the objects it comprises via the C<< ->all() >> |
|
103
|
|
|
|
|
|
|
method. |
|
104
|
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 Additional queries |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
You can make other requests against the Toggle API via the |
|
108
|
|
|
|
|
|
|
C<api_{get,post,put,delete}()> methods provided by |
|
109
|
|
|
|
|
|
|
L<WebService::Toggl::Role::Base>. For instance, if you had a |
|
110
|
|
|
|
|
|
|
L<WebService::Toggl::API::Tag> object that you wanted to delete, you |
|
111
|
|
|
|
|
|
|
could write: |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
$tag->api_delete( $tag->my_url ); |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
=head1 METHODS |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 API objects |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
=head3 me() |
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Me> object representing the |
|
123
|
|
|
|
|
|
|
authorized user. |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head3 workspace($id) |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Workspace> object with the given id. |
|
128
|
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
=head3 workspace_user( $id ) |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::WorkspaceUser> object with the given id. |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
=head3 client( $id ) |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Client> object with the given id. |
|
136
|
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
=head3 project( $id ) |
|
138
|
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Project> object with the given id. |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
=head3 project_user( $id ) |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::ProjectUser> object with the given id. |
|
144
|
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
=head3 tag( $id ) |
|
146
|
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Tag> object with the given id. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=head3 task( $id ) |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::Task> object with the given id. |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
=head3 time_entry( $id ) |
|
154
|
|
|
|
|
|
|
|
|
155
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::TimeEntry> object with the given id. |
|
156
|
|
|
|
|
|
|
|
|
157
|
|
|
|
|
|
|
=head3 user( $id ) |
|
158
|
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::API::User> object with the given id. |
|
160
|
|
|
|
|
|
|
|
|
161
|
|
|
|
|
|
|
=head2 Reports |
|
162
|
|
|
|
|
|
|
|
|
163
|
|
|
|
|
|
|
=head3 details( $args ) |
|
164
|
|
|
|
|
|
|
|
|
165
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::Report::Details> object with the |
|
166
|
|
|
|
|
|
|
given arguments. |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head3 summary( $args ) |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::Report::Summary> object with the |
|
171
|
|
|
|
|
|
|
given arguments. |
|
172
|
|
|
|
|
|
|
|
|
173
|
|
|
|
|
|
|
=head3 weekly( $args ) |
|
174
|
|
|
|
|
|
|
|
|
175
|
|
|
|
|
|
|
Returns the L<WebService::Toggl::Report::Weekly> object with the given |
|
176
|
|
|
|
|
|
|
arguments. |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
=head1 LICENSE |
|
179
|
|
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
Copyright (C) Fitz Elliott. |
|
181
|
|
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
|
183
|
|
|
|
|
|
|
it under the same terms as Perl itself. |
|
184
|
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
=head1 AUTHOR |
|
186
|
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
Fitz Elliott E<lt>felliott@fiskur.orgE<gt> |
|
188
|
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
=cut |
|
190
|
|
|
|
|
|
|
|