Class: Extface::HandlerController

Inherits:
ApplicationController show all
Includes:
ActionController::Live
Defined in:
app/controllers/extface/handler_controller.rb

Instance Method Summary collapse

Methods inherited from ApplicationController

#extfaceable, #index

Instance Method Details

#pullObject



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'app/controllers/extface/handler_controller.rb', line 11

def pull
  # request.body.read usable? : YES! return number of bytes received by device
  unless device.present?
    render nothing: true, status: :not_found
  else
    stream_job
  end
rescue => e
  p e.message
  render nothing: true, status: :internal_server_error
ensure
  response.stream.close
end

#pushObject



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'app/controllers/extface/handler_controller.rb', line 25

def push
  # get  request.body.read
  # if it is push message, process it
  status = :not_implemented
  unless device.present?
    status = :not_found
  else
    Extface.redis_block do |r|
      r.append device.uuid, request.body.read
      @full_buffer = r.get device.uuid
    end
    if bytes_porcessed = device.driver.handle(@full_buffer.b)
      Extface.redis_block do |r|
        r.set device.uuid, @full_buffer.b[bytes_porcessed..-1]
      end
    end
    #stream_job # stream right now :)
    status = :ok
  end
rescue => e
  p e.message
  render nothing: true, status: :internal_server_error
ensure
  response.stream.close
end

#settingsObject



51
52
53
# File 'app/controllers/extface/handler_controller.rb', line 51

def settings
  render text: 'settings'
end