Class: HaveAPI::Client::ActionState

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

Overview

Represents action's state as returned from API resource ActionState.Show/Poll.

Defined Under Namespace

Classes: Progress

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(response) ⇒ ActionState

Returns a new instance of ActionState.



16
17
18
19
20
21
# File 'lib/haveapi/client/action_state.rb', line 16

def initialize(response)
  @data = response.response
  @client = response.action.client

  @progress = Progress.new(@data[:current], @data[:total], @data[:unit])
end

Instance Attribute Details

#cancel_blockObject (readonly)

Returns the value of attribute cancel_block.



14
15
16
# File 'lib/haveapi/client/action_state.rb', line 14

def cancel_block
  @cancel_block
end

#progressObject (readonly)

Returns the value of attribute progress.



14
15
16
# File 'lib/haveapi/client/action_state.rb', line 14

def progress
  @progress
end

Instance Method Details

#can_cancel?Boolean

Returns:

  • (Boolean)


35
36
37
# File 'lib/haveapi/client/action_state.rb', line 35

def can_cancel?
  @data[:can_cancel] === true
end

#cancel(&block) ⇒ Object

Stop monitoring the action's state and attempt to cancel it. The block is given to Action.wait_for_completion for the cancel operation. The block is used only if the cancel operation is blocking.



42
43
44
45
46
47
48
49
# File 'lib/haveapi/client/action_state.rb', line 42

def cancel(&block)
  unless can_cancel?
    raise @client.client_message('errors.uncancelable_action', id: @data[:id])
  end

  @cancel = true
  @cancel_block = block
end

#cancel?Boolean

Returns:

  • (Boolean)


51
52
53
# File 'lib/haveapi/client/action_state.rb', line 51

def cancel?
  @cancel === true
end

#finished?Boolean

Returns:

  • (Boolean)


31
32
33
# File 'lib/haveapi/client/action_state.rb', line 31

def finished?
  @data[:finished] === true
end

#labelObject



23
24
25
# File 'lib/haveapi/client/action_state.rb', line 23

def label
  @data[:label]
end

#statusObject



27
28
29
# File 'lib/haveapi/client/action_state.rb', line 27

def status
  @data[:status] === true
end

#stopObject

Stop monitoring the action's state, the call from Action.wait_for_completion will return.



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

def stop
  @stop = true
end

#stop?Boolean

Returns:

  • (Boolean)


61
62
63
# File 'lib/haveapi/client/action_state.rb', line 61

def stop?
  !@stop.nil? && @stop
end