Class: Inngest::Event

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name: nil, data: {}, user: {}, version: nil, timestamp: nil) ⇒ Event



50
51
52
53
54
55
56
# File 'lib/inngest.rb', line 50

def initialize (name: nil, data: {}, user: {}, version: nil, timestamp: nil)
  @name = name
  @data = data
  @user = user
  @version = version
  @timestamp = timestamp ? timestamp : Time.now.to_i * 1000
end

Instance Attribute Details

#dataObject

Returns the value of attribute data.



48
49
50
# File 'lib/inngest.rb', line 48

def data
  @data
end

#nameObject

Returns the value of attribute name.



48
49
50
# File 'lib/inngest.rb', line 48

def name
  @name
end

#timestampObject

Returns the value of attribute timestamp.



48
49
50
# File 'lib/inngest.rb', line 48

def timestamp
  @timestamp
end

#userObject

Returns the value of attribute user.



48
49
50
# File 'lib/inngest.rb', line 48

def user
  @user
end

#versionObject

Returns the value of attribute version.



48
49
50
# File 'lib/inngest.rb', line 48

def version
  @version
end

Instance Method Details

#payloadObject



75
76
77
78
79
80
81
82
83
# File 'lib/inngest.rb', line 75

def payload
  {
    name: @name,
    data: @data,
    user: @user,
    v: @version,
    ts: @timestamp
  }.compact
end

#validateObject



58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
# File 'lib/inngest.rb', line 58

def validate

  unless @name&.strip
    raise InngestException.new "Event name can't be empty"
  end

  unless @data
    raise InngestException.new "Event data can't be empty"
  end

  begin
    @data.to_json
  rescue Exception
    raise InngestException.new "Event data couldn't be serialized to json"
  end
end