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.



18
19
20
21
# File 'lib/zabbix/api/client.rb', line 18

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

Instance Method Details

#on_complete(env) ⇒ Object



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

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



23
24
25
26
27
# File 'lib/zabbix/api/client.rb', line 23

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