Module: WikidataAdaptor::RestApi::Statements

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

Overview

Instance Method Summary collapse

Instance Method Details

#delete_item_statement(item_id, statement_id, payload) ⇒ String

Delete a Statement from an Item.

Parameters:

  • item_id (String)

    The ID of the Item.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Edit metadata (comment).

Returns:

  • (String)

    Confirmation message.



127
128
129
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 127

def delete_item_statement(item_id, statement_id, payload)
  delete_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/statements/#{statement_id}", payload)
end

#delete_property_statement(property_id, statement_id, payload) ⇒ String

Delete a Statement from a Property.

Parameters:

  • property_id (String)

    The ID of the Property.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Edit metadata (comment).

Returns:

  • (String)

    Confirmation message.



138
139
140
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 138

def delete_property_statement(property_id, statement_id, payload)
  delete_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/statements/#{statement_id}", payload)
end

#delete_statement(statement_id, payload) ⇒ String

Delete a Statement (global).

Parameters:

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Edit metadata (comment).

Returns:

  • (String)

    Confirmation message.



148
149
150
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 148

def delete_statement(statement_id, payload)
  delete_json("#{endpoint}/v1/statements/#{statement_id}", payload)
end

#get_item_statement(item_id, statement_id) ⇒ Object

Retrieve a single Statement from an Item.



17
18
19
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 17

def get_item_statement(item_id, statement_id)
  get_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/statements/#{statement_id}")
end

#get_item_statements(item_id, params = { property: nil }) ⇒ Object

Retrieve Statements from an Item.

Optional filter: params[:property] => property ID (e.g., "P31")



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

def get_item_statements(item_id, params = { property: nil })
  query = params[:property] ? "?property=#{CGI.escape(params[:property])}" : ""
  get_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/statements#{query}")
end

#get_property_statement(property_id, statement_id) ⇒ Object

Retrieve a single Statement from a Property.



42
43
44
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 42

def get_property_statement(property_id, statement_id)
  get_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/statements/#{statement_id}")
end

#get_property_statements(property_id) ⇒ Object

Retrieve Statements from a Property.



37
38
39
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 37

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

#get_statement(statement_id) ⇒ Object

Retrieve a single Statement (global).



32
33
34
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 32

def get_statement(statement_id)
  get_json("#{endpoint}/v1/statements/#{statement_id}")
end

#patch_item_statement(item_id, statement_id, payload) ⇒ Hash

Apply JSON Patch operations to a Statement on an Item.

Parameters:

  • item_id (String)

    The ID of the Item.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    JSON Patch operations and edit metadata.

Returns:

  • (Hash)

    The updated Statement.



95
96
97
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 95

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

#patch_property_statement(property_id, statement_id, payload) ⇒ Hash

Apply JSON Patch operations to a Statement on a Property.

Parameters:

  • property_id (String)

    The ID of the Property.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    JSON Patch operations and edit metadata.

Returns:

  • (Hash)

    The updated Statement.



106
107
108
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 106

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

#patch_statement(statement_id, payload) ⇒ Hash

Apply JSON Patch operations to a Statement (global).

Parameters:

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    JSON Patch operations and edit metadata.

Returns:

  • (Hash)

    The updated Statement.



116
117
118
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 116

def patch_statement(statement_id, payload)
  patch_json("#{endpoint}/v1/statements/#{statement_id}", payload)
end

#post_item_statement(item_id, payload) ⇒ Hash

Add a Statement to an Item.

Parameters:

  • item_id (String)

    The ID of the Item.

  • payload (Hash)

    Statement and edit metadata.

Returns:

  • (Hash)

    The newly created Statement.



27
28
29
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 27

def post_item_statement(item_id, payload)
  post_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/statements", payload)
end

#post_property_statement(property_id, payload) ⇒ Hash

Add a Statement to a Property.

Parameters:

  • property_id (String)

    The ID of the Property.

  • payload (Hash)

    Statement and edit metadata.

Returns:

  • (Hash)

    The newly created Statement.



52
53
54
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 52

def post_property_statement(property_id, payload)
  post_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/statements", payload)
end

#put_item_statement(item_id, statement_id, payload) ⇒ Hash

Replace a Statement on an Item.

Parameters:

  • item_id (String)

    The ID of the Item.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Statement and edit metadata.

Returns:

  • (Hash)

    The replaced Statement.



63
64
65
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 63

def put_item_statement(item_id, statement_id, payload)
  put_json("#{endpoint}/v1/entities/items/#{CGI.escape(item_id)}/statements/#{statement_id}", payload)
end

#put_property_statement(property_id, statement_id, payload) ⇒ Hash

Replace a Statement on a Property.

Parameters:

  • property_id (String)

    The ID of the Property.

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Statement and edit metadata.

Returns:

  • (Hash)

    The replaced Statement.



74
75
76
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 74

def put_property_statement(property_id, statement_id, payload)
  put_json("#{endpoint}/v1/entities/properties/#{CGI.escape(property_id)}/statements/#{statement_id}", payload)
end

#put_statement(statement_id, payload) ⇒ Hash

Replace a Statement (global).

Parameters:

  • statement_id (String)

    The Statement ID.

  • payload (Hash)

    Statement and edit metadata.

Returns:

  • (Hash)

    The replaced Statement.



84
85
86
# File 'lib/wikidata_adaptor/rest_api/statements.rb', line 84

def put_statement(statement_id, payload)
  put_json("#{endpoint}/v1/statements/#{statement_id}", payload)
end