Class: Captivus::Payload

Inherits:
Object
  • Object
show all
Defined in:
lib/captivus/payload.rb

Constant Summary collapse

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}
      }
    }
  }
}

Instance Method Summary collapse

Constructor Details

#initialize(json) ⇒ Payload

Returns a new instance of Payload.



57
58
59
60
# File 'lib/captivus/payload.rb', line 57

def initialize(json)
  JSON::Validator.validate! SCHEMA, json
  @json = json
end

Instance Method Details

#==(other) ⇒ Object



70
71
72
# File 'lib/captivus/payload.rb', line 70

def ==(other)
  other.is_a?(Payload) && json == other.json
end

#as_jsonObject



62
63
64
# File 'lib/captivus/payload.rb', line 62

def as_json(*)
  Captivus::Util.json_to_hash json
end

#to_jsonObject



66
67
68
# File 'lib/captivus/payload.rb', line 66

def to_json(*)
  json.dup
end