class Xooa::XooaClient

Attributes

apiToken[RW]
appUrl[RW]
debugging[RW]

Public Class Methods

new() click to toggle source

Initializes the XooaClient

@return XooaClient

# File lib/xooa.rb, line 40
def initialize
  @appUrl = "https://api.xooa.com/api/v1"
  @apiToken = null
  @debugging = false
end

Public Instance Methods

currentIdentity(timeout = "4000") click to toggle source

This endpoint returns authenticated identity information

@param timeout Request timeout in millisecond @return IdentityResponse

# File lib/xooa.rb, line 280
def currentIdentity(timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).currentIdentity(timeout)
end
deleteIdentity(identityId, timeout = "4000") click to toggle source

Deletes an identity. Required permission: manage identities (canManageIdentities=true)

@param identityId Identity id for which to delete the Identity details @param timeout Request timeout in millisecond @return boolean

# File lib/xooa.rb, line 352
def deleteIdentity(identityId, timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).deleteIdentity(identityId, timeout)
end
enrollIdentity(identityRequest, timeout = "4000") click to toggle source

The Enroll identity endpoint is used to enroll new identities for the smart contract app. A success response includes the API Token generated for the identity. This API Token can be used to call API End points on behalf of the enrolled identity. This endpoint provides equivalent functionality to adding new identity manually using Xooa console, and identities added using this endpoint will appear, and can be managed, using Xooa console under the identities tab of the smart contract app Required permission: manage identities (canManageIdentities=true)

@param identityRequest Identity Request data to create a new identity @param timeout Request timeout in millisecond @return IdentityResponse

# File lib/xooa.rb, line 305
def enrollIdentity(identityRequest, timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).enrollIdentity(identityRequest, timeout)
end
enrollIdentityAsync(identityRequest) click to toggle source

The Enroll identity endpoint is used to enroll new identities for the smart contract app. A success response includes the API Token generated for the identity. This API Token can be used to call API End points on behalf of the enrolled identity. This endpoint provides equivalent functionality to adding new identity manually using Xooa console, and identities added using this endpoint will appear, and can be managed, using Xooa console under the identities tab of the smart contract app Required permission: manage identities (canManageIdentities=true)

@param identityRequest Identity Request data to create a new identity @return PendingTransactionResponse

# File lib/xooa.rb, line 319
def enrollIdentityAsync(identityRequest)
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).enrollIdentityAsync(identityRequest)
end
getBlockByNumber(blockNumber, timeout = "4000") click to toggle source

Use this endpoint to Get the number of transactions and hashes of a specific block in the network

@param blockNumber block number for which data is required @param timeout Request timeout in millisecond @return BlockResponse

# File lib/xooa.rb, line 105
def getBlockByNumber(blockNumber, timeout = "4000")
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getBlockByNumber(blockNumber, timeout)
end
getBlockByNumberAsync(blockNumber) click to toggle source

Use this endpoint to Get the number of transactions and hashes of a specific block in the network

@param blockNumber block number for which data is required @return PendingTransactionResponse

# File lib/xooa.rb, line 114
def getBlockByNumberAsync(blockNumber)
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getBlockByNumberAsync(blockNumber)
end
getCurrentBlock(timeout = "4000") click to toggle source

Use this endpoint to Get the block number and hashes of current (highest) block in the network

@param timeout Request timeout in millisecond @return CurrentBlockResponse

# File lib/xooa.rb, line 87
def getCurrentBlock(timeout = "4000")
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getCurrentBlock(timeout)
end
getCurrentBlockAsync() click to toggle source

Use this endpoint to Get the block number and hashes of current (highest) block in the network

@return PendingTransactionResponse

# File lib/xooa.rb, line 95
def getCurrentBlockAsync
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getCurrentBlockAsync
end
getIdentities(timeout = "4000") click to toggle source

Get all identities from the identity registry Required permission: manage identities (canManageIdentities=true)

@param timeout Request timeout in millisecond @return Array

# File lib/xooa.rb, line 290
def getIdentities(timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).getIdentities(timeout)
end
getIdentity(identityId, timeout = "4000") click to toggle source

Get the specified identity from the identity registry. Required permission: manage identities (canManageIdentities=true)

@param identityId Identity id for which to find the Identity details @param timeout Request timeout in millisecond @return IdentityResponse

# File lib/xooa.rb, line 341
def getIdentity(identityId, timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).getIdentity(identityId, timeout)
end
getResultForBlockByNumber(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return BlockResponse

# File lib/xooa.rb, line 261
def getResultForBlockByNumber(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForBlockByNumber(resultId, timeout)
end
getResultForCurrentBlock(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return CurrentBlockResponse

# File lib/xooa.rb, line 251
def getResultForCurrentBlock(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForCurrentBlock(resultId, timeout)
end
getResultForIdentities(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return IdentityResponse

# File lib/xooa.rb, line 241
def getResultForIdentities(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForIdentity(resultId, timeout)
end
getResultForInvoke(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return InvokeResponse

# File lib/xooa.rb, line 231
def getResultForInvoke(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForInvoke(resultId, timeout)
end
getResultForQuery(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return QueryResponse

# File lib/xooa.rb, line 221
def getResultForQuery(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForQuery(resultId, timeout)
end
getResultForTransaction(resultId, timeout = "4000") click to toggle source

This endpoint returns the result of previously submitted api request.

@param resultId Returned in previous Query/Invoke/Participant Operation @param timeout Request timeout in millisecond @return TransactionResponse

# File lib/xooa.rb, line 271
def getResultForTransaction(resultId, timeout = "4000")
  Xooa::Api::ResultApi.new(appUrl, apiToken, debugging).getResultForTransaction(resultId, timeout)
end
getTransactionByTransactionId(transactionId, timeout = "4000") click to toggle source

Use this endpoint to Get transaction by transaction id

@param transactionId transactionId from a previous transaction @param timeout Request timeout in millisecond @return TransactionResponse

# File lib/xooa.rb, line 124
def getTransactionByTransactionId(transactionId, timeout = "4000")
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getTransactionByTransactionId(transactionId, timeout)
end
getTransactionByTransactionIdAsync(transactionId) click to toggle source

Use this endpoint to Get transaction by transaction id

@param transactionId transactionId from a previous transaction @return PendingTransactionResponse

# File lib/xooa.rb, line 133
def getTransactionByTransactionIdAsync(transactionId)
  Xooa::Api::BlockChainApi.new(appUrl, apiToken, debugging).getTransactionByTransactionIdAsync(transactionId)
end
invoke(functionName, args, timeout = "4000") click to toggle source

The invoke API endpoint is used for submitting transaction for processing by the blockchain smart contract app when the transaction payload need to be persisted into the Ledger (new block is mined). The endpoint must call a function already defined in your smart contract app which will process the invoke request. The function name is part of the endpoint URL, or can be entered as the fcn parameter when testing using the Sandbox. For example, if testing the sample get-set smart contract app, use ‘set’ (without quotes) as the value for fcn. The function arguments (number of arguments and type) is determined by the smart contract. The smart contract is also responsible for arguments validation and exception management. In case of error the smart contract is responsible for returning the proper http error code. When exception happens, and it is not caught by smart contract or if caught and no http status code is returned, the API gateway will return http-status-code 500 to the client app. The payload of Invoke Transaction Response in case of final response is determined by the smart contract app.

@param functionName Name of the smart contract function to be invoked @param args the arguments to be passed to the smart contract @param timeout Request timeout in millisecond @return InvokeResponse

# File lib/xooa.rb, line 154
def invoke(functionName, args, timeout = "4000")
  Xooa::Api::InvokeApi.new(appUrl, apiToken, debugging).invoke(functionName, args, timeout)
end
invokeAsync(functionName, args) click to toggle source

The invoke API endpoint is used for submitting transaction for processing by the blockchain smart contract app when the transaction payload need to be persisted into the Ledger (new block is mined). The endpoint must call a function already defined in your smart contract app which will process the invoke request. The function name is part of the endpoint URL, or can be entered as the fcn parameter when testing using the Sandbox. For example, if testing the sample get-set smart contract app, use ‘set’ (without quotes) as the value for fcn. The function arguments (number of arguments and type) is determined by the smart contract. The smart contract is also responsible for arguments validation and exception management. In case of error the smart contract is responsible for returning the proper http error code. When exception happens, and it is not caught by smart contract or if caught and no http status code is returned, the API gateway will return http-status-code 500 to the client app. The payload of Invoke Transaction Response in case of final response is determined by the smart contract app.

@param functionName Name of the smart contract function to be invoked @param args the arguments to be passed to the smart contract @return PendingTransactionResponse

# File lib/xooa.rb, line 174
def invokeAsync(functionName, args)
  Xooa::Api::InvokeApi.new(appUrl, apiToken, debugging).invokeAsync(functionName, args)
end
query(functionName, args, timeout = "4000") click to toggle source

The query API endpoint is used for querying (reading) a blockchain ledger using smart contract function. The endpoint must call a function already defined in your smart contract app which will process the query request. The function name is part of the endpoint URL, or can be entered as the fcn parameter when testing using the Sandbox. The function arguments (number of arguments and type) is determined by the smart contract. The smart contract is responsible for validation and exception management. In case of error the smart contract is responsible for returning the proper http error code. When exception happens, and it is not caught by smart contract or if caught and no http status code is returned, the API gateway will return http-status-code 500 to the client app. For example, if testing the sample get-set smart contract app, enter ‘get’ (without quotes) as the value for fcn.

@param functionName Name of the smart contract function to be invoked @param args the arguments to be passed to the smart contract @param timeout Request timeout in millisecond @return QueryResponse

# File lib/xooa.rb, line 193
def query(functionName, args, timeout = "4000")
  Xooa::Api::QueryApi.new(appUrl, apiToken, debugging).query(functionName, args, timeout)
end
queryAsync(functionName, args) click to toggle source

The query API endpoint is used for querying (reading) a blockchain ledger using smart contract function. The endpoint must call a function already defined in your smart contract app which will process the query request. The function name is part of the endpoint URL, or can be entered as the fcn parameter when testing using the Sandbox. The function arguments (number of arguments and type) is determined by the smart contract. The smart contract is responsible for validation and exception management. In case of error the smart contract is responsible for returning the proper http error code. When exception happens, and it is not caught by smart contract or if caught and no http status code is returned, the API gateway will return http-status-code 500 to the client app. For example, if testing the sample get-set smart contract app, enter ‘get’ (without quotes) as the value for fcn.

@param functionName Name of the smart contract function to be invoked @param args the arguments to be passed to the smart contract @return PendingTransactionResponse

# File lib/xooa.rb, line 211
def queryAsync(functionName, args)
  Xooa::Api::QueryApi.new(appUrl, apiToken, debugging).queryAsync(functionName, args)
end
regenerateIdentityApiToken(identityId, timeout = "4000") click to toggle source

Generates new identity API Token Required permission: manage identities (canManageIdentities=true)

@param identityId Identity id for which to create a new API Token @param timeout Request timeout in millisecond @return IdentityResponse

# File lib/xooa.rb, line 330
def regenerateIdentityApiToken(identityId, timeout = "4000")
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).regenerateIdentityApiToken(identityId, timeout)
end
subscribe(callback) click to toggle source

Subscribe to all the events from the App

@param callback callback method to be invoked upon an event

# File lib/xooa.rb, line 71
def subscribe(callback)
  block = method(callback)
  @xooaSocket = Xooa::Util::XooaSocket.new(appUrl, apiToken).subscribeEvents(block)
end
unsubscribe() click to toggle source

Unsubscribe from all the events

# File lib/xooa.rb, line 78
def unsubscribe
  @xooaSocket.unsubscribe
end
validate() click to toggle source

Validate the appUrl and Api Token

@return IdentityResponse

# File lib/xooa.rb, line 63
def validate
  Xooa::Api::IdentitiesApi.new(appUrl, apiToken, debugging).currentIdentity
end