Data Sources: Difference between revisions

Jump to navigation Jump to search
m
no edit summary
mNo edit summary
mNo edit summary
(8 intermediate revisions by 2 users not shown)
Line 1: Line 1:
{{Stamp|2017-03-05|4.3.0|1.1.0}}
{{Stamp|2017-03-05|4.3.0|1.0.9}}


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 16: Line 16:
# Open the Library Edit screen, click on the Autofill tab, and then click <big>'''+'''</big>.
# Open the Library Edit screen, click on the Autofill tab, and then click <big>'''+'''</big>.
# Select the type of search &mdash; By Name or By Barcode.
# Select the type of search &mdash; By Name or By Barcode.
# Select '''Custom source'''.
# Select "Custom source".
# Select the field to be used for data search within the source.
# Select the field to be used for data search within the source.
# You are presented with an Autofill Data Load Rules edit card. For each field to be loaded from the data source, enter the object property name that will identify that field. Then, select the field to be loaded from that property.
# You are presented with an Autofill Data Load Rules edit card. For each field to be loaded from the data source, enter the object property name that will identify that field. Then, select the field to be loaded from that property.
Line 27: Line 27:
The result of the script should be returned as an array object.
The result of the script should be returned as an array object.


See [[#Scripting Details|Scripting Details]] below for details on script writing.
See [[#Scripting details|Scripting Details]] below for details on script writing.


=== Step 3 &mdash; Set Autofill data load rules (Map data to fields) ===
=== Step 3 &mdash; Set Autofill data load rules (Map data to fields) ===
Line 53: Line 53:
To extract all available information for an individual object, an additional source service request is needed. In this case, a function for additional data load should be passed via the ''result()'' call as a second argument &mdash; ''result(sourceObjects, fullFetchFunction)''.
To extract all available information for an individual object, an additional source service request is needed. In this case, a function for additional data load should be passed via the ''result()'' call as a second argument &mdash; ''result(sourceObjects, fullFetchFunction)''.


The function call will supply one argument &mdash; the identifier previously returned for the object selected by the user. The function then returns an object containing a full set of properties, which will be loaded into the fields of the library entry according to Autofill rules.
The function call will supply one argument &mdash; ''id'', the identifier previously returned for the object selected by the user. The function then returns an object containing a full set of properties, which will be loaded into the fields of the library entry according to Autofill rules.


As an example, let's consider a Web service with an API having two methods:
As an example, let's consider a Web service with an API having two methods:
Line 93: Line 93:
So, to do this, we edit the receiving library, go to the Autofill tab, and press the <big>'''+'''</big> button to add a set of Autofill rules and then select whether the search is to be by title or by barcode.
So, to do this, we edit the receiving library, go to the Autofill tab, and press the <big>'''+'''</big> button to add a set of Autofill rules and then select whether the search is to be by title or by barcode.


Let's create the script now, so tap the top bar called '''script editor''' to open the card. Paste the following script into the editor. Then follow the instructions above to make it do what you want. You can test the script by tapping the Play button. The message at the bottom of the card should say "successful".
Let's create the script now, so tap the top bar called '''script editor''' to open the card. Paste the following script into the editor. Then follow the instructions above to make it do what you want. You can test the script by tapping the Play button. The message at the bottom of the card should say something like "Successfully executed script".


<source lang="JavaScript">
<source lang="JavaScript">
var anotherLib = libByName(“AnotherLib”)          // Replace with yours
var anotherLib = libByName(“AnotherLib”);         // Replace with yours
var entries = anotherLib.find(query);
var entries = anotherLib.find(query);
var resultArray = [];
var resultArray = [];
Line 118: Line 118:
# Click '''Add JavaScript libraries'''
# Click '''Add JavaScript libraries'''
# Click on tab '''Repositories'''
# Click on tab '''Repositories'''
# Select repository '''''github.com/mementodatabase/script/data-sources'''''
# Select repository '''''github.com/mementodatabase/scripts/data-sources'''''
# Select '''''discogs.js'''''
# Select '''''discogs.js'''''


Line 130: Line 130:
* Consumer key and consumer secret are the keys required to execute the request. They may be obtained at http://discogs.com/settings/developers.
* Consumer key and consumer secret are the keys required to execute the request. They may be obtained at http://discogs.com/settings/developers.
* After the script is written, it is necessary to map the object properties to the fields of the library. Available object properties are documented in the discogs API documentation. See an example of a response to a successful request at https://www.discogs.com/developers/#page:database,header:database-release.
* After the script is written, it is necessary to map the object properties to the fields of the library. Available object properties are documented in the discogs API documentation. See an example of a response to a successful request at https://www.discogs.com/developers/#page:database,header:database-release.
* If the search in the data source is done by barcode, use discogs.barcode(query) instead of discogs.search(query).
* If the search in the data source is done by barcode, use ''discogs.barcode(query)'' instead of ''discogs.search(query)''.


[[Category:Spec]]
[[Category:en]] [[Category:Spec]]

Navigation menu