Class: HaveAPI::ActionState
- Inherits:
-
Object
- Object
- HaveAPI::ActionState
- 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
-
.list_pending(user, from_id, limit, order) ⇒ Array<ActionState>
Return an array of objects representing actions that are pending completion.
Instance Method Summary collapse
-
#can_cancel? ⇒ Boolean
True if the action can be cancelled.
-
#cancel ⇒ Integer, ...
Stop action execution.
- #created_at ⇒ Time
-
#finished? ⇒ Boolean
True of the action is finished.
-
#id ⇒ Integer
Action state id.
-
#initialize(user, id: nil, state: nil) ⇒ ActionState
constructor
The constructor either gets parameter ‘id` or `state`.
-
#label ⇒ String
Human-readable label of this action state.
- #progress ⇒ Hash
-
#status ⇒ Boolean
True if the action was/is going to be successful.
- #updated_at ⇒ Time
-
#valid? ⇒ Boolean
True if the action exists.
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`.
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.
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.
74 75 76 |
# File 'lib/haveapi/action_state.rb', line 74 def can_cancel? false end |
#cancel ⇒ Integer, ...
Stop action execution
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_at ⇒ Time
68 |
# File 'lib/haveapi/action_state.rb', line 68 def created_at; end |
#finished? ⇒ Boolean
Returns true of the action is finished.
43 44 45 |
# File 'lib/haveapi/action_state.rb', line 43 def finished? raise NotImplementedError end |
#id ⇒ Integer
Returns action state id.
53 54 55 |
# File 'lib/haveapi/action_state.rb', line 53 def id raise NotImplementedError end |
#label ⇒ String
Returns human-readable label of this action state.
58 59 60 |
# File 'lib/haveapi/action_state.rb', line 58 def label raise NotImplementedError end |
#progress ⇒ Hash
63 64 65 |
# File 'lib/haveapi/action_state.rb', line 63 def progress raise NotImplementedError end |
#status ⇒ Boolean
Returns true if the action was/is going to be successful.
48 49 50 |
# File 'lib/haveapi/action_state.rb', line 48 def status raise NotImplementedError end |
#updated_at ⇒ Time
71 |
# File 'lib/haveapi/action_state.rb', line 71 def updated_at; end |
#valid? ⇒ Boolean
Returns true if the action exists.
38 39 40 |
# File 'lib/haveapi/action_state.rb', line 38 def valid? raise NotImplementedError end |