Data Sources: Difference between revisions

m
no edit summary
mNo edit summary
mNo edit summary
Line 1: Line 1:
{{Stamp|2017-02-25|4.3.0|1.1.0}}
{{Stamp|2017-03-05|4.3.0|1.1.0}}


The Autofill facility in Memento allows users to look up information from data sources on the Web, in Memento libraries, or from other data sources. Certain Web data sources are included by default in the Memento application for the convenience of users. For other lookups, a custom data source is needed.
The Autofill facility in Memento allows users to look up information from data sources on the Web, in Memento libraries, or from other data sources. Certain Web data sources are included by default in the Memento application for the convenience of users. For other lookups, a custom data source is needed.
Line 26: Line 26:
The script is executed in the context of the library or entry, so it can use the same functions and objects as a trigger.<br/>A script has the same security parameters as a trigger.<br/>The result of the script should be returned as an array object.
The script is executed in the context of the library or entry, so it can use the same functions and objects as a trigger.<br/>A script has the same security parameters as a trigger.<br/>The result of the script should be returned as an array object.


=== Step 3 &mdash; Settings for autofill rules ===
After the script is written, it is necessary to map the properties of the returned object to the fields of the library:
# Close the script edit card and click <big>'''+'''</big>.
# This will open the card for creation of autofill rules.
# Identify the object property returned by the script.
# Select the library field to receive the data.
# Create rules for the remaining object properties.
== Script Details ==
The API specific to data sources is as follows.
:; result(objects, getDetailsFunction): Function to return the initial result of the script &mdash; an array of objects representing the search results and a function to be called for details.
:; result(objects, getDetailsFunction): Function to return the initial result of the script &mdash; an array of objects representing the search results and a function to be called for details.
:: '''Arguments'''
:: '''Arguments'''
Line 37: Line 47:
:::; thumb: Reference to the image of the object
:::; thumb: Reference to the image of the object
:::; id: Object identifier. Used if the result() is called with a second argument.
:::; id: Object identifier. Used if the result() is called with a second argument.
=== Examples ===


==== Example &mdash; Filling data from another library ====
==== Example &mdash; Filling data from another library ====
Line 45: Line 57:
[[TBD]]
[[TBD]]


==== Additional data load ====
=== Additional data load ===
Many services (APIs) return general information without details as a result of a search. To extract complete detailed information, an additional API request is needed. In this case, a function for additional data load should be used. The argument for this function is the identifier of the object selected by the user. The function returns an object whose parameters will be loaded into the fields of the entry according to autofill rules. As an example, let's use an API with two methods:
Many services (APIs) return general information without details as a result of a search. To extract complete detailed information, an additional API request is needed. In this case, a function for additional data load should be used. The argument for this function is the identifier of the object selected by the user. The function returns an object whose parameters will be loaded into the fields of the entry according to autofill rules. As an example, let's use an API with two methods:
# http://api.example.com/search?q='search query' &mdash; This API does a search for an object and returns only identifiers and names of the objects. The result is a JSON array of objects. Each object has a ''title'' and an ''id'' properties.
# http://api.example.com/search?q='search query' &mdash; This API does a search for an object and returns only identifiers and names of the objects. The result is a JSON array of objects. Each object has a ''title'' and an ''id'' properties.
# http://api.example.com/get?id=123 &mdash; Receive the detail information of the object based on the id. The result is a JSON object.
# http://api.example.com/get?id=123 &mdash; Receive the detail information of the object based on the id. The result is a JSON object.


Scipted data source can be as follows:
Scripted data source can be as follows:
: [[insert code]]
: [[insert code]]
=== Step 3 &mdash; Settings for autofill rules ===
After the script is written, it is necessary to map the properties of the returned object to the fields of the library:
# Close the script edit card and click <big>'''+'''</big>.
# This will open the card for creation of autofill rules.
# Identify the object property returned by the script.
# Select the library field to receive the data.
# Create rules for the remaining object properties.
==== Example &mdash; Web data source ====
==== Example &mdash; Web data source ====
Let's consider service http://www.discogs.com/ &mdash; Provides information about music albums. This service has an API documented as http://www.discogs.com/developers.
Let's consider service http://www.discogs.com/ &mdash; Provides information about music albums. This service has an API documented as http://www.discogs.com/developers.