| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package WebService::POEditor; |
|
2
|
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
# ABSTRACT: POEditor.com API wrapper |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
421780
|
use Moose; |
|
|
0
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
with 'Role::REST::Client'; |
|
7
|
|
|
|
|
|
|
use MooseX::Attribute::ENV; |
|
8
|
|
|
|
|
|
|
use WebService::POEditor::Response; |
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
use version; our $VERSION = version->new('v1.1.0'); |
|
11
|
|
|
|
|
|
|
use namespace::clean; |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
has api_token => ( |
|
15
|
|
|
|
|
|
|
is => 'ro', |
|
16
|
|
|
|
|
|
|
isa => 'Str', |
|
17
|
|
|
|
|
|
|
required => 1, |
|
18
|
|
|
|
|
|
|
traits => ['ENV'], |
|
19
|
|
|
|
|
|
|
env_key => 'POEDITOR_API_TOKEN', |
|
20
|
|
|
|
|
|
|
); |
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has server => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
isa => 'Str', |
|
26
|
|
|
|
|
|
|
default => 'https://poeditor.com/api', |
|
27
|
|
|
|
|
|
|
traits => ['ENV'], |
|
28
|
|
|
|
|
|
|
env_key => 'POEDITOR_API_SERVER', |
|
29
|
|
|
|
|
|
|
); |
|
30
|
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
32
|
|
|
|
|
|
|
# private attributes |
|
33
|
|
|
|
|
|
|
#--------------------------------------------------------------------------# |
|
34
|
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
## overload Role::REST::Client defaults |
|
36
|
|
|
|
|
|
|
has '+type' => (default => 'application/x-www-form-urlencoded'); |
|
37
|
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
has _api_methods => ( |
|
39
|
|
|
|
|
|
|
is => 'ro', |
|
40
|
|
|
|
|
|
|
isa => 'ArrayRef', |
|
41
|
|
|
|
|
|
|
traits => ['Array'], |
|
42
|
|
|
|
|
|
|
lazy => 1, |
|
43
|
|
|
|
|
|
|
builder => '_build__api_methods', |
|
44
|
|
|
|
|
|
|
handles => { |
|
45
|
|
|
|
|
|
|
api_methods => 'uniq', |
|
46
|
|
|
|
|
|
|
add_api_method => 'push', |
|
47
|
|
|
|
|
|
|
}, |
|
48
|
|
|
|
|
|
|
); |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _build__api_methods { |
|
51
|
|
|
|
|
|
|
my $self = shift; |
|
52
|
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
return [ |
|
54
|
|
|
|
|
|
|
qw/ |
|
55
|
|
|
|
|
|
|
list_projects |
|
56
|
|
|
|
|
|
|
create_project |
|
57
|
|
|
|
|
|
|
view_project |
|
58
|
|
|
|
|
|
|
list_languages |
|
59
|
|
|
|
|
|
|
add_language |
|
60
|
|
|
|
|
|
|
delete_language |
|
61
|
|
|
|
|
|
|
set_reference_language |
|
62
|
|
|
|
|
|
|
clear_reference_language |
|
63
|
|
|
|
|
|
|
view_terms |
|
64
|
|
|
|
|
|
|
add_terms |
|
65
|
|
|
|
|
|
|
delete_terms |
|
66
|
|
|
|
|
|
|
sync_terms |
|
67
|
|
|
|
|
|
|
update_language |
|
68
|
|
|
|
|
|
|
export |
|
69
|
|
|
|
|
|
|
upload |
|
70
|
|
|
|
|
|
|
available_languages |
|
71
|
|
|
|
|
|
|
list_contributors |
|
72
|
|
|
|
|
|
|
add_contributor |
|
73
|
|
|
|
|
|
|
/ |
|
74
|
|
|
|
|
|
|
]; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
has _api_method_handler => ( |
|
78
|
|
|
|
|
|
|
is => 'ro', |
|
79
|
|
|
|
|
|
|
isa => 'CodeRef', |
|
80
|
|
|
|
|
|
|
traits => ['Code'], |
|
81
|
|
|
|
|
|
|
lazy => 1, |
|
82
|
|
|
|
|
|
|
builder => '_build__api_method_handler', |
|
83
|
|
|
|
|
|
|
handles => { _handle_api_method => 'execute_method' }); |
|
84
|
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub _build__api_method_handler { |
|
86
|
|
|
|
|
|
|
my $self = shift; |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
return sub { |
|
89
|
|
|
|
|
|
|
my ($self, $method, $params) = @_; |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
my $res = $self->post( |
|
92
|
|
|
|
|
|
|
'/', |
|
93
|
|
|
|
|
|
|
{ api_token => $self->api_token, |
|
94
|
|
|
|
|
|
|
action => $method, |
|
95
|
|
|
|
|
|
|
%{ $params || {} }, |
|
96
|
|
|
|
|
|
|
}, |
|
97
|
|
|
|
|
|
|
); |
|
98
|
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
return WebService::POEditor::Response->new( |
|
100
|
|
|
|
|
|
|
res => $res, |
|
101
|
|
|
|
|
|
|
method => $method, |
|
102
|
|
|
|
|
|
|
); |
|
103
|
|
|
|
|
|
|
}; |
|
104
|
|
|
|
|
|
|
} |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub BUILD { |
|
108
|
|
|
|
|
|
|
my ($self,) = @_; |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
foreach my $method ($self->api_methods) { |
|
111
|
|
|
|
|
|
|
$self->meta->add_method( |
|
112
|
|
|
|
|
|
|
$method => sub { |
|
113
|
|
|
|
|
|
|
my ($self, @args) = @_; |
|
114
|
|
|
|
|
|
|
return $self->_handle_api_method($method, @args); |
|
115
|
|
|
|
|
|
|
}); |
|
116
|
|
|
|
|
|
|
} |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
return 1; |
|
119
|
|
|
|
|
|
|
} |
|
120
|
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
|
|
122
|
|
|
|
|
|
|
1; ## eof |
|
123
|
|
|
|
|
|
|
|
|
124
|
|
|
|
|
|
|
__END__ |
|
125
|
|
|
|
|
|
|
|
|
126
|
|
|
|
|
|
|
=pod |
|
127
|
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
=encoding UTF-8 |
|
129
|
|
|
|
|
|
|
|
|
130
|
|
|
|
|
|
|
=head1 NAME |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
WebService::POEditor - POEditor.com API wrapper |
|
133
|
|
|
|
|
|
|
|
|
134
|
|
|
|
|
|
|
=head1 VERSION |
|
135
|
|
|
|
|
|
|
|
|
136
|
|
|
|
|
|
|
version v1.1.0 |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
use WebService::POEditor; |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
my $poeditor = WebService::POEditor->new(api_token => 'XYZ'); |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
## get a list of projects |
|
145
|
|
|
|
|
|
|
my $res = $poeditor->list_projects; |
|
146
|
|
|
|
|
|
|
my @projects = $res->list; |
|
147
|
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
## create a project |
|
149
|
|
|
|
|
|
|
my $res = $poeditor->create_project({ name => 'Project X' }); |
|
150
|
|
|
|
|
|
|
print $res->message if $res->code == 200; ## Project created. |
|
151
|
|
|
|
|
|
|
|
|
152
|
|
|
|
|
|
|
=head1 ATTRIBUTES |
|
153
|
|
|
|
|
|
|
|
|
154
|
|
|
|
|
|
|
=head2 api_token |
|
155
|
|
|
|
|
|
|
|
|
156
|
|
|
|
|
|
|
Set API token L<obtained from POEditor.com|https://poeditor.com/account/api>. |
|
157
|
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
Alternatively, API token can be set via environment variable C<POEDITOR_API_TOKEN>. |
|
159
|
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
=head2 server |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
API server URL. |
|
163
|
|
|
|
|
|
|
|
|
164
|
|
|
|
|
|
|
Can also be altered via environment variable C<POEDITOR_API_SERVER>. |
|
165
|
|
|
|
|
|
|
|
|
166
|
|
|
|
|
|
|
Default: https://poeditor.com/api |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
=head1 METHODS |
|
169
|
|
|
|
|
|
|
|
|
170
|
|
|
|
|
|
|
=head2 API methods |
|
171
|
|
|
|
|
|
|
|
|
172
|
|
|
|
|
|
|
The following API methods (actions) are currently supported: |
|
173
|
|
|
|
|
|
|
|
|
174
|
|
|
|
|
|
|
add_contributor |
|
175
|
|
|
|
|
|
|
add_language |
|
176
|
|
|
|
|
|
|
add_terms |
|
177
|
|
|
|
|
|
|
available_languages |
|
178
|
|
|
|
|
|
|
clear_reference_language |
|
179
|
|
|
|
|
|
|
create_project |
|
180
|
|
|
|
|
|
|
delete_language |
|
181
|
|
|
|
|
|
|
delete_terms |
|
182
|
|
|
|
|
|
|
export |
|
183
|
|
|
|
|
|
|
list_contributors |
|
184
|
|
|
|
|
|
|
list_languages |
|
185
|
|
|
|
|
|
|
list_projects |
|
186
|
|
|
|
|
|
|
set_reference_language |
|
187
|
|
|
|
|
|
|
sync_terms |
|
188
|
|
|
|
|
|
|
update_language |
|
189
|
|
|
|
|
|
|
upload |
|
190
|
|
|
|
|
|
|
view_project |
|
191
|
|
|
|
|
|
|
view_terms |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
The method either takes no arguments (e.g. for listings), or takes one HashRef |
|
194
|
|
|
|
|
|
|
as an argument (e.g. for creation of objects). |
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
The return value is always an instance of L<WebService::POEditor::Response> object. |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
=head1 AUTHOR |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
Roman F. <romanf@cpan.org> |
|
201
|
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
This software is copyright (c) 2013 by Roman F.. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
207
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
=cut |