-
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathREADME
372 lines (312 loc) · 12.7 KB
/
README
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
NAME
Wikibase::API - Wikibase API class.
SYNOPSIS
use Wikibase::API;
my $obj = Wikibase::API->new(%params);
my $res = $obj->create_item($item_obj, $summary);
my $item_obj = $obj->get_item($id);
my $struct_hr = $obj->get_item_raw($id);
METHODS
"new"
my $obj = Wikibase::API->new(%params);
Constructor.
* "login_name"
Login name.
Default value is undef.
* "login_password"
Login password.
Default value is undef.
* "mediawiki_api"
MediaWiki::API object.
Default value is MediaWiki::API->new.
* "mediawiki_site"
MediaWiki site.
Default value is 'test.wikidata.org'.
Returns instance of object.
"create_item"
my $res = $obj->create_item($item_obj, $summary);
Create item in system. $item_obj is Wikibase::Datatype::Item instance.
$summary is text comment of change.
Returns reference to hash like this:
{
'entity' => {
...
},
'success' => __STATUS_CODE__,
}
"get_item"
my $item_obj = $obj->get_item($id);
Get item from system.
Returns Wikibase::Datatype::Item instance.
"get_item_raw"
my $struct_hr = $obj->get_item_raw($id);
Get item raw structure as Perl hash.
Returns reference to hash.
ERRORS
new():
From Class::Utils::set_params():
Unknown parameter '%s'.
Cannot login.
Error code: %s
Error details: %s
Cannot get token.
Error code: %s
Error details: %s
create_item():
Bad data. Not supported object.
EXAMPLE1
use strict;
use warnings;
use Data::Printer;
use Wikibase::API;
use Wikibase::Datatype::Item;
# API object.
my $api = Wikibase::API->new;
# Wikibase::Datatype::Item blank object.
my $item_obj = Wikibase::Datatype::Item->new;
# Create item.
my $res = $api->create_item($item_obj);
# Dump response structure.
p $res;
# Output like:
# \ {
# entity {
# aliases {},
# claims {},
# descriptions {},
# id "Q213698",
# labels {},
# lastrevid 535146,
# sitelinks {},
# type "item"
# },
# success 1
# }
EXAMPLE2
use strict;
use warnings;
use Data::Printer;
use Wikibase::API;
if (@ARGV < 1) {
print STDERR "Usage: $0 id\n";
exit 1;
}
my $id = $ARGV[0];
# API object.
my $api = Wikibase::API->new;
# Get item.
my $item_obj = $api->get_item($id);
# Dump response structure.
p $item_obj;
# Output for Q213698 argument like:
# Wikibase::Datatype::Item {
# Parents Mo::Object
# public methods (9) : BUILD, can (UNIVERSAL), DOES (UNIVERSAL), err (Error::Pure), check_array_object (Mo::utils), check_number (Mo::utils), check_number_of_items (Mo::utils), isa (UNIVERSAL), VERSION (UNIVERSAL)
# private methods (1) : __ANON__ (Mo::is)
# internals: {
# aliases [],
# descriptions [],
# id "Q213698",
# labels [],
# lastrevid 535146,
# modified "2020-12-11T22:26:06Z",
# ns 0,
# page_id 304259,
# sitelinks [],
# statements [],
# title "Q213698"
# }
# }
EXAMPLE3
use strict;
use warnings;
use Data::Printer;
use Wikibase::API;
if (@ARGV < 1) {
print STDERR "Usage: $0 id\n";
exit 1;
}
my $id = $ARGV[0];
# API object.
my $api = Wikibase::API->new;
# Get item.
my $struct_hr = $api->get_item_raw($id);
# Dump response structure.
p $struct_hr;
# Output for Q213698 argument like:
# {
# aliases {},
# claims {
# P623 [
# [0] {
# id "Q213698$89A385A8-2BE1-46CA-85FF-E0B53DEBC0F0",
# mainsnak {
# datatype "string",
# datavalue {
# type "string",
# value "101 Great Marques /Andrew Whyte." (dualvar: 101)
# },
# hash "db60f4054e0048355b75a07cd84f83398a84f515",
# property "P623",
# snaktype "value"
# },
# qualifiers {
# P446 [
# [0] {
# datatype "string",
# datavalue {
# type "string",
# value "a[1] c[1]"
# },
# hash "831cae40e488a0e8f4b06111ab3f1e1f8c42e79a" (dualvar: 831),
# property "P446",
# snaktype "value"
# }
# ],
# P624 [
# [0] {
# datatype "string",
# datavalue {
# type "string",
# value 1
# },
# hash "32eaf6cc04d6387b0925aea349bba4e35d2bc186" (dualvar: 32),
# property "P624",
# snaktype "value"
# }
# ],
# P625 [
# [0] {
# datatype "string",
# datavalue {
# type "string",
# value 0
# },
# hash "7b763330efc9d8269854747714d91ae0d0bc87a0" (dualvar: 7),
# property "P625",
# snaktype "value"
# }
# ],
# P626 [
# [0] {
# datatype "string",
# datavalue {
# type "string",
# value "101 Great Marques /" (dualvar: 101)
# },
# hash "0d2c3b012d13b9de1477bae831bd6d61a46e8c64",
# property "P626",
# snaktype "value"
# }
# ],
# P628 [
# [0] {
# datatype "string",
# datavalue {
# type "string",
# value "Andrew Whyte."
# },
# hash "a2c9c46ce7b17b13b197179fb0e5238965066211",
# property "P628",
# snaktype "value"
# }
# ]
# },
# qualifiers-order [
# [0] "P624",
# [1] "P626",
# [2] "P628",
# [3] "P446",
# [4] "P625"
# ],
# rank "normal",
# references [
# [0] {
# hash "98b2538ea26ec4da8e4aab27e74f1d832490a846" (dualvar: 98),
# snaks {
# P9 [
# [0] {
# datatype "wikibase-item",
# datavalue {
# type "wikibase-entityid",
# value {
# entity-type "item",
# id "Q1886",
# numeric-id 1886
# }
# },
# hash "271c3f13dd08a66f38eb2571d2f338e8b4b8074a" (dualvar: 271),
# property "P9",
# snaktype "value"
# }
# ],
# P21 [
# [0] {
# datatype "url",
# datavalue {
# type "string",
# value "http://lccn.loc.gov/87103973/marcxml"
# },
# hash "1e253d1dcb9867353bc71fc7c661cdc777e14885" (dualvar: 1e+253),
# property "P21",
# snaktype "value"
# }
# ]
# },
# snaks-order [
# [0] "P9",
# [1] "P21"
# ]
# }
# ],
# type "statement"
# }
# ]
# },
# descriptions {
# en {
# language "en",
# value 87103973
# },
# it {
# language "it",
# value 87103973
# }
# },
# id "Q213698",
# labels {
# en {
# language "en",
# value "101 Great Marques /" (dualvar: 101)
# },
# it {
# language "it",
# value "101 Great Marques /" (dualvar: 101)
# }
# },
# lastrevid 538778,
# modified "2021-03-20T14:35:50Z" (dualvar: 2021),
# ns 0,
# pageid 304259,
# sitelinks {},
# title "Q213698",
# type "item"
# }
DEPENDENCIES
Class::Utils, Error::Pure, JSON::XS, MediaWiki::API, Unicode::UTF8,
Wikibase::Datatype::Item.
SEE ALSO
Wikibase::Datatype
Wikibase datatypes.
Wikibase::Datatype::Struct
Wikibase structure serialization.
REPOSITORY
<https://github.com/michal-josef-spacek/Wikibase-API>
AUTHOR
Michal Josef Špaček <mailto:skim@cpan.org>
<http://skim.cz>
LICENSE AND COPYRIGHT
© 2020-2025 Michal Josef Špaček
BSD 2-Clause License
VERSION
0.08