internet archive metadata api helper methods.
the methods in this module have been created based on the The Internet Archive Metadata API blog post, which apply to internet archive items that already exist in the internet archive database.
- installation
- use
- license
npm install internet-archive-metadata-api
this module provides two main methods: read
and write
, however, getRequestOptions
and postRequestOptions
are also exposed for those that would rather initiate the request in a different manner than this module does with request-as-bluebird.
* @param {Object} [user_options]
* @param {Object} [request_options]
* @returns {Object}
var user_options = {
count: number,
identifier: string,
index: number,
start: number
type: string
};
used in conjunction with the files
endpoint to indicate the limit of file objects returned.
used in conjunction with all endpoints to determine which resource to retrieve.
used in the collection_index
and files_index
endpoints.
used in conjunction with the files
endpoint to indicate which file object, in the total file list available, to begin returning.
used in conjunction with all endpoints, defaults to all
.
this object refers the request_headers
object used by the generic-request-options module, which is used internally by this module.
api-endpoints available can be found in the get-api-endpoint.js file and refer to the Sub-item Access
section of the internet archive metadata api documentation.
the colon prefixed terms in the api endpoint urls are replaced with matching user_options properties; e.g. :identifier
, and :index
would be replaced with values indicated in the user_options
object.
var getRequestOptions = require( 'internet-archive-metadata-api' ).getRequestOptions;
var user_options = {
identifier: 'frenchenglishmed00gorduoft',
index: 1,
type: 'collection_index'
};
var request_options = getRequestOptions( user_options );
request_options => {
identifier: 'frenchenglishmed00gorduoft',
index: 1,
type: 'collection_index',
headers: { 'user-agent': 'node.js/v4.6.0 request (https://www.npmjs.com/package/request)' },
timeout: 10000,
method: 'get',
qs: {},
url: 'https://archive.org/metadata/frenchenglishmed00gorduoft/metadata/collection/1'
}
* @param {Object} [user_options]
* @param {Object} [request_options]
* @returns {Promise.<{ body:string, response:IncomingMessage }>}
see request_headers ( get/post )
var read = require( 'internet-archive-metadata-api' ).read;
var user_options = { identifier: 'frenchenglishmed00gorduoft' };
read( user_options )
.then(
/**
* {{ body:string, response:IncomingMessage }} result
*/
function( result ) {
var json = JSON.parse( result.body );
}
)
.catch();
* @param {Object} [user_options]
* @param {Object} [request_options]
* @returns {Object}
var user_options = {
access: string,
identifier: string,
patch: string,
secret: string,
target: string
};
your ia-s3 access key, which can be obtained by logging into your internet archive account and requesting an ia-s3 key.
determines which internet archive resource will be affected by the write.
the updates you want to apply to the internet archive item indicated by the identifier
. they should be a string containing an array of valid json patches 02. for example:
patch: '[ { "add": "/description", "value": "Testing the limits ..." }, { "add": "/publisher", "value": "Philadelphia P. Blakiston" } ]'
your ia-s3 secret key, which can be obtained by logging into your internet archive account and requesting an ia-s3 key.
one of the following values:
- metadata
- targets the metadata object for the item, which can be viewed at
http://archive.org/metadata/:identifier/metadata
; e.g., http://archive.org/metadata/frenchenglishmed00gorduoft/metadata
- targets the metadata object for the item, which can be viewed at
- files/:filename
- targets the file metadata for the item indicated by the
identifier
- replace :filename with the filename you wish to affect
- a list of available files; e.g., http://archive.org/metadata/frenchenglishmed00gorduoft/files
- target the
frenchenglishmed00gorduoft_marc.xml
file by setting the target tofiles/frenchenglishmed00gorduoft_marc.xml
- targets the file metadata for the item indicated by the
- other
- targets the other object for the item, which can be viewed at
http://archive.org/metadata/:identifier/other
; e.g., http://archive.org/metadata/frenchenglishmed00gorduoft/other
- targets the other object for the item, which can be viewed at
var postRequestOptions = require( 'internet-archive-metadata-api' ).postRequestOptions;
var user_options = {
access: 's3-access-token',
identifier: 'test-api',
patch: '[ { "add": "/description", "value": "Testing the limits ..." }, { "add": "/publisher", "value": "Philadelphia P. Blakiston" } ]',
secret: 's3-secret',
target: 'metadata'
};
var request_options = postRequestOptions( user_options );
request_options => {
headers: { 'user-agent': 'node.js/v4.6.0 request (https://www.npmjs.com/package/request)' },
form: {
access: 's3-access-token',
'-patch': '%5B%20%7B%20%22add%22%3A%20%22%2Fdescription%22%2C%20%22value%22%3A%20%22Testing%20the%20limits%20...%22%20%7D%2C%20%7B%20%22add%22%3A%20%22%2Fpublisher%22%2C%20%22value%22%3A%20%22Philadelphia%20P.%20Blakiston%22%20%7D%20%5D',
secret: 's3-secret',
'-target': 'metadata'
},
method: 'post',
timeout: 10000,
url: 'https://archive.org/metadata/test-api'
}
* @param {Object} [user_options]
* @param {Object} [request_options]
* @returns {Promise.<{ body:string, response:IncomingMessage }>}
see request_headers ( get/post )
var write = require( 'internet-archive-metadata-api' ).write;
var user_options = {
access: '<your-ia-s3-access-token>',
identifier: 'test-api',
patch: '[ { "add": "/publisher", "value": "Philadelphia P. Blakiston" } ]',
secret: '<your-ia-s3-secret>',
target: 'metadata'
};
write( user_options )
.then(
/**
* {{ body:string, response:IncomingMessage }} result
*/
function( result ) {
var json = JSON.parse( result.body );
}
)
.catch();