Module: EverSdk::Debot

Defined in:
lib/ever_sdk_client/debot.rb

Defined Under Namespace

Modules: ErrorCode Classes: DebotActivity, ParamsOfAppDebotBrowser, ResultOfAppDebotBrowser

Constant Summary collapse

DebotAction =
KwStruct.new(:description, :name, :action_type, :to, :attributes, :misc) do
  def to_h
    {
      description: description,
      name: name,
      action_type: action_type,
      to: to,
      attributes: attributes,
      misc: misc
    }
  end

  def self.from_json(j)
    return if j.nil?

    self.new(
      description: j["description"],
      name: j["name"],
      action_type: j["action_type"],
      to: j["to"],
      attributes: j["attributes"],
      misc: j["misc"]
    )
  end
end
DebotInfo =
KwStruct.new(
  :name,
  :version,
  :publisher,
  :caption,
  :author,
  :support,
  :hello,
  :language,
  :dabi,
  :icon,
  :interfaces,
  :dabi_version
) do
  def initialize(
    name: nil,
    version: nil,
    publisher: nil,
    caption: nil,
    author: nil,
    support: nil,
    hello: nil,
    language: nil,
    dabi: nil,
    icon: nil,
    interfaces: [],
    dabi_version: nil
  )
    super
  end
end
Spending =
KwStruct.new(:amount, :dst)
ParamsOfInit =
KwStruct.new(:address)
RegisteredDebot =
KwStruct.new(:debot_handle, :debot_abi, :info) do
  def to_h
    {
      debot_handle: debot_handle,
      debot_abi: debot_abi,
      info: info.to_h
    }
  end
end
ParamsOfStart =
KwStruct.new(:debot_handle)
ParamsOfFetch =
KwStruct.new(:address)
ResultOfFetch =
KwStruct.new(:info)
ParamsOfExecute =
KwStruct.new(:debot_handle, :action) do
  def to_h
    {
      debot_handle: debot_handle,
      action: action.to_h
    }
  end
end
ParamsOfSend =
KwStruct.new(:debot_handle, :message)
ParamsOfRemove =
KwStruct.new(:debot_handle)

Class Method Summary collapse

Class Method Details

.execute(ctx, params) ⇒ Object



331
332
333
334
335
336
337
338
339
340
341
# File 'lib/ever_sdk_client/debot.rb', line 331

def self.execute(ctx, params)
  Interop::request_to_native_lib(ctx, "debot.execute", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: nil
      )
    else
      yield resp
    end
  end
end

.fetch(ctx, params) ⇒ Object



310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
# File 'lib/ever_sdk_client/debot.rb', line 310

def self.fetch(ctx, params)
  Interop::request_to_native_lib(
    ctx,
    "debot.fetch",
    params,
    is_single_thread_only: false
  ) do |resp|
    if resp.success?
      debot_info = resp.result["info"].transform_keys(&:to_sym)
      debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
      yield NativeLibResponseResult.new(
        result: ResultOfFetch.new(
          info: DebotInfo.new(**debot_info)
        )
      )
    else
      yield resp
    end
  end
end

.init(ctx, params, app_browser_obj = nil) ⇒ Object

functions



271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
# File 'lib/ever_sdk_client/debot.rb', line 271

def self.init(ctx, params, app_browser_obj = nil)
  Interop::request_to_native_lib(
    ctx,
    "debot.init",
    params
  ) do |resp|
    if resp.success?
      debot_info = resp.result["info"].transform_keys(&:to_sym)
      debot_info[:dabi_version] = debot_info.delete(:dabiVersion)
      yield NativeLibResponseResult.new(
        result: RegisteredDebot.new(
          debot_handle: resp.result["debot_handle"],
          debot_abi: resp.result["debot_abi"],
          info: DebotInfo.new(**debot_info)
        )
      )
    else
      yield resp
    end
  end
end

.remove(ctx, params) ⇒ Object



343
344
345
346
347
348
349
350
351
352
353
# File 'lib/ever_sdk_client/debot.rb', line 343

def self.remove(ctx, params)
  Interop::request_to_native_lib(ctx, "debot.remove", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: nil
      )
    else
      yield resp
    end
  end
end

.send(ctx, params) ⇒ Object



355
356
357
358
359
360
361
362
363
364
365
# File 'lib/ever_sdk_client/debot.rb', line 355

def self.send(ctx, params)
  Interop::request_to_native_lib(ctx, "debot.send", params) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: nil
      )
    else
      yield resp
    end
  end
end

.start(ctx, params) ⇒ Object



293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
# File 'lib/ever_sdk_client/debot.rb', line 293

def self.start(ctx, params)
  Interop::request_to_native_lib(
    ctx,
    "debot.start",
    params,
    is_single_thread_only: false
  ) do |resp|
    if resp.success?
      yield NativeLibResponseResult.new(
        result: nil
      )
    else
      yield resp
    end
  end
end