require 'captivus/util' require 'json-schema' module Captivus class Payload SCHEMA = { 'type' => 'object', 'properties' => { 'notifier' => { 'type' => 'object', 'required' => true, 'properties' => { 'name' => {'type' => 'string', 'required' => true}, 'version' => {'type' => 'string', 'required' => true}, 'language' => {'type' => 'string', 'required' => true} } }, 'event' => { 'type' => 'object', 'required' => true, 'properties' => { 'type' => {'type' => 'string', 'required' => true}, 'message' => {'type' => 'string', 'required' => true}, 'timestamp' => {'type' => 'string', 'required' => true, 'format' => 'date-time'} } }, 'backtrace' => { 'type' => 'array', 'required' => true, 'items' => { 'type' => 'object', 'properties' => { 'file' => {'type' => 'string', 'required' => true}, 'number' => { 'type' => 'integer', 'required' => true}, 'method' => {'type' => 'string'} } } }, 'context' => { 'type' => 'object', 'properties' => { 'controller' => {'type' => 'string'}, 'action' => {'type' => 'string'}, 'params' => {'type' => 'object'} } }, 'environment' => { 'type' => 'object', 'required' => true, 'properties' => { 'name' => {'type' => 'string', 'required' => true} } } } } def initialize(json) JSON::Validator.validate! SCHEMA, json @json = json end def as_json(*) Captivus::Util.json_to_hash json end def to_json(*) json.dup end def ==(other) other.is_a?(Payload) && json == other.json end protected attr_reader :json end end