Skip to content
Ibrahim Ansari edited this page Feb 6, 2021 · 2 revisions

Documentation for octyne-api 1.0.0

Classes

OctyneError

An error sent back by Octyne after making a request.

Client

The Octyne API client.

Functions

OctyneApi(url, info)Client

A function to initialise an Octyne API {Client}. Requires either a username/password pair or a token.

OctyneError

An error sent back by Octyne after making a request.

Kind: global class
Properties

Name Type Description
code number The HTTP response code sent by Octyne.
name string Constant set to the value OctyneError.

new OctyneError(message, code)

The constructor for an OctyneError.

Param Type Description
message string The error message sent by Octyne.
code number The HTTP response code sent by Octyne.

octyneError.format() ⇒ string

Kind: instance method of OctyneError
Returns: string - The error in string format.

Client

The Octyne API client.

Kind: global class
Properties

Name Type Description
info Object An object containing the URL, username, password and token to Octyne.
info.url string The URL to the Octyne instance.
[info.username] string The username of the Octyne user.
[info.password] string The password of the Octyne user.
[info.token] string The token of the Octyne user.

new OctyneClient(url, info)

The constructor for the Octyne API client. Requires either a username/password pair or a token.

Param Type Description
url string The URL to the Octyne instance.
info Object An object containing either a username/password pair or an Octyne token.
[info.username] string A string containing the username to log into Octyne with.
[info.password] string A string containing the password to log into Octyne with.
[info.token] string A string containing the token to authenticate to Octyne with.

client.getServers() ⇒ Object

Get all the servers running on this Octyne instance. The object returned has server names as keys, and numbers as the status for the server. 0 indicates offline, 1 indicates online, 2 indicated crashed.

Kind: instance method of Client
Returns: Object - Returns an object containing server names as keys, and a number as value.

client.login() ⇒ Promise.<void>

Logs into Octyne using the username/password pair provided and retrieves the token and saves it.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves when login succeeds, and rejects if failed.

client.logout() ⇒ Promise.<void>

Invalidates the stored token by logging out of Octyne.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves after logout, and rejects if failed.

client.getTicket() ⇒ Promise.<string>

Returns an Octyne one-time ticket which is used for console/file downloads on browser. They expire within 120 seconds and can only be used by the IP address that requested it.

Kind: instance method of Client
Returns: Promise.<string> - A Promise which resolves with a string containing the ticket.

client.openConsole(server, [ticket]) ⇒ Promise.<WebSocket>

Connects to the console of a process running on Octyne, and returns a WebSocket connection in a Promise.

Kind: instance method of Client
Returns: Promise.<WebSocket> - A Promise which resolves with a WebSocket when the connection succeeds.

Param Type Description
server string The name of the Octyne server, which console is to be connected to.
[ticket] string | boolean If an Octyne ticket should be used. If a string is passed, it is used as ticket. Default: window !== 'undefined'

client.startServer(server) ⇒ Promise.<void>

Starts a process on Octyne, given the name of the process.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves after the request, and rejects on error.

Param Type Description
server string The name of the Octyne process to start.

client.stopServer(server) ⇒ Promise.<void>

Stops a process on Octyne, given the name of the process.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves after the request, and rejects on error.

Param Type Description
server string The name of the Octyne process to stop.

client.getFile(server, file, stream) ⇒ Promise.<Buffer> | ReadableStream

Get a file from an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<Buffer> | ReadableStream - A ReadableStream if stream is true, else a Promise with a Buffer, with the file data.

Param Type Description
server string The name of the Octyne server from which to get the file.
file string The path to the file to download.
stream boolean Whether or not to return a ReadableStream (performant for large files). If Octyne responds with an non-2xx HTTP status code, this option will be ignored.

client.getFiles(server, directory) ⇒ Promise.<Array.<Object>>

Gets the contents of the provided folder in an Octyne server process directory. Each file in the array returned is in the following format: { name: string, size: number, lastModified: number, folder: boolean, mimeType: string }

Kind: instance method of Client
Returns: Promise.<Array.<Object>> - A Promise containing an array of objects, in the format given in the description.

Param Type Description
server string The name of the Octyne server from which to get the folder contents.
directory string Path to the folder in the Octyne server process directory.

client.createFolder(server, directory) ⇒ Promise.<void>

Creates a folder in an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves on success and rejects on failure.

Param Type Description
server string The name of the Octyne server where the folder needs to be created.
directory string Path to the directory which needs to be created.

client.moveFile(server, oldpath, newpath) ⇒ Promise.<void>

Moves a file/folder within an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves on success and rejects on failure.

Param Type Description
server string The name of the Octyne server wherein which the file/folder needs to be moved.
oldpath string The path where the current file/folder is located.
newpath string The new path where the file/folder needs to be moved.

client.copyFile(server, oldpath, newpath) ⇒ Promise.<void>

Copies a file/folder within an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves on success and rejects on failure.

Param Type Description
server string The name of the Octyne server wherein which the file/folder needs to be moved.
oldpath string The path where the current file/folder is located.
newpath string The new path where the file/folder needs to be copied to.

client.renameFile(server, oldpath, newname) ⇒ Promise.<void>

Renames a file/folder in an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves on success and rejects on failure.

Param Type Description
server string The name of the Octyne server where the file/folder needs to be renamed.
oldpath string The path where the current file/folder is located.
newname string The new name of the file/folder.

client.deleteFile(server, path) ⇒ Promise.<void>

Deletes a file/folder in an Octyne server process directory.

Kind: instance method of Client
Returns: Promise.<void> - A Promise which resolves on success and rejects on failure.

Param Type Description
server string The name of the Octyne server where the file/folder needs to be deleted.
path string Path to the file/folder which needs to be created.

client.getServer(server) ⇒ Promise.<Object>

Gets info on an Octyne server process. The Object returned is: { status, cpuUsage, memoryUsage, totalMemory, uptime, serverVersion } where only serverVersion is a string.

Kind: instance method of Client
Returns: Promise.<Object> - A Promise containing an Octyne server process object.

Param Type Description
server string The name of the Octyne server process.

client.request(endpoint, options) ⇒ Promise.<Object>

Make a manual request to an Octyne endpoint.

Kind: instance method of Client
Returns: Promise.<Object> - A Promise containing the JSON response.

Param Type Description
endpoint string The Octyne endpoint to make a request to.
options Object The options to pass to the fetch function.

OctyneApi(url, info) ⇒ Client

A function to initialise an Octyne API {Client}. Requires either a username/password pair or a token.

Kind: global function
Returns: Client - Returns an Octyne API {Client}.

Param Type Description
url String The URL to the Octyne instance.
info Object An object containing either a username/password pair or an Octyne token.
[info.username] String A string containing the username to log into Octyne with.
[info.password] String A string containing the password to log into Octyne with.
[info.token] String A string containing the token to authenticate to Octyne with.