Module: WikidataAdaptor::RestApi::Labels

Included in:
WikidataAdaptor::RestApi
Defined in:
lib/wikidata_adaptor/rest_api/labels.rb

Overview

Instance Method Summary collapse

Instance Method Details

#delete_item_label(item_id, lang_code, payload) ⇒ String

Delete an Item's label in a specific language.

Parameters:

  • item_id (String)

    The ID of the Item.

  • lang_code (String)

    The language code.

  • payload (Hash)

    Edit metadata (comment).

Returns:

  • (String)

    Confirmation message.



122
123
124
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 122

def delete_item_label(item_id, lang_code, payload)
  delete_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels/#{lang_code}", payload)
end

#delete_property_label(property_id, lang_code, payload) ⇒ String

Delete a Property's label in a specific language.

Parameters:

  • property_id (String)

    The ID of the Property.

  • lang_code (String)

    The language code.

  • payload (Hash)

    Edit metadata (comment).

Returns:

  • (String)

    Confirmation message.



133
134
135
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 133

def delete_property_label(property_id, lang_code, payload)
  delete_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels/#{lang_code}", payload)
end

#get_item_label(item_id, lang_code) ⇒ String

Retrieve an Item's label in a specific language.

Parameters:

  • item_id (String)

    The ID of the required Item.

  • lang_code (String)

    The requested resource language.

Returns:

  • (String)

    Item's label in a specific language.



22
23
24
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 22

def get_item_label(item_id, lang_code)
  get_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels/#{lang_code}")
end

#get_item_label_with_language_fallback(item_id, lang_code) ⇒ String

Retrieve an Item's label in a specific language, using Wikibase language fallback.

NOTE: The OpenAPI spec documents that this endpoint may respond with a redirect (e.g. 307/308) and a Location header. api_adaptor v0.1.0+ follows these redirects.

Parameters:

  • item_id (String)

    The ID of the required Item.

  • lang_code (String)

    The requested resource language.

Returns:

  • (String)

    Item's label in a specific language.



36
37
38
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 36

def get_item_label_with_language_fallback(item_id, lang_code)
  get_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels_with_language_fallback/#{lang_code}")
end

#get_item_labels(item_id) ⇒ Hash

Retrieve an Item's labels.

Parameters:

  • item_id (String)

    The ID of the required Item.

Returns:

  • (Hash)

    Item's labels by language.



12
13
14
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 12

def get_item_labels(item_id)
  get_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels")
end

#get_property_label(property_id, lang_code) ⇒ String

Retrieve a Property's label in a specific language.

Parameters:

  • property_id (String)

    The ID of the required Property.

  • lang_code (String)

    The requested resource language.

Returns:

  • (String)

    Property's label in a specific language.



55
56
57
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 55

def get_property_label(property_id, lang_code)
  get_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels/#{lang_code}")
end

#get_property_label_with_language_fallback(property_id, lang_code) ⇒ String

Retrieve a Property's label in a specific language, using Wikibase language fallback.

NOTE: The OpenAPI spec documents that this endpoint may respond with a redirect (e.g. 307/308) and a Location header. api_adaptor v0.1.0+ follows these redirects.

Parameters:

  • property_id (String)

    The ID of the required Property.

  • lang_code (String)

    The requested resource language.

Returns:

  • (String)

    Property's label in a specific language.



69
70
71
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 69

def get_property_label_with_language_fallback(property_id, lang_code)
  get_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels_with_language_fallback/#{lang_code}")
end

#get_property_labels(property_id) ⇒ Hash

Retrieve a Property's labels.

Parameters:

  • property_id (String)

    The ID of the required Property.

Returns:

  • (Hash)

    Property's labels by language.



45
46
47
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 45

def get_property_labels(property_id)
  get_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels")
end

#patch_item_labels(item_id, payload) ⇒ Hash

Apply JSON Patch operations to an Item's labels.

Parameters:

  • item_id (String)

    The ID of the Item.

  • payload (Hash)

    JSON Patch operations and edit metadata.

Returns:

  • (Hash)

    The updated labels.



101
102
103
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 101

def patch_item_labels(item_id, payload)
  patch_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels", payload)
end

#patch_property_labels(property_id, payload) ⇒ Hash

Apply JSON Patch operations to a Property's labels.

Parameters:

  • property_id (String)

    The ID of the Property.

  • payload (Hash)

    JSON Patch operations and edit metadata.

Returns:

  • (Hash)

    The updated labels.



111
112
113
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 111

def patch_property_labels(property_id, payload)
  patch_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels", payload)
end

#put_item_label(item_id, lang_code, payload) ⇒ String

Replace an Item's label in a specific language.

Parameters:

  • item_id (String)

    The ID of the Item.

  • lang_code (String)

    The language code.

  • payload (Hash)

    Label value and edit metadata.

Returns:

  • (String)

    The new label value.



80
81
82
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 80

def put_item_label(item_id, lang_code, payload)
  put_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/labels/#{lang_code}", payload)
end

#put_property_label(property_id, lang_code, payload) ⇒ String

Replace a Property's label in a specific language.

Parameters:

  • property_id (String)

    The ID of the Property.

  • lang_code (String)

    The language code.

  • payload (Hash)

    Label value and edit metadata.

Returns:

  • (String)

    The new label value.



91
92
93
# File 'lib/wikidata_adaptor/rest_api/labels.rb', line 91

def put_property_label(property_id, lang_code, payload)
  put_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/labels/#{lang_code}", payload)
end