class HerdstServicecall::Request

Attributes

body[RW]
event[RW]

Public Class Methods

new(event, body) click to toggle source
# File lib/herdst_servicecall/request.rb, line 8
def initialize(event, body)
    self.event = event
    self.body = body ? 
        (body.respond_to?(:with_indifferent_access) ? body.with_indifferent_access : body) : 
        nil
end

Public Instance Methods

parse!(data) click to toggle source
# File lib/herdst_servicecall/request.rb, line 24
def parse!(data)
    body = JSON.parse(data) rescue nil
    
    raise "Invalid body" unless body
    
    self.event = body["event"]
    self.body = body["data"].respond_to?(:with_indifferent_access) ? 
        body["data"].with_indifferent_access : 
        body["data"]
end
to_json() click to toggle source
# File lib/herdst_servicecall/request.rb, line 16
def to_json
    {
        :event => self.event,
        :data => self.body
    }.to_json
end