class HaveAPI::ActionState

This class is an interface between APIs and HaveAPI for handling of blocking actions. Blocking actions are not executed immediately, but their execution takes an unspecified amount of time. This interface allows to list actions that are pending completion and view their status.

If method ‘poll` is defined, it is called by action Resources::ActionState::Poll. it can provide a more sophisticated polling implementation than the implicit one, which is to create a new instance of this class every second and check its state. `poll` is passed one argument, a hash of input parameters from Resources::ActionState::Poll.

Public Class Methods

list_pending(user, from_id, limit, order) click to toggle source

Return an array of objects representing actions that are pending completion. @param [Object] user @param [Integer] from_id @param [Integer] limit @param [Symbol] order (:newest or :oldest) @return [Array<ActionState>]

# File lib/haveapi/action_state.rb, line 18
def self.list_pending(user, from_id, limit, order)
  raise NotImplementedError
end
new(user, id: nil, state: nil) click to toggle source

The constructor either gets parameter ‘id` or `state`. If `state` is not provided, the method should find it using the `id`.

When the client is asking about the state of a specific action, lookup using ‘id` is used. When the client is listing pending actions, instances of this class are created in self.list_pending and are passed the `state` parameter to avoid double lookups. `id` should lead to the same object that would be passed as `state`.

@param [Object] user @param [Integer] id action state id @param [Object] state

# File lib/haveapi/action_state.rb, line 33
def initialize(user, id: nil, state: nil)
  raise NotImplementedError
end

Public Instance Methods

can_cancel?() click to toggle source

@return [Boolean] true if the action can be cancelled

# File lib/haveapi/action_state.rb, line 74
def can_cancel?
  false
end
cancel() click to toggle source

Stop action execution @raise [RuntimeError] if the cancellation failed @raise [NotImplementedError] if the cancellation is not supported @return [Integer] if the cancellation succeded and is a blocking action @return [truthy] if the cancellation succeeded @return [falsy] if the cancellation failed

# File lib/haveapi/action_state.rb, line 84
def cancel
  raise NotImplementedError, 'action cancellation is not implemented by this API'
end
created_at() click to toggle source

@return [Time]

# File lib/haveapi/action_state.rb, line 68
def created_at; end
finished?() click to toggle source

@return [Boolean] true of the action is finished

# File lib/haveapi/action_state.rb, line 43
def finished?
  raise NotImplementedError
end
id() click to toggle source

@return [Integer] action state id

# File lib/haveapi/action_state.rb, line 53
def id
  raise NotImplementedError
end
label() click to toggle source

@return [String] human-readable label of this action state

# File lib/haveapi/action_state.rb, line 58
def label
  raise NotImplementedError
end
progress() click to toggle source

@return [Hash]

# File lib/haveapi/action_state.rb, line 63
def progress
  raise NotImplementedError
end
status() click to toggle source

@return [Boolean] true if the action was/is going to be successful

# File lib/haveapi/action_state.rb, line 48
def status
  raise NotImplementedError
end
updated_at() click to toggle source

@return [Time]

# File lib/haveapi/action_state.rb, line 71
def updated_at; end
valid?() click to toggle source

@return [Boolean] true if the action exists

# File lib/haveapi/action_state.rb, line 38
def valid?
  raise NotImplementedError
end