Class: Zabbix::Api::FaradayMiddleware::ZabbixApiRequest

Inherits:
Faraday::Middleware
  • Object
show all
Defined in:
lib/zabbix/api/client.rb

Overview

this middleware adapter does zabbix api essential things at the REST level, and hendles serializing/de-serializing ruby objects.

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ ZabbixApiRequest

Returns a new instance of ZabbixApiRequest.



20
21
22
23
# File 'lib/zabbix/api/client.rb', line 20

def initialize(app)
  super(app)
  @app=app
end

Instance Method Details

#on_complete(env) ⇒ Object



31
32
33
34
35
36
37
# File 'lib/zabbix/api/client.rb', line 31

def on_complete(env)
  begin
    env[:response_body] = JSON.parse(env[:response_body])
  rescue JSON::ParserError => e
    env[:response_body] = {error: e,note: 'Check api web configuration (e.g. url, PHP memory, etc)'}
  end
end

#on_request(env) ⇒ Object



25
26
27
28
29
# File 'lib/zabbix/api/client.rb', line 25

def on_request(env)
  env[:request_body][:jsonrpc] = "2.0"
  env[:request_body][:id] = "1"
  env[:request_body] = env[:request_body].to_json
end