DaemonApi

DaemonApi

Class to make HTTP calls to an OIP Daemon




Constructor

new DaemonApi(daemonUrlopt)

Examples

Spawn an OIP Daemon API (OIPdAPI) that connects to a local running daemon

import {DaemonApi} from 'js-oip'

let oipd = new DaemonApi("localhost:1606") //leave blank for default API URL
let latestArtifacts = await oipd.getLatestArtifacts()
Parameters:
Name Type Attributes Default Description
daemonUrl String <optional>
"https://api.oip.io/oip"

The URL of an OIP Daemon

Source:

Methods




createQs(args) → {string}

Generate a complex querystring for elasticsearch

Parameters:
Name Type Description
args Array.<queryObject>

An array of objects that follow given example

Source:
Examples

Search for both Research and Music artifact types that were created in 2017

let args = [
     {operator: "wrap", type: 'start'},
     {field: "artifact.details.defocus", query: "-10"},
     {operator: "AND"},
     {field: "artifact.details.microscopist", query: "Yiwei Chang"},
     {operator: "wrap", type: "end"},
     {operator: "OR"},
     {operator: "wrap", type: "start"},
     {field: "artifact.details.defocus", query: "-8"},
     {operator: "AND"},
     {field: "artifact.details.microscopist", query: "Ariane Briegel"},
     {operator: "wrap", type: "end"},
]
//the query would end up looking something like:
let query = "(artifact.details.defocus:"-10" AND artifact.details.microscopist:"Yiwei Chang") OR (artifact.details.defocus:"-8" AND artifact.details.microscopist:"Ariane Briegel")"
let querystring = this.generateQs(args)
querystring === query //true
let {artifacts} = await this.searchArtifacts(querystring)
Returns:
Type:
string



(async) get041Artifact(txid) → {Promise.<Object>}

Get a version 41 Artifact from the Index by TXID

Parameters:
Name Type Description
txid TXID

transaction id of the artifact you wish to retrieve

Source:
Example
let txid = '8c204c5f39b67431c59c7703378b2cd3b746a64743e130de0f5cfb2118b5136b'
let {success, artifact, error} = await DaemonApi.get041Artifact(txid)
Returns:
Type:
Promise.<Object>



(async) get041Artifacts(txids) → {Promise.<Object>}

Get multiple OIP041 artifact by their TXID

Parameters:
Name Type Description
txids Array.<TXID>

an array of transaction IDs

Source:
Example
const txid1 = '8c204c5f39b67431c59c7703378b2cd3b746a64743e130de0f5cfb2118b5136b'
const txid2 = 'a690609a2a8198fbf4ed3fd7e4987637a93b7e1cad96a5aeac2197b7a7bf8fb9'
const txid3 = 'b4e6c9e86d14ca3565e57fed8b482d742a7a1cff0dd4cabfe9e3ea29efb3211c'
let txArray = [txid1, txid2, txid3]
let {success, artifacts, error} = await DaemonApi.get041Artifacts(txArray)
Returns:
Type:
Promise.<Object>



(async) getAlexandriaMediaArtifact(txid) → {Promise.<Object>}

Get an Alexandria Media Artifact (version "40") from the Index by TXID

Parameters:
Name Type Description
txid TXID

transaction id of the artifact you wish to retrieve

Source:
Example
let txid = '756f9199c8992cd42c750cbd73d1fa717b31feafc3b4ab5871feadae9848acac'
let {success, artifact, error} = await DaemonApi.getAlexandriaMediaArtifact(txid)
Returns:
Type:
Promise.<Object>



(async) getAlexandriaMediaArtifacts(txids) → {Promise.<Object>}

Get one or more Alexandria Media (version "40") artifacts by their TXID

Parameters:
Name Type Description
txids Array.<TXID>

an array of transaction IDs

Source:
Example
const txid1 = '33e04cb2dcf7004a460d0719eea36129ebaf48fb10cffff19653bfeeca9bc7ad'
const txid2 = 'a2110a1058b620d91bc78ad71e466d736f6b8b078025d19c23ddac6a3c0355ee'
const txid3 = 'b6f89f3c6410276f7d4cf9c3c58c4f0577495650e742e71dddc669c9e912217c'
let txArray = [txid1, txid2, txid3]
let {success, artifacts, error} = await DaemonApi.getAlexandriaMediaArtifacts(txArray)
Returns:
Type:
Promise.<Object>



(async) getArtifact(txid) → {Promise.<Object>}

Get an Artifact from the Index by TXID

Parameters:
Name Type Description
txid TXID

transaction id of the artifact you wish to retrieve

Source:
Example
let txid = 'cc9a11050acdc4401aec3f40c4cce123d99c0f2c27d4403ae4a2536ee38a4716'
let {success, artifact, error} = await DaemonApi.getArtifact(txid)
Returns:
Type:
Promise.<Object>



(async) getArtifacts(txids) → {Promise.<Object>}

Get multiple artifacts by TXID

Parameters:
Name Type Description
txids Array.<TXID>

an array of transaction IDs

Source:
Example
const txid1 = '6ffbffd475c7eabe0acc664087ac56c13ac7c2084746619182b360c2f19e430e'
const txid2 = 'f72c314d257d8062581788ab56bbe4ab1dc09dafb7961866903d1144575a3b48'
const txid3 = '0be3e260a9ff71464383e328d05d9e85984dd6636626bc0356eae8440de150aa'
let txArray = [txid1, txid2, txid3]
let {success, artifacts, error} = await DaemonApi.getArtifacts(txArray)
Returns:
Type:
Promise.<Object>



(async) getFloData(txid) → {Promise.<Object>}

Get floData by TXID

Parameters:
Name Type Description
txid TXID

the transaction id you wish to grab the floData from

Source:
Example
let txid = '83452d60230d3c2c69000c2a79da79fe60cdf63012f946ac46e6df3409fb1fa7'
let {success, tx, error} = await DaemonApi.getFloData(txid)
let floData = tx.floData
Returns:
Type:
Promise.<Object>



(async) getHistorianData(txid) → {Promise.<Object>}

Get a historian data point by its txid

Parameters:
Name Type Description
txid TXID
Source:
Example
let id = '83452d60230d3c2c69000c2a79da79fe60cdf63012f946ac46e6df3409fb1fa7'
let {success, hdata, error} = await DaemonApi.getHistorianData(id)
Returns:
Type:
Promise.<Object>



(async) getLastestHistorianData(limitopt) → {Promise.<Object>}

Get the latest historian data points

Parameters:
Name Type Attributes Default Description
limit number <optional>
100
Source:
Example
let {success, hdata, error} = await DaemonApi.getLastestHistorianData()
Returns:
Type:
Promise.<Object>



(async) getLatest041Artifacts(limitopt, nsfwopt) → {Promise.<Object>}

Get the latest version 41 artifacts published to the Index

Parameters:
Name Type Attributes Default Description
limit number <optional>
100

The amount of artifact you want returns ( max: 1000 )

nsfw boolean <optional>
false

not safe for work

Source:
Example
const limit = 50
let {success, artifacts, error} = await DaemonApi.getLatest041Artifacts(limit)
Returns:
Type:
Promise.<Object>



(async) getLatest042Artifacts(limitopt, nsfwopt) → {Promise.<Object>}

Get the version 42 artifacts published to the Index

Parameters:
Name Type Attributes Default Description
limit number <optional>
100

The amount of artifact you want returns ( max: 1000 )

nsfw boolean <optional>
false

not safe for work artifact

Source:
Example
const limit = 50
let {success, artifacts, error} = await DaemonApi.getLatest042Artifacts(limit)
Returns:
Type:
Promise.<Object>



(async) getLatestAlexandriaMediaArtifacts(limitopt, nsfwopt) → {Promise.<Object>}

Get the latest Alexandria Media artifacts (version "40") published to the Index

Parameters:
Name Type Attributes Default Description
limit number <optional>
100

The amount of artifact you want returns ( max: 1000 )

nsfw boolean <optional>
false

not safe for work

Source:
Example
const limit = 50
let {success, artifacts, error} = await DaemonApi.getLatestAlexandriaMediaArtifacts(limit)
Returns:
Type:
Promise.<Object>



(async) getLatestArtifacts(limitopt, nsfwopt) → {Promise.<Object>}

Get the latest artifacts published to the Index

Parameters:
Name Type Attributes Default Description
limit number <optional>
100

The amount of artifact you want returns ( max: 1000 )

nsfw boolean <optional>
false

not safe for work

Source:
Example
let limit = 50
let {success, artifacts, error} = await DaemonApi.getLatestArtifacts(limit)
Returns:
Type:
Promise.<Object>



(async) getLatestOip5Records(optionsopt) → {Promise.<Object>}

Get latest oip5 records

Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Default Description
limit number <optional>
10

max num of results

after string <optional>

the string ID returned on response to get the next set of data

pages number <optional>

page number

sort string <optional>

sort field ascending or descending. Format must match: ([0-9a-zA-Z._-]+:[ad]$?)+

Source:
Returns:
Type:
Promise.<Object>



(async) getLatestOip5Templates(optionsopt) → {Promise.<Object>}

Get latest oip5 templates

Parameters:
Name Type Attributes Description
options Object <optional>
Properties
Name Type Attributes Default Description
limit number <optional>
10

max num of results

after string <optional>

the string ID returned on response to get the next set of data

pages number <optional>

page number

sort string <optional>

sort field ascending or descending. Format must match: ([0-9a-zA-Z._-]+:[ad]$?)+

Source:
Returns:
Type:
Promise.<Object>



(async) getMultipart(txid) → {Promise.<Object>}

Get a Multipart Single by its TXID

Parameters:
Name Type Description
txid TXID

transaction id of the single multipart

Source:
Example
let txid = 'f550b9739e7453224075630d44cba24c31959af913aeb7cb364a563f96f54548'
let {success, multipart, error} = await DaemonApi.getMultipart(txid)
Returns:
Type:
Promise.<Object>



(async) getMultiparts(ref, limitopt) → {Promise.<Object>}

Get OIP Multiparts by the First TXID Reference

Parameters:
Name Type Attributes Description
ref string

the TXID reference of the first multipart

limit number <optional>

max num of results

Source:
Example
let ref = '8c204c5f39'
let {success, multiparts, error} = await DaemonApi.getMultiparts(ref)
Returns:
Type:
Promise.<Object>



getNetwork() → {axios}

Get Axios Instance

Source:
Returns:
Type:
axios



(async) getOip5Mapping(tmplIdentifiersopt) → {Promise.<Object>}

Get oip5 template

Parameters:
Name Type Attributes Description
tmplIdentifiers string | Array.<string> <optional>

'template identifiers' transaction IDs'

Source:
Returns:
Type:
Promise.<Object>



(async) getOip5Record(txidopt) → {Promise.<Object>}

Get oip5 record

Parameters:
Name Type Attributes Description
txid string <optional>

transaction id of record

Source:
Returns:
Type:
Promise.<Object>



(async) getOip5Records(txids) → {Promise.<Array.<Object>>}

Get oip5 records

Parameters:
Name Type Description
txids Array.<string> | string

transaction id of record

Source:
Returns:
Type:
Promise.<Array.<Object>>



(async) getOip5Template(txidopt) → {Promise.<Object>}

Get oip5 template

Parameters:
Name Type Attributes Description
txid string <optional>

transaction id of record

Source:
Returns:
Type:
Promise.<Object>



(async) getOip5Templates(txids) → {Promise.<Array.<Object>>}

Get oip5 templates

Parameters:
Name Type Description
txids string | Array.<string>

transaction ids of record

Source:
Returns:
Type:
Promise.<Array.<Object>>



(async) getRecord(txid) → {Promise.<Object>}

Get a Record from the Index by TXID

Parameters:
Name Type Description
txid TXID

transaction id of the artifact you wish to retrieve

Source:
Example
let txid = 'cc9a11050acdc4401aec3f40c4cce123d99c0f2c27d4403ae4a2536ee38a4716'
let {success, record, error} = await DaemonApi.getRecord(txid)
Returns:
Type:
Promise.<Object>



(async) getSyncStatus() → {Promise.<Object>}

Get the Daemon's sync status

Source:
Returns:
Type:
Promise.<Object>



getUrl() → {String}

Get current DaemonUrl

Source:
Example
let url = DaemonUrl.getUrl()
Returns:

daemonUrl

Type:
String



(async) getVersion() → {Promise.<Object>}

Get OIP Daemon specs

Source:
Example
let versionData = await DaemonApi.getVersion()
Returns:
Type:
Promise.<Object>



(async) searchArtifacts(query, limitopt) → {Promise.<Object>}

Search the Index for artifacts by query

Parameters:
Name Type Attributes Default Description
query string

your search query

limit number <optional>
100

max num of results

Source:
Example
let {success, artifacts, error} = await DaemonApi.search('myQuery')
Returns:
Type:
Promise.<Object>



(async) searchArtifactsByType(type, subtypeopt) → {Promise.<Object>}

Search Artifacts by type and subtype

Parameters:
Name Type Attributes Description
type string

options: video, music, audio, image, text, research, and property (as of 12/15/18)

subtype string <optional>

options: tomogram (as of (12/15/18)

Source:
Example
let {success, artifacts, error} = await DaemonApi.searchArtifactsByType('research', 'tomogram')
Returns:
Type:
Promise.<Object>



(async) searchFloData(query, limitopt) → {Promise.<Object>}

Search the floData from FLO provided by the Daemon's Index

Parameters:
Name Type Attributes Description
query string

your search query

limit number <optional>

max num of results

Source:
Example
let query = 'myQuery'
let {success, txs, error} = await DaemonApi.searchFloData(query)
for (let i of txs) {
    let floData = i.tx.floData
}
Returns:

Returns FLO transactions that contain your query in their respective floData

Type:
Promise.<Object>



(async) searchOip5Records(options) → {Promise.<Object>}

Search oip5 templates

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
q string

query string query

limit number <optional>
10

max num of results (limited to 10 on backend)

after string <optional>

the string ID returned on response to get the next set of data

pages number <optional>

page number

sort string <optional>

sort field ascending or descending. Format must match: ([0-9a-zA-Z._-]+:[ad]$?)+

Source:
Returns:
Type:
Promise.<Object>



(async) searchOip5Templates(options) → {Promise.<Object>}

Search oip5 templates

Parameters:
Name Type Description
options Object
Properties
Name Type Attributes Default Description
q string

query string query

limit number <optional>
10

max num of results (limited to 10 on backend)

after string <optional>

the string ID returned on response to get the next set of data

pages number <optional>

page number

sort string <optional>

sort field ascending or descending. Format must match: ([0-9a-zA-Z._-]+:[ad]$?)+

Source:
Returns:
Type:
Promise.<Object>



setUrl(daemonUrl)

Set the DaemonUrl

Parameters:
Name Type Description
daemonUrl String

the URL of an OIP Daemon (OIPd)

Source:
Example
DaemonApi.setUrl('https://api.oip.io/oip')
let url = DaemonUrl.getUrl()
url === 'https://api.oip.io/oip' //true