Class: Crowdkit::Client::Poll

Inherits:
API
  • Object
show all
Includes:
Enumerable
Defined in:
lib/crowdkit/client/poll.rb

Instance Attribute Summary

Attributes inherited from API

#auto_pagination, #client, #stored_params

Instance Method Summary collapse

Methods inherited from API

#arguments, extract_class_name, #id_key, namespace, #set, #with

Methods included from API::RequestMethods

#agent, #method

Constructor Details

#initialize(options, &block) ⇒ Poll

Returns a new instance of Poll.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/crowdkit/client/poll.rb', line 5

def initialize(options, &block)
  super(options, &block)
  arguments([options], required: [:job_id])

  prepare_sawyer
  get_units

  @units.data.each do |unit|
    def unit.delete
      do_delete("units/#{id}/queue")
    end
  end unless @units.data.empty?
end

Dynamic Method Handling

This class handles dynamic methods through the method_missing method

#method_missing(method_name, *args, &block) ⇒ Object



27
28
29
# File 'lib/crowdkit/client/poll.rb', line 27

def method_missing(method_name, *args, &block)
  @units.send(method_name, *args, &block)
end

Instance Method Details

#any?Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/crowdkit/client/poll.rb', line 23

def any?
  last_response.status != 304
end

#delete(*args) ⇒ Object



31
32
33
34
# File 'lib/crowdkit/client/poll.rb', line 31

def delete(*args)
  arguments(args, required: [:job_id])
  do_delete("jobs/#{job_id}/units/queue", {ids: @units.data.map(&:id)}) if any?
end

#each(&block) ⇒ Object



19
20
21
# File 'lib/crowdkit/client/poll.rb', line 19

def each(&block)
  @units.each(&block)
end