module Polyseerio::SDK::Method

SDK Method (instance) module.

Instance methods.

Instance methods.

Introduce methods.

Instance methods.

Instance methods.

Static methods.

Instance methods.

Instance methods.

Intance methods.

Instance methods.

Instance methods.

Instance methods.

Instance methods.

Instance methods.

Constants

MAP

Public Class Methods

add_fact() click to toggle source
# File lib/sdk/method/add_fact.rb, line 5
def self.add_fact
  proc do |instance, key, value|
    instance._facts ||= {}

    instance._facts[key] = value
  end
end
add_gauge() click to toggle source
# File lib/sdk/method/add_gauge.rb, line 5
def self.add_gauge
  proc do |instance, key, value|
    instance._gauges ||= {}

    instance._gauges[key] = value
  end
end
attach() click to toggle source
# File lib/sdk/method/attach.rb, line 9
def self.attach
  proc do |instance|
    options = Polyseerio::Helper.defaults(
      {},
      delay: Constant::DEFAULT_HEARTBEAT_DELAY
    )

    uri = Helper.instance_to_uri instance

    options[:delay] = Polyseerio::Helper.ms_to_seconds options[:delay]

    Concurrent::Promise.new do
      heartbeat_thread = Thread.new(instance, options) do |inst, opts|
        begin
          loop do
            payload = {}

            Polyseerio.log 'debug', 'Sending heartbeat.'
            inst.request.post("#{uri}/heartbeat", payload).execute.value

            sleep(opts[:delay])
          end
        rescue => err
          Polyseerio.log 'error', 'Heartbeat failed.'
          Polyseerio.log 'error', err.message
        end
      end

      heartbeat_thread
    end
  end
end
check() click to toggle source
# File lib/sdk/method/check.rb, line 5
def self.check
  proc do ||
  end
end
detach() click to toggle source
# File lib/sdk/method/detach.rb, line 5
def self.detach
  proc do ||
  end
end
execute() click to toggle source
# File lib/sdk/method/execute.rb, line 5
def self.execute
  proc do ||
  end
end
fact() click to toggle source
# File lib/sdk/method/fact.rb, line 5
def self.fact
  proc do ||
  end
end
factory(_request, _resource, methods = [], _options = {}) click to toggle source

Generates method (instance) functions.

# File lib/sdk/factory.rb, line 29
def self.factory(_request, _resource, methods = [], _options = {})
  accumulator = Helper.accumulate_procs('method', MAP)

  methods = methods.each_with_object({}, &accumulator)

  methods
end
gauge() click to toggle source
# File lib/sdk/method/gauge.rb, line 5
def self.gauge
  proc do ||
  end
end
message() click to toggle source
# File lib/sdk/method/message.rb, line 5
def self.message
  proc do ||
  end
end
remove() click to toggle source
# File lib/sdk/method/remove.rb, line 5
def self.remove
  proc do ||
  end
end
save() click to toggle source
# File lib/sdk/method/save.rb, line 7
def self.save
  proc do |instance|
    uri = Helper.instance_to_uri instance

    # TODO: need a way to make raw requests without middleware.
    # TODO: there is no reason to have to create another instance.
    if instance.new?
      instance.request.post(uri, instance.properties)
              .then do |result|
                instance.override_properties(result.properties)

                instance
              end
    else
      instance.request.put(uri, instance.properties)
              .then do |result|
                instance.override_properties(result.properties)

                instance
              end
    end
  end
end
to_json() click to toggle source
# File lib/sdk/method/to_json.rb, line 5
def self.to_json
  proc do ||
  end
end
trigger() click to toggle source
# File lib/sdk/method/trigger.rb, line 7
def self.trigger
  proc do |instance, payload = {}|
    # raise if the instance has not been saved yet...
    uri = Helper.instance_to_uri instance

    instance.request.post("#{uri}/trigger", payload)
  end
end