Sha256: a47f08b405b1e045ba2a4944f5bab8140c8d802a7d2a48be97cb5d2cbd9c0b60
Contents?: true
Size: 934 Bytes
Versions: 1
Compression:
Stored size: 934 Bytes
Contents
class Zobbix class ApiResponse attr_reader :response, :exception def initialize(&request) @response = {} @exception = nil @response = request.call rescue => ex @exception = ex end def success? @exception.nil? && @response['error'].nil? end def error? !success? end def result @response['result'] end def error_code @response['error'] && @response['error']['code'] end def error_message @response['error'] && @response['error']['message'] end def error_data @response['error'] && @response['error']['data'] end def id @response['id'] end def raise_exception return if success? if @exception raise @exception else raise Error.new("API returned error. Code: #{error_code} Message: #{error_message} Data: #{error_data}") end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
zobbix-0.0.1 | lib/zobbix/api_response.rb |