Class: HaveAPI::ActionState

Inherits:
Object
  • Object
show all
Defined in:
lib/haveapi/action_state.rb

Overview

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.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(user, id: nil, state: nil) ⇒ ActionState

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`.

Parameters:

  • user (Object)
  • id (Integer) (defaults to: nil)

    action state id

  • state (Object) (defaults to: nil)

Raises:

  • (NotImplementedError)


33
34
35
# File 'lib/haveapi/action_state.rb', line 33

def initialize(user, id: nil, state: nil)
  raise NotImplementedError
end

Class Method Details

.list_pending(user, from_id, limit, order) ⇒ Array<ActionState>

Return an array of objects representing actions that are pending completion.

Parameters:

  • user (Object)
  • from_id (Integer)
  • limit (Integer)
  • order (Symbol)

    (:newest or :oldest)

Returns:

Raises:

  • (NotImplementedError)


18
19
20
# File 'lib/haveapi/action_state.rb', line 18

def self.list_pending(user, from_id, limit, order)
  raise NotImplementedError
end

Instance Method Details

#can_cancel?Boolean

Returns true if the action can be cancelled.

Returns:

  • (Boolean)

    true if the action can be cancelled



74
75
76
# File 'lib/haveapi/action_state.rb', line 74

def can_cancel?
  false
end

#cancelInteger, ...

Stop action execution

Returns:

  • (Integer)

    if the cancellation succeded and is a blocking action

  • (truthy)

    if the cancellation succeeded

  • (falsy)

    if the cancellation failed

Raises:

  • (RuntimeError)

    if the cancellation failed

  • (NotImplementedError)

    if the cancellation is not supported



84
85
86
# File 'lib/haveapi/action_state.rb', line 84

def cancel
  raise NotImplementedError, 'action cancellation is not implemented by this API'
end

#created_atTime

Returns:

  • (Time)


68
# File 'lib/haveapi/action_state.rb', line 68

def created_at; end

#finished?Boolean

Returns true of the action is finished.

Returns:

  • (Boolean)

    true of the action is finished

Raises:

  • (NotImplementedError)


43
44
45
# File 'lib/haveapi/action_state.rb', line 43

def finished?
  raise NotImplementedError
end

#idInteger

Returns action state id.

Returns:

  • (Integer)

    action state id

Raises:

  • (NotImplementedError)


53
54
55
# File 'lib/haveapi/action_state.rb', line 53

def id
  raise NotImplementedError
end

#labelString

Returns human-readable label of this action state.

Returns:

  • (String)

    human-readable label of this action state

Raises:

  • (NotImplementedError)


58
59
60
# File 'lib/haveapi/action_state.rb', line 58

def label
  raise NotImplementedError
end

#progressHash

Returns:

  • (Hash)

Raises:

  • (NotImplementedError)


63
64
65
# File 'lib/haveapi/action_state.rb', line 63

def progress
  raise NotImplementedError
end

#statusBoolean

Returns true if the action was/is going to be successful.

Returns:

  • (Boolean)

    true if the action was/is going to be successful

Raises:

  • (NotImplementedError)


48
49
50
# File 'lib/haveapi/action_state.rb', line 48

def status
  raise NotImplementedError
end

#updated_atTime

Returns:

  • (Time)


71
# File 'lib/haveapi/action_state.rb', line 71

def updated_at; end

#valid?Boolean

Returns true if the action exists.

Returns:

  • (Boolean)

    true if the action exists

Raises:

  • (NotImplementedError)


38
39
40
# File 'lib/haveapi/action_state.rb', line 38

def valid?
  raise NotImplementedError
end