Class: KingKong::Processor::Cube

Inherits:
Base
  • Object
show all
Includes:
Logging
Defined in:
lib/kingkong/processor.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Logging

#logger

Methods inherited from Base

#initialize

Constructor Details

This class inherits a constructor from KingKong::Processor::Base

Instance Attribute Details

#urlObject

Returns the value of attribute url.



44
45
46
# File 'lib/kingkong/processor.rb', line 44

def url
  @url
end

Instance Method Details

#process(ping, name) ⇒ Object

TODO use web sockets …



47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/kingkong/processor.rb', line 47

def process(ping, name)
  http = EM::HttpRequest.new(url).post({
    :body => Yajl::Encoder.encode([cube_hash(ping, name)]),
    :head => {'content-type' => 'application/json'}
  })
  http.callback{
    case http.response_header.status
    when 200..204
      logger.debug "Successfully reported to Cube at #{url}"
    else
      logger.error "Could not report to Cube server: HTTP #{http.response_header.status} : #{http.response}"
    end
  }
  http.errback{
    logger.error "Could not connect to Cube at #{url}"
  }
end