Class: Zebra::ProxyServer

Inherits:
Goliath::API
  • Object
show all
Defined in:
lib/zebra/proxy_server.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(config = {}) ⇒ ProxyServer

Returns a new instance of ProxyServer.



74
75
76
77
# File 'lib/zebra/proxy_server.rb', line 74

def initialize(config={})
  super
  @log = config[:logger] || Logger.new(STDERR)
end

Instance Attribute Details

#logObject

Returns the value of attribute log.



38
39
40
# File 'lib/zebra/proxy_server.rb', line 38

def log
  @log
end

Instance Method Details

#dispatchObject



79
80
81
# File 'lib/zebra/proxy_server.rb', line 79

def dispatch
  # Don't need to do anything, handled by Goliath
end

#response(env) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
# File 'lib/zebra/proxy_server.rb', line 53

def response(env)
  #ap env
  json = env.select { |k,v| v.instance_of?(String) }.to_json
  @log.debug "Sending #{json}"

  config[:connection_pool].execute(false) do |conn|
    handler = EM::Protocols::ZMQConnectionHandler.new(conn)
    reply = handler.send_msg(json).first
    #ap reply
    if reply.eql?('null')
      response = [500, {}, 'Server Error']
    else
      response = JSON.parse(reply)
      response[2] = Base64.decode64(response[2])
    end
    #ap response
    return response
    #[200, {}, resp]
  end
end