NAME Wikibase::API - Wikibase API class. SYNOPSIS use Wikibase::API; my $obj = Wikibase::API->new(%params); my $res = $obj->create_item($item_obj); 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) Create item in system. $item_obj is Wikibase::Datatype::Item instance. 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. Must be 'Wikibase::Datatype::Item' 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 AUTHOR Michal Josef Špaček LICENSE AND COPYRIGHT © 2020-2024 Michal Josef Špaček BSD 2-Clause License VERSION 0.05