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
24
# 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
  response.stream.write ''
rescue => e
  p e.message
  render nothing: true, status: :internal_server_error
ensure
  response.stream.close
end

#pushObject



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

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
    while @full_buffer.try(:b).present? && bytes_porcessed = device.driver.pre_handle(@full_buffer.b) #handle more than one valid packet in the buffer
      Extface.redis_block do |r|
        r.set device.uuid, @full_buffer.b[bytes_porcessed..-1]
        @full_buffer = r.get device.uuid
      end
    end
    #stream_job # stream right now :)
    status = :ok
  end
  response.stream.write ''
rescue => e
  p e
  p e.message
  render nothing: true, status: :internal_server_error
ensure
  response.stream.close
end

#settingsObject



55
56
57
# File 'app/controllers/extface/handler_controller.rb', line 55

def settings
  render text: 'settings'
end