Class: AllQ::Peek

Inherits:
Base
  • Object
show all
Defined in:
lib/allq/actions/peek.rb

Constant Summary

Constants inherited from Base

Base::ALLQ_DEBUG_DATA

Instance Attribute Summary

Attributes inherited from Base

#client, #connection

Instance Method Summary collapse

Methods inherited from Base

#build_job, #initialize, #send_hash_as_json, #setup

Constructor Details

This class inherits a constructor from AllQ::Base

Instance Method Details

#base_send(tube, buried) ⇒ Object



26
27
28
29
30
31
32
33
34
35
36
# File 'lib/allq/actions/peek.rb', line 26

def base_send(tube, buried)
  out = {
    'action' => 'peek',
    'params' => {
      'tube' => tube
    }
  }

  out['params']['buried'] = 'true' if buried
  out
end

#rcv(data) ⇒ Object



14
15
16
17
18
19
20
21
22
23
24
# File 'lib/allq/actions/peek.rb', line 14

def rcv(data)
  return nil if data.to_s == '' || data.to_s.strip == '{}'

  result = JSON.parse(data)
  if result['job']
    return nil if result['job'].empty?
    job = Job.new_from_hash(result['job'], @client)
    return job
  end
  nil
end

#snd(data) ⇒ Object



4
5
6
7
8
9
10
11
12
# File 'lib/allq/actions/peek.rb', line 4

def snd(data)
  result = nil
  tube = data.delete(:tube)
  buried = data.delete(:buried)

  send_data = base_send(tube, buried)
  response = send_hash_as_json(send_data)
  rcv(response)
end